diff options
| author | Bob Halley <halley@dnspython.org> | 2016-05-30 16:34:32 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2016-05-30 16:34:32 -0700 |
| commit | 995a46caade4c8bbaaa19bc42fcf75c8956fc885 (patch) | |
| tree | f01f2bb50d007c3cd2f2796ef3e7bef40ea1cbbc /dns/ipv6.py | |
| parent | 70b41f007a8da0999db5c21ed6147c4d23b7ccf3 (diff) | |
| download | dnspython-995a46caade4c8bbaaa19bc42fcf75c8956fc885.tar.gz | |
revert prior patch as things are more messed up than I thought!
Diffstat (limited to 'dns/ipv6.py')
| -rw-r--r-- | dns/ipv6.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/dns/ipv6.py b/dns/ipv6.py index 4622ba7..ee991e8 100644 --- a/dns/ipv6.py +++ b/dns/ipv6.py @@ -91,9 +91,9 @@ def inet_ntoa(address): hex = b':'.join(chunks) return hex -_v4_ending = re.compile('(.*):(\d+\.\d+\.\d+\.\d+)$') -_colon_colon_start = re.compile('::.*') -_colon_colon_end = re.compile('.*::$') +_v4_ending = re.compile(b'(.*):(\d+\.\d+\.\d+\.\d+)$') +_colon_colon_start = re.compile(b'::.*') +_colon_colon_end = re.compile(b'.*::$') def inet_aton(text): """Convert a text format IPv6 address into network format. @@ -104,8 +104,14 @@ def inet_aton(text): @raises dns.exception.SyntaxError: the text was not properly formatted """ - if text == '::': - text = '0::' + # + # Our aim here is not something fast; we just want something that works. + # + if not isinstance(text, binary_type): + text = text.encode() + + if text == b'::': + text = b'0::' # # Get rid of the icky dot-quad syntax if we have it. # @@ -128,29 +134,29 @@ def inet_aton(text): # # Now canonicalize into 8 chunks of 4 hex digits each # - chunks = text.split(':') + chunks = text.split(b':') l = len(chunks) if l > 8: raise dns.exception.SyntaxError seen_empty = False canonical = [] for c in chunks: - if c == '': + if c == b'': if seen_empty: raise dns.exception.SyntaxError seen_empty = True for i in xrange(0, 8 - l + 1): - canonical.append('0000') + canonical.append(b'0000') else: lc = len(c) if lc > 4: raise dns.exception.SyntaxError if lc != 4: - c = ('0' * (4 - lc)) + c + c = (b'0' * (4 - lc)) + c canonical.append(c) if l < 8 and not seen_empty: raise dns.exception.SyntaxError - text = ''.join(canonical) + text = b''.join(canonical) # # Finally we can go to binary. |
