projects
/
zonemaker.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
62c4aa9
)
compatibility with python 3.2
author
Ralf Jung
<post@ralfj.de>
Tue, 11 Nov 2014 10:03:54 +0000
(11:03 +0100)
committer
Ralf Jung
<post@ralfj.de>
Tue, 11 Nov 2014 10:03:54 +0000
(11:03 +0100)
zonemaker/zone.py
patch
|
blob
|
history
diff --git
a/zonemaker/zone.py
b/zonemaker/zone.py
index f9712e9e5e3aa9a7fa8a94df09a4720fd07998f9..390b0dd4de65ceefa2ab35ad72d9da090aa42dcf 100644
(file)
--- a/
zonemaker/zone.py
+++ b/
zonemaker/zone.py
@@
-1,5
+1,4
@@
import re, datetime
import re, datetime
-from ipaddress import IPv4Address, IPv6Address
from typing import List, Dict, Any, Iterator, Tuple, Sequence
from typing import List, Dict, Any, Iterator, Tuple, Sequence
@@
-10,6
+9,8
@@
day = 24*hour
week = 7*day
REGEX_label = r'[a-zA-Z90-9]([a-zA-Z90-9-]{0,61}[a-zA-Z90-9])?' # max. 63 characters; must not start or end with hyphen
week = 7*day
REGEX_label = r'[a-zA-Z90-9]([a-zA-Z90-9-]{0,61}[a-zA-Z90-9])?' # max. 63 characters; must not start or end with hyphen
+REGEX_ipv4 = r'^\d{1,3}(\.\d{1,3}){3}$'
+REGEX_ipv6 = r'^[a-fA-F0-9]{1,4}(:[a-fA-F0-9]{1,4}){7}$'
def check_label(label: str) -> str:
pattern = r'^{0}$'.format(REGEX_label)
def check_label(label: str) -> str:
pattern = r'^{0}$'.format(REGEX_label)
@@
-29,6
+30,16
@@
def check_hex(data: str) -> str:
return data
raise Exception(data+" is not valid hex data")
return data
raise Exception(data+" is not valid hex data")
+def check_ipv4(address: str) -> str:
+ if re.match(REGEX_ipv4, address):
+ return address
+ raise Exception(address+" is not a valid IPv4 address")
+
+def check_ipv6(address: str) -> str:
+ if re.match(REGEX_ipv6, address):
+ return address
+ raise Exception(address+" is not a valid IPv6 address")
+
def time(time: int) -> str:
if time == 0:
return "0"
def time(time: int) -> str:
if time == 0:
return "0"
@@
-72,7
+83,7
@@
class Digest:
## Record types
class A:
def __init__(self, address: str) -> None:
## Record types
class A:
def __init__(self, address: str) -> None:
- self._address =
IPv4Address
(address)
+ self._address =
check_ipv4
(address)
def generate_rr(self, owner: str, zone: 'Zone') -> Any:
return zone.RR(owner, 'A', self._address)
def generate_rr(self, owner: str, zone: 'Zone') -> Any:
return zone.RR(owner, 'A', self._address)
@@
-80,7
+91,7
@@
class A:
class AAAA:
def __init__(self, address: str) -> None:
class AAAA:
def __init__(self, address: str) -> None:
- self._address =
IPv6Address
(address)
+ self._address =
check_ipv6
(address)
def generate_rr(self, owner: str, zone: 'Zone') -> Any:
return zone.RR(owner, 'AAAA', self._address)
def generate_rr(self, owner: str, zone: 'Zone') -> Any:
return zone.RR(owner, 'AAAA', self._address)