Update dnspython-2.2.0

This commit is contained in:
JonnyWong16 2021-10-14 21:36:41 -07:00
parent 4b28040d59
commit 4d62245cf5
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
111 changed files with 9077 additions and 5877 deletions

View file

@ -1,4 +1,6 @@
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
# Copyright (C) 2003-2017 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
@ -18,30 +20,29 @@
import struct
import dns.exception
from ._compat import binary_type
def inet_ntoa(address):
"""Convert an IPv4 address in network form to text form.
"""Convert an IPv4 address in binary form to text form.
@param address: The IPv4 address
@type address: string
@returns: string
*address*, a ``bytes``, the IPv4 address in binary form.
Returns a ``str``.
"""
if len(address) != 4:
raise dns.exception.SyntaxError
if not isinstance(address, bytearray):
address = bytearray(address)
return (u'%u.%u.%u.%u' % (address[0], address[1],
address[2], address[3])).encode()
return ('%u.%u.%u.%u' % (address[0], address[1],
address[2], address[3]))
def inet_aton(text):
"""Convert an IPv4 address in text form to network form.
"""Convert an IPv4 address in text form to binary form.
@param text: The IPv4 address
@type text: string
@returns: string
*text*, a ``str``, the IPv4 address in textual form.
Returns a ``bytes``.
"""
if not isinstance(text, binary_type):
if not isinstance(text, bytes):
text = text.encode()
parts = text.split(b'.')
if len(parts) != 4:
@ -49,11 +50,11 @@ def inet_aton(text):
for part in parts:
if not part.isdigit():
raise dns.exception.SyntaxError
if len(part) > 1 and part[0] == '0':
if len(part) > 1 and part[0] == ord('0'):
# No leading zeros
raise dns.exception.SyntaxError
try:
bytes = [int(part) for part in parts]
return struct.pack('BBBB', *bytes)
except:
b = [int(part) for part in parts]
return struct.pack('BBBB', *b)
except Exception:
raise dns.exception.SyntaxError