/opt/alt/python34/lib64/python3.4/__pycache__
NameSizeModeActions
abc.cpython-34.pyc78770644editdlrm
abc.cpython-34.pyo78270644editdlrm
aifc.cpython-34.pyc279120644editdlrm
aifc.cpython-34.pyo279120644editdlrm
antigravity.cpython-34.pyc8470644editdlrm
antigravity.cpython-34.pyo8470644editdlrm
argparse.cpython-34.pyc658740644editdlrm
argparse.cpython-34.pyo657150644editdlrm
ast.cpython-34.pyc123600644editdlrm
ast.cpython-34.pyo123600644editdlrm
asynchat.cpython-34.pyc83590644editdlrm
asynchat.cpython-34.pyo83590644editdlrm
asyncore.cpython-34.pyc179630644editdlrm
asyncore.cpython-34.pyo179630644editdlrm
base64.cpython-34.pyc182970644editdlrm
base64.cpython-34.pyo180990644editdlrm
bdb.cpython-34.pyc186940644editdlrm
bdb.cpython-34.pyo186940644editdlrm
binhex.cpython-34.pyc135410644editdlrm
binhex.cpython-34.pyo135410644editdlrm
bisect.cpython-34.pyc28580644editdlrm
bisect.cpython-34.pyo28580644editdlrm
bz2.cpython-34.pyc151560644editdlrm
bz2.cpython-34.pyo151560644editdlrm
calendar.cpython-34.pyc275670644editdlrm
calendar.cpython-34.pyo275670644editdlrm
cgi.cpython-34.pyc298270644editdlrm
cgi.cpython-34.pyo298270644editdlrm
cgitb.cpython-34.pyc110640644editdlrm
cgitb.cpython-34.pyo110640644editdlrm
chunk.cpython-34.pyc52700644editdlrm
chunk.cpython-34.pyo52700644editdlrm
cmd.cpython-34.pyc134560644editdlrm
cmd.cpython-34.pyo134560644editdlrm
code.cpython-34.pyc97020644editdlrm
code.cpython-34.pyo97020644editdlrm
codecs.cpython-34.pyc351320644editdlrm
codecs.cpython-34.pyo351320644editdlrm
codeop.cpython-34.pyc64660644editdlrm
codeop.cpython-34.pyo64660644editdlrm
colorsys.cpython-34.pyc36590644editdlrm
colorsys.cpython-34.pyo36590644editdlrm
compileall.cpython-34.pyc73780644editdlrm
compileall.cpython-34.pyo73780644editdlrm
configparser.cpython-34.pyc448820644editdlrm
configparser.cpython-34.pyo448820644editdlrm
contextlib.cpython-34.pyc103700644editdlrm
contextlib.cpython-34.pyo103700644editdlrm
copy.cpython-34.pyc80610644editdlrm
copy.cpython-34.pyo79750644editdlrm
copyreg.cpython-34.pyc46070644editdlrm
copyreg.cpython-34.pyo45660644editdlrm
cProfile.cpython-34.pyc46220644editdlrm
cProfile.cpython-34.pyo46220644editdlrm
crypt.cpython-34.pyc24370644editdlrm
crypt.cpython-34.pyo24370644editdlrm
csv.cpython-34.pyc129970644editdlrm
csv.cpython-34.pyo129970644editdlrm
datetime.cpython-34.pyc562640644editdlrm
datetime.cpython-34.pyo542960644editdlrm
decimal.cpython-34.pyc1725260644editdlrm
decimal.cpython-34.pyo1725260644editdlrm
difflib.cpython-34.pyc605150644editdlrm
difflib.cpython-34.pyo604670644editdlrm
dis.cpython-34.pyc145870644editdlrm
dis.cpython-34.pyo145870644editdlrm
doctest.cpython-34.pyc801100644editdlrm
doctest.cpython-34.pyo798370644editdlrm
dummy_threading.cpython-34.pyc12140644editdlrm
dummy_threading.cpython-34.pyo12140644editdlrm
enum.cpython-34.pyc163390644editdlrm
enum.cpython-34.pyo163390644editdlrm
filecmp.cpython-34.pyc91200644editdlrm
filecmp.cpython-34.pyo91200644editdlrm
fileinput.cpython-34.pyc142970644editdlrm
fileinput.cpython-34.pyo142970644editdlrm
fnmatch.cpython-34.pyc31460644editdlrm
fnmatch.cpython-34.pyo31460644editdlrm
formatter.cpython-34.pyc189160644editdlrm
formatter.cpython-34.pyo189160644editdlrm
fractions.cpython-34.pyc192700644editdlrm
fractions.cpython-34.pyo192700644editdlrm
ftplib.cpython-34.pyc333220644editdlrm
ftplib.cpython-34.pyo333220644editdlrm
functools.cpython-34.pyc236140644editdlrm
functools.cpython-34.pyo236140644editdlrm
genericpath.cpython-34.pyc34930644editdlrm
genericpath.cpython-34.pyo34930644editdlrm
getopt.cpython-34.pyc67330644editdlrm
getopt.cpython-34.pyo66910644editdlrm
getpass.cpython-34.pyc46240644editdlrm
getpass.cpython-34.pyo46240644editdlrm
gettext.cpython-34.pyc151740644editdlrm
gettext.cpython-34.pyo151740644editdlrm
glob.cpython-34.pyc28800644editdlrm
glob.cpython-34.pyo28800644editdlrm
gzip.cpython-34.pyc194460644editdlrm
gzip.cpython-34.pyo193920644editdlrm
hashlib.cpython-34.pyc79440644editdlrm
hashlib.cpython-34.pyo79440644editdlrm
heapq.cpython-34.pyc139100644editdlrm
heapq.cpython-34.pyo139100644editdlrm
hmac.cpython-34.pyc51460644editdlrm
hmac.cpython-34.pyo51460644editdlrm
imaplib.cpython-34.pyc434790644editdlrm
imaplib.cpython-34.pyo409550644editdlrm
imghdr.cpython-34.pyc41430644editdlrm
imghdr.cpython-34.pyo41430644editdlrm
imp.cpython-34.pyc98670644editdlrm
imp.cpython-34.pyo98670644editdlrm
inspect.cpython-34.pyc763270644editdlrm
inspect.cpython-34.pyo760060644editdlrm
io.cpython-34.pyc34580644editdlrm
io.cpython-34.pyo34580644editdlrm
ipaddress.cpython-34.pyc629840644editdlrm
ipaddress.cpython-34.pyo629840644editdlrm
keyword.cpython-34.pyc19460644editdlrm
keyword.cpython-34.pyo19460644editdlrm
linecache.cpython-34.pyc31120644editdlrm
linecache.cpython-34.pyo31120644editdlrm
locale.cpython-34.pyc372760644editdlrm
locale.cpython-34.pyo372760644editdlrm
lzma.cpython-34.pyc159170644editdlrm
lzma.cpython-34.pyo159170644editdlrm
macpath.cpython-34.pyc60060644editdlrm
macpath.cpython-34.pyo60060644editdlrm
macurl2path.cpython-34.pyc21020644editdlrm
macurl2path.cpython-34.pyo21020644editdlrm
mailbox.cpython-34.pyc702880644editdlrm
mailbox.cpython-34.pyo701890644editdlrm
mailcap.cpython-34.pyc65440644editdlrm
mailcap.cpython-34.pyo65440644editdlrm
mimetypes.cpython-34.pyc168070644editdlrm
mimetypes.cpython-34.pyo168070644editdlrm
modulefinder.cpython-34.pyc173760644editdlrm
modulefinder.cpython-34.pyo172970644editdlrm
netrc.cpython-34.pyc42770644editdlrm
netrc.cpython-34.pyo42770644editdlrm
nntplib.cpython-34.pyc363100644editdlrm
nntplib.cpython-34.pyo363100644editdlrm
ntpath.cpython-34.pyc133050644editdlrm
ntpath.cpython-34.pyo133050644editdlrm
nturl2path.cpython-34.pyc17160644editdlrm
nturl2path.cpython-34.pyo17160644editdlrm
numbers.cpython-34.pyc126670644editdlrm
numbers.cpython-34.pyo126670644editdlrm
opcode.cpython-34.pyc51740644editdlrm
opcode.cpython-34.pyo51740644editdlrm
operator.cpython-34.pyc127780644editdlrm
operator.cpython-34.pyo127780644editdlrm
optparse.cpython-34.pyc515370644editdlrm
optparse.cpython-34.pyo514600644editdlrm
os.cpython-34.pyc295990644editdlrm
os.cpython-34.pyo295990644editdlrm
pathlib.cpython-34.pyc404830644editdlrm
pathlib.cpython-34.pyo404830644editdlrm
pdb.cpython-34.pyc494720644editdlrm
pdb.cpython-34.pyo494060644editdlrm
pickle.cpython-34.pyc469840644editdlrm
pickle.cpython-34.pyo468380644editdlrm
pickletools.cpython-34.pyc702540644editdlrm
pickletools.cpython-34.pyo691670644editdlrm
pipes.cpython-34.pyc84310644editdlrm
pipes.cpython-34.pyo84310644editdlrm
pkgutil.cpython-34.pyc176000644editdlrm
pkgutil.cpython-34.pyo176000644editdlrm
platform.cpython-34.pyc311720644editdlrm
platform.cpython-34.pyo311720644editdlrm
plistlib.cpython-34.pyc301510644editdlrm
plistlib.cpython-34.pyo300680644editdlrm
poplib.cpython-34.pyc137540644editdlrm
poplib.cpython-34.pyo137540644editdlrm
posixpath.cpython-34.pyc98090644editdlrm
posixpath.cpython-34.pyo98090644editdlrm
pprint.cpython-34.pyc114600644editdlrm
pprint.cpython-34.pyo112950644editdlrm
profile.cpython-34.pyc151510644editdlrm
profile.cpython-34.pyo148980644editdlrm
pstats.cpython-34.pyc236750644editdlrm
pstats.cpython-34.pyo236750644editdlrm
pty.cpython-34.pyc42250644editdlrm
pty.cpython-34.pyo42250644editdlrm
pyclbr.cpython-34.pyc91920644editdlrm
pyclbr.cpython-34.pyo91920644editdlrm
pydoc.cpython-34.pyc909150644editdlrm
pydoc.cpython-34.pyo908540644editdlrm
py_compile.cpython-34.pyc68570644editdlrm
py_compile.cpython-34.pyo68570644editdlrm
queue.cpython-34.pyc92620644editdlrm
queue.cpython-34.pyo92620644editdlrm
quopri.cpython-34.pyc64460644editdlrm
quopri.cpython-34.pyo62360644editdlrm
random.cpython-34.pyc190590644editdlrm
random.cpython-34.pyo190590644editdlrm
re.cpython-34.pyc145500644editdlrm
re.cpython-34.pyo145500644editdlrm
reprlib.cpython-34.pyc58720644editdlrm
reprlib.cpython-34.pyo58720644editdlrm
rlcompleter.cpython-34.pyc56950644editdlrm
rlcompleter.cpython-34.pyo56950644editdlrm
runpy.cpython-34.pyc77530644editdlrm
runpy.cpython-34.pyo77530644editdlrm
sched.cpython-34.pyc65730644editdlrm
sched.cpython-34.pyo65730644editdlrm
selectors.cpython-34.pyc167440644editdlrm
selectors.cpython-34.pyo167440644editdlrm
shelve.cpython-34.pyc99550644editdlrm
shelve.cpython-34.pyo99550644editdlrm
shlex.cpython-34.pyc75180644editdlrm
shlex.cpython-34.pyo75180644editdlrm
shutil.cpython-34.pyc330150644editdlrm
shutil.cpython-34.pyo330150644editdlrm
site.cpython-34.pyc179710644editdlrm
site.cpython-34.pyo179710644editdlrm
smtpd.cpython-34.pyc256690644editdlrm
smtpd.cpython-34.pyo256690644editdlrm
smtplib.cpython-34.pyc331290644editdlrm
smtplib.cpython-34.pyo330550644editdlrm
sndhdr.cpython-34.pyc67690644editdlrm
sndhdr.cpython-34.pyo67690644editdlrm
socket.cpython-34.pyc181110644editdlrm
socket.cpython-34.pyo180610644editdlrm
socketserver.cpython-34.pyc232550644editdlrm
socketserver.cpython-34.pyo232550644editdlrm
sre_compile.cpython-34.pyc119350644editdlrm
sre_compile.cpython-34.pyo117780644editdlrm
sre_constants.cpython-34.pyc55810644editdlrm
sre_constants.cpython-34.pyo55810644editdlrm
sre_parse.cpython-34.pyc202380644editdlrm
sre_parse.cpython-34.pyo202380644editdlrm
ssl.cpython-34.pyc276080644editdlrm
ssl.cpython-34.pyo276080644editdlrm
stat.cpython-34.pyc35780644editdlrm
stat.cpython-34.pyo35780644editdlrm
statistics.cpython-34.pyc171580644editdlrm
statistics.cpython-34.pyo168560644editdlrm
string.cpython-34.pyc83760644editdlrm
string.cpython-34.pyo83760644editdlrm
stringprep.cpython-34.pyc136360644editdlrm
stringprep.cpython-34.pyo135730644editdlrm
struct.cpython-34.pyc3470644editdlrm
struct.cpython-34.pyo3470644editdlrm
subprocess.cpython-34.pyc433590644editdlrm
subprocess.cpython-34.pyo432460644editdlrm
sunau.cpython-34.pyc183090644editdlrm
sunau.cpython-34.pyo183090644editdlrm
symbol.cpython-34.pyc26620644editdlrm
symbol.cpython-34.pyo26620644editdlrm
symtable.cpython-34.pyc113050644editdlrm
symtable.cpython-34.pyo111830644editdlrm
sysconfig.cpython-34.pyc172870644editdlrm
sysconfig.cpython-34.pyo172870644editdlrm
tabnanny.cpython-34.pyc77490644editdlrm
tabnanny.cpython-34.pyo77490644editdlrm
tarfile.cpython-34.pyc680400644editdlrm
tarfile.cpython-34.pyo680400644editdlrm
telnetlib.cpython-34.pyc193940644editdlrm
telnetlib.cpython-34.pyo193940644editdlrm
tempfile.cpython-34.pyc215760644editdlrm
tempfile.cpython-34.pyo215760644editdlrm
textwrap.cpython-34.pyc138000644editdlrm
textwrap.cpython-34.pyo137140644editdlrm
this.cpython-34.pyc13160644editdlrm
this.cpython-34.pyo13160644editdlrm
threading.cpython-34.pyc389650644editdlrm
threading.cpython-34.pyo382520644editdlrm
timeit.cpython-34.pyc110620644editdlrm
timeit.cpython-34.pyo110620644editdlrm
token.cpython-34.pyc36150644editdlrm
token.cpython-34.pyo36150644editdlrm
tokenize.cpython-34.pyc199510644editdlrm
tokenize.cpython-34.pyo199010644editdlrm
trace.cpython-34.pyc241840644editdlrm
trace.cpython-34.pyo241270644editdlrm
traceback.cpython-34.pyc110910644editdlrm
traceback.cpython-34.pyo110910644editdlrm
tracemalloc.cpython-34.pyc171300644editdlrm
tracemalloc.cpython-34.pyo171300644editdlrm
tty.cpython-34.pyc11460644editdlrm
tty.cpython-34.pyo11460644editdlrm
types.cpython-34.pyc55600644editdlrm
types.cpython-34.pyo55600644editdlrm
uu.cpython-34.pyc40210644editdlrm
uu.cpython-34.pyo40210644editdlrm
uuid.cpython-34.pyc218640644editdlrm
uuid.cpython-34.pyo218020644editdlrm
warnings.cpython-34.pyc122680644editdlrm
warnings.cpython-34.pyo115360644editdlrm
wave.cpython-34.pyc191350644editdlrm
wave.cpython-34.pyo190740644editdlrm
weakref.cpython-34.pyc203450644editdlrm
weakref.cpython-34.pyo203080644editdlrm
webbrowser.cpython-34.pyc171320644editdlrm
webbrowser.cpython-34.pyo170930644editdlrm
xdrlib.cpython-34.pyc90020644editdlrm
xdrlib.cpython-34.pyo90020644editdlrm
zipfile.cpython-34.pyc458200644editdlrm
zipfile.cpython-34.pyo457710644editdlrm
_bootlocale.cpython-34.pyc10470644editdlrm
_bootlocale.cpython-34.pyo10160644editdlrm
_collections_abc.cpython-34.pyc239490644editdlrm
_collections_abc.cpython-34.pyo239490644editdlrm
_compat_pickle.cpython-34.pyc75010644editdlrm
_compat_pickle.cpython-34.pyo74270644editdlrm
_dummy_thread.cpython-34.pyc48250644editdlrm
_dummy_thread.cpython-34.pyo48250644editdlrm
_markupbase.cpython-34.pyc89320644editdlrm
_markupbase.cpython-34.pyo87450644editdlrm
_osx_support.cpython-34.pyc106300644editdlrm
_osx_support.cpython-34.pyo106300644editdlrm
_pyio.cpython-34.pyc649330644editdlrm
_pyio.cpython-34.pyo649070644editdlrm
_sitebuiltins.cpython-34.pyc36770644editdlrm
_sitebuiltins.cpython-34.pyo36770644editdlrm
_strptime.cpython-34.pyc157790644editdlrm
_strptime.cpython-34.pyo157790644editdlrm
_sysconfigdata.cpython-34.pyc227000644editdlrm
_sysconfigdata.cpython-34.pyo227000644editdlrm
_threading_local.cpython-34.pyc69460644editdlrm
_threading_local.cpython-34.pyo69460644editdlrm
_weakrefset.cpython-34.pyc84650644editdlrm
_weakrefset.cpython-34.pyo84650644editdlrm
__future__.cpython-34.pyc41680644editdlrm
__future__.cpython-34.pyo41680644editdlrm
__phello__.foo.cpython-34.pyc1340644editdlrm
__phello__.foo.cpython-34.pyo1340644editdlrm
Edit: /opt/alt/python34/lib64/python3.4/__pycache__/ipaddress.cpython-34.pyo (62984B)
f@sdZdZddlZdZdZGdddeZGdd d eZd d Zd d dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"ZGd#d$d$ZejGd%d&d&eZejGd'd(d(eZGd)d*d*ZGd+d,d,eeZGd-d.d.eZGd/d0d0eeZGd1d2d2ZGd3d4d4eeZGd5d6d6eZGd7d8d8eeZdS)9zA fast, lightweight IPv4/IPv6 manipulation library in Python. This library is used to create/poke/manipulate IPv4 and IPv6 addresses and networks. z1.0N c@seZdZdZdS)AddressValueErrorz%A Value Error related to the address.N)__name__ __module__ __qualname____doc__r r ./opt/alt/python34/lib64/python3.4/ipaddress.pyrs rc@seZdZdZdS)NetmaskValueErrorz%A Value Error related to the netmask.N)rrrrr r r r r s r cCsfyt|SWnttfk r(YnXyt|SWnttfk rQYnXtd|dS)aTake an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Address or IPv6Address object. Raises: ValueError: if the *address* passed isn't either a v4 or a v6 address z0%r does not appear to be an IPv4 or IPv6 addressN) IPv4Addressrr IPv6Address ValueError)addressr r r ip_addresssrTcCslyt||SWnttfk r+YnXyt||SWnttfk rWYnXtd|dS)aTake an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP network. Either IPv4 or IPv6 networks may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Network or IPv6Network object. Raises: ValueError: if the string passed isn't either a v4 or a v6 address. Or if the network has host bits set. z0%r does not appear to be an IPv4 or IPv6 networkN) IPv4Networkrr IPv6Networkr)rstrictr r r ip_network9srcCsfyt|SWnttfk r(YnXyt|SWnttfk rQYnXtd|dS)agTake an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Interface or IPv6Interface object. Raises: ValueError: if the string passed isn't either a v4 or a v6 address. Notes: The IPv?Interface classes describe an Address on a particular Network, so they're basically a combination of both the Address and Network classes. z2%r does not appear to be an IPv4 or IPv6 interfaceN) IPv4Interfacerr IPv6Interfacer)rr r r ip_interfaceWsrc Cs/y|jddSWntdYnXdS)a`Represent an address as 4 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv4 IP address. Returns: The integer address packed as 4 bytes in network (big-endian) order. Raises: ValueError: If the integer is negative or too large to be an IPv4 IP address. bigz&Address negative or too large for IPv4N)to_bytesr)rr r r v4_int_to_packedzsrc Cs/y|jddSWntdYnXdS)zRepresent an address as 16 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv6 IP address. Returns: The integer address packed as 16 bytes in network (big-endian) order. rz&Address negative or too large for IPv6N)rr)rr r r v6_int_to_packeds rcCs>t|jd}t|dkr:td|n|S)zAHelper to split the netmask and raise AddressValueError if needed/zOnly one '/' permitted in %r)strsplitlenr)raddrr r r _split_optional_netmasksr$cCsS|d}}x8|ddD]&}|j|jdkrD|}qPqW||fS)zFind a sequence of IPv#Address. Args: addresses: a list of IPv#Address objects. Returns: A tuple containing the first and last IP addresses in the sequence. rN)_ip) addressesfirstlastipr r r _find_address_ranges  r+cCs=|dkr|Sx&t|D]}||?d@r|SqW|S)zCount the number of zero bits on the right hand side. Args: number: an integer. bits: maximum number of bits to count. Returns: The number of zero bits on the right hand side of the number. rr%)range)Znumberbitsir r r _count_righthand_zero_bitss r/ccs^t|tot|ts-tdn|j|jkrXtd||fn||krstdn|jdkrt}n$|jdkrt}n td|j}|j}|j}x||krYt t ||||dj d}|d|||f}|V|d|>7}|d|j krGPn|j |}qWd S) aSummarize a network range given the first and last IP addresses. Example: >>> list(summarize_address_range(IPv4Address('192.0.2.0'), ... IPv4Address('192.0.2.130'))) ... #doctest: +NORMALIZE_WHITESPACE [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'), IPv4Network('192.0.2.130/32')] Args: first: the first IPv4Address or IPv6Address in the range. last: the last IPv4Address or IPv6Address in the range. Returns: An iterator of the summarized IPv(4|6) network objects. Raise: TypeError: If the first and last objects are not IP addresses. If the first and last objects are not the same version. ValueError: If the last object is not greater than the first. If the version of the first address is not 4 or 6. z1first and last must be IP addresses, not networksz%%s and %s are not of the same versionz*last IP address must be greater than firstrzunknown IP versionr%z%s/%dN) isinstance _BaseAddress TypeErrorversionrrr_max_prefixlenr&minr/ bit_length _ALL_ONES __class__)r(r)r*Zip_bitsZ first_intZlast_intZnbitsZnetr r r summarize_address_ranges2       r:cCsxd}g}d}x|D]}|s>|}|j|q|j|jkrk|j|jkrkd}q|t|jjdkr|j|d<}d}q|}|j|qW|}|s|SqWdS)avLoops through the addresses, collapsing concurrent netblocks. Example: ip1 = IPv4Network('192.0.2.0/26') ip2 = IPv4Network('192.0.2.64/26') ip3 = IPv4Network('192.0.2.128/26') ip4 = IPv4Network('192.0.2.192/26') _collapse_addresses_recursive([ip1, ip2, ip3, ip4]) -> [IPv4Network('192.0.2.0/24')] This shouldn't be called directly; it is called via collapse_addresses([]). Args: addresses: A list of IPv4Network's or IPv6Network's Returns: A list of IPv4Network's or IPv6Network's depending on what we were passed. NFTr%)appendnetwork_addressbroadcast_addresslistsupernetsubnets)r'Z last_addrZ ret_arrayZ optimizedZcur_addrr r r _collapse_addresses_recursives&  " rBc Csd}g}g}g}x3|D]+}t|tr}|rm|dj|jkrmtd||dfn|j|q|j|jkr|r|dj|jkrtd||d fny|j|jWqJtk r|j|j YqJXq|r=|d j|jkr=td||d fn|j|qWt t |}t t |}x[|t |krt ||d\}}|j|d}|jt||quWttt ||dtjS) aCollapse a list of IP objects. Example: collapse_addresses([IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')]) -> [IPv4Network('192.0.2.0/24')] Args: addresses: An iterator of IPv4Network or IPv6Network objects. Returns: An iterator of the collapsed IPv(4|6)Network objects. Raises: TypeError: If passed a list of mixed version objects. rr%z%%s and %s are not of the same versionNkeyr;r;r;r;r;r;)r1r2_versionr3r< _prefixlenr5r*AttributeErrorr=sortedsetr"r+indexextendr:iterrB _BaseNetwork_get_networks_key)r'r.ZaddrsZipsZnetsr*r(r)r r r collapse_addresses5s<   rNcCs6t|tr|jSt|tr2|jStS)a2Return a key suitable for sorting between networks and addresses. Address and Network objects are not sortable by default; they're fundamentally different so the expression IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24') doesn't make any sense. There are some times however, where you may wish to have ipaddress sort these for you anyway. If you need to do this, you can use this function as the key= argument to sorted(). Args: obj: either a Network or Address object. Returns: appropriate key. )r1rLrMr2_get_address_keyNotImplemented)objr r r get_mixed_type_keyns   rRc@seZdZdZeddZeddZeddZdd Zd d Z d d Z ddZ ddZ ddZ ddZdS)_IPAddressBasezThe mother class.cCs |jS)z:Return the longhand version of the IP address as a string.)_explode_shorthand_ip_string)selfr r r explodedsz_IPAddressBase.explodedcCs t|S)z;Return the shorthand version of the IP address as a string.)r )rUr r r compressedsz_IPAddressBase.compressedcCs#dt|f}t|dS)Nz%200s has no version specified)typeNotImplementedError)rUmsgr r r r4sz_IPAddressBase.versioncCsi|dkr.d}t|||jfn||jkred}t|||j|jfndS)Nrz-%d (< 0) is not permitted as an IPv%d addressz2%d (>= 2**%d) is not permitted as an IPv%d address)rrDr8r5)rUrrZr r r _check_int_addresss z!_IPAddressBase._check_int_addresscCsDt|}||kr@d}t|||||jfndS)Nz6%r (len %d != %d) is not permitted as an IPv%d address)r"rrD)rUrZ expected_lenZ address_lenrZr r r _check_packed_addresss    z$_IPAddressBase._check_packed_addresscCs|j|j|?AS)zTurn the prefix length into a bitwise netmask Args: prefixlen: An integer, the prefix length. Returns: An integer. )r8)rU prefixlenr r r _ip_int_from_prefixs z"_IPAddressBase._ip_int_from_prefixc Cst||j}|j|}||?}d|>d}||kr{|jd}|j|d}d}t||n|S)aReturn prefix length from the bitwise netmask. Args: ip_int: An integer, the netmask in expanded bitwise format Returns: An integer, the prefix length. Raises: ValueError: If the input intermingles zeroes & ones r%rz&Netmask pattern %r mixes zeroes & ones)r/r5rr) rUip_intZtrailing_zeroesr]Z leading_onesZall_onesZbyteslenZdetailsrZr r r _prefix_from_ip_ints      z"_IPAddressBase._prefix_from_ip_intcCsd|}t|ddS)Nz%r is not a valid netmask)r )rUZ netmask_strrZr r r _report_invalid_netmasks z&_IPAddressBase._report_invalid_netmaskc Cstjj|s"|j|nyt|}Wntk rS|j|YnXd|kon|jkns|j|n|S)a Return prefix length from a numeric string Args: prefixlen_str: The string to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask r)_BaseV4_DECIMAL_DIGITS issupersetrbintrr5)rUZ prefixlen_strr]r r r _prefix_from_prefix_strings z)_IPAddressBase._prefix_from_prefix_stringcCsy|j|}Wntk r4|j|YnXy|j|SWntk rZYnX||jN}y|j|SWntk r|j|YnXdS)aTurn a netmask/hostmask string into a prefix length Args: ip_str: The netmask/hostmask to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask/hostmask N)_ip_int_from_stringrrbrarr8)rUip_strr`r r r _prefix_from_ip_strings     z%_IPAddressBase._prefix_from_ip_stringN)rrrrpropertyrVrWr4r[r\r^rarbrgrjr r r r rSs     rSc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS)r2zA generic IP object. This IP class contains the version independent methods which are used by single IP addresses. cCs9t|t r5dt|kr5td|ndS)NrzUnexpected '/' in %r)r1bytesr r)rUrr r r __init__sz_BaseAddress.__init__cCs|jS)N)r&)rUr r r __int__sz_BaseAddress.__int__c CsCy&|j|jko$|j|jkSWntk r>tSYnXdS)N)r&rDrFrP)rUotherr r r __eq__s  z_BaseAddress.__eq__cCsdt|tstS|j|jkr>td||fn|j|jkr`|j|jkSdS)Nz%%s and %s are not of the same versionF)r1r2rPrDr3r&)rUror r r __lt__$sz_BaseAddress.__lt__cCs*t|tstS|jt||S)N)r1rfrPr9)rUror r r __add__0sz_BaseAddress.__add__cCs*t|tstS|jt||S)N)r1rfrPr9)rUror r r __sub__5sz_BaseAddress.__sub__cCsd|jjt|fS)Nz%s(%r))r9rr )rUr r r __repr__:sz_BaseAddress.__repr__cCst|j|jS)N)r _string_from_ip_intr&)rUr r r __str__=sz_BaseAddress.__str__cCsttt|jS)N)hashhexrfr&)rUr r r __hash__@sz_BaseAddress.__hash__cCs |j|fS)N)rD)rUr r r rOCsz_BaseAddress._get_address_keyN)rrrrrmrnrprqrrrsrtrvryrOr r r r r2 s         r2c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZeddZeddZeddZeddZed d!Zed"d#Zed$d%Zed&d'Zd(d)Zd*d+Zd,d-Zd.d/d0d1Zd.d/d2d3Zed4d5Zed6d7Zed8d9Zed:d;Z ed<d=Z!ed>d?Z"ed@dAZ#d/S)BrLz~A generic IP network object. This IP class contains the version independent methods which are used by networks. cCs i|_dS)N)_cache)rUrr r r rmPsz_BaseNetwork.__init__cCsd|jjt|fS)Nz%s(%r))r9rr )rUr r r rtSsz_BaseNetwork.__repr__cCsd|j|jfS)Nz%s/%d)r=r])rUr r r rvVsz_BaseNetwork.__str__ccsNt|j}t|j}x)t|d|D]}|j|Vq2WdS)zGenerate Iterator over usable hosts in a network. This is like __iter__ except it doesn't return the network or broadcast addresses. r%N)rfr=r>r,_address_class)rUnetwork broadcastxr r r hostsYsz_BaseNetwork.hostsccsNt|j}t|j}x)t||dD]}|j|Vq2WdS)Nr%)rfr=r>r,r{)rUr|r}r~r r r __iter__esz_BaseNetwork.__iter__cCst|j}t|j}|dkrT|||krCtn|j||S|d7}|||krwtn|j||SdS)Nrr%)rfr=r> IndexErrorr{)rUnr|r}r r r __getitem__ks    z_BaseNetwork.__getitem__cCst|tstS|j|jkr>td||fn|j|jkr`|j|jkS|j|jkr|j|jkSdS)Nz%%s and %s are not of the same versionF)r1rLrPrDr3r=netmask)rUror r r rqxsz_BaseNetwork.__lt__c CsayD|j|jkoB|j|jkoBt|jt|jkSWntk r\tSYnXdS)N)rDr=rfrrFrP)rUror r r rps   z_BaseNetwork.__eq__cCs tt|jt|jAS)N)rwrfr=r)rUr r r rysz_BaseNetwork.__hash__cCs`|j|jkrdSt|tr)dSt|jt|jkoYt|jkSSdS)NF)rDr1rLrfr=r&r>)rUror r r __contains__s  z_BaseNetwork.__contains__cCs:|j|kp9|j|kp9|j|kp9|j|kS)z*Tell if self is partly contained in other.)r=r>)rUror r r overlapssz_BaseNetwork.overlapscCsW|jjd}|dkrS|jt|jt|jB}||jd)rzgetr{rfr=hostmask)rUr~r r r r>s  z_BaseNetwork.broadcast_addresscCsQ|jjd}|dkrM|jt|j|jA}||jdr=)rUr r r num_addressessz_BaseNetwork.num_addressescCs#dt|f}t|dS)Nz%%200s has no associated address class)rXrY)rUrZr r r r{sz_BaseNetwork._address_classcCs|jS)N)rE)rUr r r r]sz_BaseNetwork.prefixlenccs|j|jks+td||fnt|tsMtd|n|j|jkon|j|jkstd||fn||krtn|jd|j|j f}|j \}}x||kr||kr|j|jkr)|j|jkr)|V|j \}}q|j|jkrg|j|jkrg|V|j \}}qt d|||fqW||kr|Vn-||kr|Vnt d|||fdS)aRemove an address from a larger block. For example: addr1 = ip_network('192.0.2.0/28') addr2 = ip_network('192.0.2.1/32') addr1.address_exclude(addr2) = [IPv4Network('192.0.2.0/32'), IPv4Network('192.0.2.2/31'), IPv4Network('192.0.2.4/30'), IPv4Network('192.0.2.8/29')] or IPv6: addr1 = ip_network('2001:db8::1/32') addr2 = ip_network('2001:db8::1/128') addr1.address_exclude(addr2) = [ip_network('2001:db8::1/128'), ip_network('2001:db8::2/127'), ip_network('2001:db8::4/126'), ip_network('2001:db8::8/125'), ... ip_network('2001:db8:8000::/33')] Args: other: An IPv4Network or IPv6Network object of the same type. Returns: An iterator of the IPv(4|6)Network objects which is self minus other. Raises: TypeError: If self and other are of differing address versions, or if other is not a network object. ValueError: If other is not completely contained by self. z%%s and %s are not of the same versionz%s is not a network objectz%s not contained in %sz%s/%sz3Error performing exclusion: s1: %s s2: %s other: %sN) rDr3r1rLr=r>r StopIterationr9r]rAAssertionError)rUros1s2r r r address_excludes<$    z_BaseNetwork.address_excludecCs|j|jkr+td||fn|j|jkrAdS|j|jkrWdS|j|jkrmdS|j|jkrdSdS)aCompare two IP objects. This is only concerned about the comparison of the integer representation of the network addresses. This means that the host bits aren't considered at all in this method. If you want to compare host bits, you can easily enough do a 'HostA._ip < HostB._ip' Args: other: An IP object. Returns: If the IP versions of self and other are the same, returns: -1 if self < other: eg: IPv4Network('192.0.2.0/25') < IPv4Network('192.0.2.128/25') IPv6Network('2001:db8::1000/124') < IPv6Network('2001:db8::2000/124') 0 if self == other eg: IPv4Network('192.0.2.0/24') == IPv4Network('192.0.2.0/24') IPv6Network('2001:db8::1000/124') == IPv6Network('2001:db8::1000/124') 1 if self > other eg: IPv4Network('192.0.2.128/25') > IPv4Network('192.0.2.0/25') IPv6Network('2001:db8::2000/124') > IPv6Network('2001:db8::1000/124') Raises: TypeError if the IP versions are different. z"%s and %s are not of the same typer%rr;r;)rDr3r=r)rUror r r compare_networkss!z_BaseNetwork.compare_networkscCs|j|j|jfS)zNetwork-only key function. Returns an object that identifies this address' network and netmask. This function is a suitable "key" argument for sorted() and list.sort(). )rDr=r)rUr r r rMOsz_BaseNetwork._get_networks_keyr%NccsL|j|jkr|VdS|dk rp||jkrEtdn|dkr`tdn||j}n|dkrtdn|j|}||jkrtd||fn|jd|j|j|f}|V|}xW|j}||jkr dS|jt|d}|jd||f}|VqWdS) aThe subnets which join to make the current subnet. In the case that self contains only one IP (self._prefixlen == 32 for IPv4 or self._prefixlen == 128 for IPv6), yield an iterator with just ourself. Args: prefixlen_diff: An integer, the amount the prefix length should be increased by. This should not be set if new_prefix is also set. new_prefix: The desired new prefix length. This must be a larger number (smaller prefix) than the existing prefix. This should not be set if prefixlen_diff is also set. Returns: An iterator of IPv(4|6) objects. Raises: ValueError: The prefixlen_diff is too small or too large. OR prefixlen_diff and new_prefix are both set or new_prefix is a smaller number than the current prefix (smaller number means a larger network) Nznew prefix must be longerr%z(cannot set prefixlen_diff and new_prefixrzprefix length diff must be > 0z0prefix length diff %d is invalid for netblock %sz%s/%s)rEr5rr9r=r>r{rf)rUprefixlen_diff new_prefixZ new_prefixlenr(Zcurrentr}Znew_addrr r r rAYs:        z_BaseNetwork.subnetscCs|jdkr|S|dk rh||jkr=tdn|dkrXtdn|j|}n|j|dkrtd|j|fn|jd|j|j|fdd }|jd|j|jfS) aThe supernet containing the current network. Args: prefixlen_diff: An integer, the amount the prefix length of the network should be decreased by. For example, given a /24 network and a prefixlen_diff of 3, a supernet with a /21 netmask is returned. Returns: An IPv4 network object. Raises: ValueError: If self.prefixlen - prefixlen_diff < 0. I.e., you have a negative prefix length. OR If prefixlen_diff and new_prefix are both set or new_prefix is a larger number than the current prefix (larger number means a smaller network) rNznew prefix must be shorterr%z(cannot set prefixlen_diff and new_prefixz;current prefixlen is %d, cannot have a prefixlen_diff of %dz%s/%drF)rErr]r9r=)rUrrtr r r r@s    z_BaseNetwork.supernetcCs|jjo|jjS)zTest if the address is reserved for multicast use. Returns: A boolean, True if the address is a multicast address. See RFC 2373 2.7 for details. )r= is_multicastr>)rUr r r rs z_BaseNetwork.is_multicastcCs|jjo|jjS)zTest if the address is otherwise IETF reserved. Returns: A boolean, True if the address is within one of the reserved IPv6 Network ranges. )r= is_reservedr>)rUr r r rs z_BaseNetwork.is_reservedcCs|jjo|jjS)zTest if the address is reserved for link-local. Returns: A boolean, True if the address is reserved per RFC 4291. )r= is_link_localr>)rUr r r rs z_BaseNetwork.is_link_localcCs|jjo|jjS)zTest if this address is allocated for private networks. Returns: A boolean, True if the address is reserved per iana-ipv4-special-registry or iana-ipv6-special-registry. )r= is_privater>)rUr r r rs z_BaseNetwork.is_privatecCs|j S)zTest if this address is allocated for public networks. Returns: A boolean, True if the address is not reserved per iana-ipv4-special-registry or iana-ipv6-special-registry. )r)rUr r r is_globals z_BaseNetwork.is_globalcCs|jjo|jjS)zTest if the address is unspecified. Returns: A boolean, True if this is the unspecified address as defined in RFC 2373 2.5.2. )r=is_unspecifiedr>)rUr r r rs z_BaseNetwork.is_unspecifiedcCs|jjo|jjS)zTest if the address is a loopback address. Returns: A boolean, True if the address is a loopback address as defined in RFC 2373 2.5.3. )r= is_loopbackr>)rUr r r rs z_BaseNetwork.is_loopback)$rrrrrmrtrvrrrrqrpryrrrkr>rrrrrr{r]rrrMrAr@rrrrrrrr r r r rLGs@          N 0 >)      rLc @seZdZdZdedZedZed!ZddZ ddZ ddZ ddZ ddZ ddZddZeddZeddZd S)"rczyBase IPv4 object. The following methods are used by IPv4 objects in both single IP addresses and networks. rr% 0123456789rrcCsd|_t|_dS)Nr)rD IPV4LENGTHr5)rUrr r r rm#s z_BaseV4.__init__cCs t|S)N)r )rUr r r rT'sz$_BaseV4._explode_shorthand_ip_stringcCs|stdn|jd}t|dkrItd|ny tjt|j|dSWn>tk r}ztd||fdWYdd}~XnXdS)aTurn the given IP string into an integer for comparison. Args: ip_str: A string, the IP ip_str. Returns: The IP ip_str as an integer. Raises: AddressValueError: if ip_str isn't a valid IPv4 Address. zAddress cannot be empty.rzExpected 4 octets in %rrz%s in %rN)rr!r"rf from_bytesmap _parse_octetr)rUriZoctetsexcr r r rh*s  z_BaseV4._ip_int_from_stringcCs|stdn|jj|s@d}t||nt|dkrkd}t||nt|d}|dkr|ddkrd }t||n|d krtd |n|S) a Convert a decimal octet into an integer. Args: octet_str: A string, the number to parse. Returns: The octet as an integer. Raises: ValueError: if the octet isn't strictly a decimal from [0..255]. zEmpty octet not permittedz#Only decimal digits permitted in %rz$At most 3 characters permitted in %r r0z3Ambiguous (octal/decimal) value in %r not permittedrzOctet %d (> 255) not permitted)rrdrer"rf)rUZ octet_strrZZ octet_intr r r rCs  z_BaseV4._parse_octetcCs"djtt|jddS)zTurns a 32-bit integer into dotted decimal notation. Args: ip_int: An integer, the IP address. Returns: The IP address as a string in dotted decimal notation. rrr)joinrr r)rUr`r r r rugs z_BaseV4._string_from_ip_intcCs|jd}t|dkry.x'|D]}t||jkr+dSq+WWntk rgdSYnXx>t|D]0\}}|dkru|||dkrudSquWdSyt|}Wntk rdSYnXd|ko|jkSS)zVerify that the netmask is valid. Args: netmask: A string, either a prefix or dotted decimal netmask. Returns: A boolean, True if the prefix represents a valid IPv4 netmask. rrFrr%T)r!r"rf_valid_mask_octetsr enumerater5)rUrmaskr~idxyr r r _is_valid_netmaskss"        z_BaseV4._is_valid_netmaskc s|jd}y&fddtt|D}Wntk rMdSYnXt|t|krjdS|d|dkrdSdS) zTest if the IP string is a hostmask (rather than a netmask). Args: ip_str: A string, the potential hostmask. Returns: A boolean, True if the IP string is a hostmask. rcs%g|]}|jkr|qSr )r).0r~)rUr r s z(_BaseV4._is_hostmask..Frr%Tr;)r!rrfrr")rUrir-partsr )rUr _is_hostmasks &  z_BaseV4._is_hostmaskcCs|jS)N)r5)rUr r r max_prefixlensz_BaseV4.max_prefixlencCs|jS)N)rD)rUr r r r4sz_BaseV4.versionN) rrrrrrrrr)rrrrrr8 frozensetrdrrmrTrhrrurrrkrr4r r r r rcs       $  rcc@seZdZdZddZeddZeddZeej dd Z ed d Z ed d Z eddZ eddZdS)r z/Represent and manipulate single IPv4 Addresses.cCstj||tj||t|trI|j|||_dSt|tr|j|dtj |d|_dSt |}|j ||_dS)a Args: address: A string or integer representing the IP Additionally, an integer can be passed, so IPv4Address('192.0.2.1') == IPv4Address(3221225985). or, more generally IPv4Address(int(IPv4Address('192.0.2.1'))) == IPv4Address('192.0.2.1') Raises: AddressValueError: If ipaddress isn't a valid IPv4 address. Nrr) r2rmrcr1rfr[r&rlr\rr rh)rUraddr_strr r r rms   zIPv4Address.__init__cCs t|jS)z*The binary representation of this address.)rr&)rUr r r packedszIPv4Address.packedcCstd}||kS)zTest if the address is otherwise IETF reserved. Returns: A boolean, True if the address is within the reserved IPv4 Network range. z 240.0.0.0/4)r)rUZreserved_networkr r r rs zIPv4Address.is_reservedcCs|tdkp|tdkp|tdkp|tdkp|tdkp|tdkp|tdkp|tdkp|td kp|td kp|td kp|td kp|td kp|tdkS)zTest if this address is allocated for private networks. Returns: A boolean, True if the address is reserved per iana-ipv4-special-registry. z 0.0.0.0/8z 10.0.0.0/8z 127.0.0.0/8z169.254.0.0/16z 172.16.0.0/12z 192.0.0.0/29z192.0.0.170/31z 192.0.2.0/24z192.168.0.0/16z 198.18.0.0/15z198.51.100.0/24z203.0.113.0/24z 240.0.0.0/4z255.255.255.255/32)r)rUr r r rs zIPv4Address.is_privatecCstd}||kS)zTest if the address is reserved for multicast use. Returns: A boolean, True if the address is multicast. See RFC 3171 for details. z 224.0.0.0/4)r)rUmulticast_networkr r r rs zIPv4Address.is_multicastcCstd}||kS)zTest if the address is unspecified. Returns: A boolean, True if this is the unspecified address as defined in RFC 5735 3. z0.0.0.0)r )rUZunspecified_addressr r r rs zIPv4Address.is_unspecifiedcCstd}||kS)zTest if the address is a loopback address. Returns: A boolean, True if the address is a loopback per RFC 3330. z 127.0.0.0/8)r)rUZloopback_networkr r r rs zIPv4Address.is_loopbackcCstd}||kS)zTest if the address is reserved for link-local. Returns: A boolean, True if the address is link-local per RFC 3927. z169.254.0.0/16)r)rUlinklocal_networkr r r r&s zIPv4Address.is_link_localN)rrrrrmrkrr functools lru_cacherrrrrr r r r r s  $    r c@seZdZddZddZddZddZd d Zed d Z ed dZ eddZ eddZ dS)rcCst|ttfrGtj||t|j|_|j|_ dSt |}tj||dt|dd|_|jj |_ |jj |_ |jj |_ dS)NrrF) r1rlrfr rmrr&r|r5rEr$rr)rUrr#r r r rm4s  zIPv4Interface.__init__cCs d|j|j|jjfS)Nz%s/%d)rur&r|r])rUr r r rvDszIPv4Interface.__str__c CsZtj||}| s%|tkr)|Sy|j|jkSWntk rUdSYnXdS)NF)r rprPr|rF)rUro address_equalr r r rpHs zIPv4Interface.__eq__c CsStj||}|tkr"tSy|j|jkSWntk rNdSYnXdS)NF)r rqrPr|rF)rUro address_lessr r r rqTs  zIPv4Interface.__lt__cCs|j|jAt|jjAS)N)r&rErfr|r=)rUr r r ry_szIPv4Interface.__hash__cCs t|jS)N)r r&)rUr r r r*bszIPv4Interface.ipcCsd|j|j|jfS)Nz%s/%s)rur&rE)rUr r r rfszIPv4Interface.with_prefixlencCsd|j|j|jfS)Nz%s/%s)rur&r)rUr r r rkszIPv4Interface.with_netmaskcCsd|j|j|jfS)Nz%s/%s)rur&r)rUr r r rpszIPv4Interface.with_hostmaskN) rrrrmrvrprqryrkr*rrrr r r r r2s    rc@sIeZdZdZeZdddZeej ddZ dS)raeThis class represents and manipulates 32-bit IPv4 network + addresses.. Attributes: [examples for IPv4Network('192.0.2.0/27')] .network_address: IPv4Address('192.0.2.0') .hostmask: IPv4Address('0.0.0.31') .broadcast_address: IPv4Address('192.0.2.32') .netmask: IPv4Address('255.255.255.224') .prefixlen: 27 Tc Cstj||tj||t|tr`t||_|j|_t|j |_ dSt|t rt||_|j|_t|j |_ dSt |}t|j |d|_t|dkr"y|j|d|_Wq.tk r|j|d|_Yq.Xn |j|_t|j|j|_ |rtt |jt |j @|jkrtd|qntt |jt |j @|_|j|jdkr|j|_ndS)aInstantiate a new IPv4 network object. Args: address: A string or integer representing the IP [& network]. '192.0.2.0/24' '192.0.2.0/255.255.255.0' '192.0.0.2/0.0.0.255' are all functionally the same in IPv4. Similarly, '192.0.2.1' '192.0.2.1/255.255.255.255' '192.0.2.1/32' are also functionally equivalent. That is to say, failing to provide a subnetmask will create an object with a mask of /32. If the mask (portion after the / in the argument) is given in dotted quad form, it is treated as a netmask if it starts with a non-zero field (e.g. /255.0.0.0 == /8) and as a hostmask if it starts with a zero field (e.g. 0.255.255.255 == /8), with the single exception of an all-zero mask which is treated as a netmask == /0. If no mask is given, a default of /32 is used. Additionally, an integer can be passed, so IPv4Network('192.0.2.1') == IPv4Network(3221225985) or, more generally IPv4Interface(int(IPv4Interface('192.0.2.1'))) == IPv4Interface('192.0.2.1') Raises: AddressValueError: If ipaddress isn't a valid IPv4 address. NetmaskValueError: If the netmask isn't valid for an IPv4 address. ValueError: If strict is True and a network address is not supplied. Nrrr%z%s has host bits set)rcrmrLr1rlr r=r5rEr8rrfr$rhr"rgr rjr^rrr)rUrrr#r r r rms:&      zIPv4Network.__init__cCs3|jtdko'|jtdk o2|j S)zTest if this address is allocated for public networks. Returns: A boolean, True if the address is not reserved per iana-ipv4-special-registry. z 100.64.0.0/10)r=rr>r)rUr r r rs zIPv4Network.is_globalN) rrrrr r{rmrkrrrr r r r rvs Trc@seZdZdZdedZdZedZddZ dd Z d d Z d d Z dddZ ddZeddZeddZdS)_BaseV6zyBase IPv6 object. The following methods are used by IPv6 objects in both single IP addresses and networks. rr%r_Z0123456789ABCDEFabcdefcCsd|_t|_dS)Nr0)rD IPV6LENGTHr5)rUrr r r rms z_BaseV6.__init__cCs|stdn|jd}d}t||kr[d||f}t|nd|dkryt|jj}Wn>tk r}ztd||fdWYdd}~XnX|jd |d ?d @|jd |d @n|jd}t||kr8d |d|f}t|nd}xYtdt|dD]>} || sX|dk rd |}t|n| }qXqXW|dk rr|} t||d} |ds| d8} | rd}t||qn|ds,| d8} | r,d}t||q,n|j| | } | dkrd}t||jd|fqnt||jkrd}t||j|fn|dsd}t||n|dsd}t||nt|} d} d} yd} x5t| D]'} | d K} | |j || O} qW| d | K} x9t| dD]'} | d K} | |j || O} qgW| SWn>t k r}ztd||fdWYdd}~XnXdS)zTurn an IPv6 ip_str into an integer. Args: ip_str: A string, the IPv6 ip_str. Returns: An int, the IPv6 address Raises: AddressValueError: if ip_str isn't a valid IPv6 Address. zAddress cannot be empty:rz At least %d parts expected in %rrr%z%s in %rNz%xriz!At most %d colons permitted in %rz At most one '::' permitted in %rrz0Leading ':' only permitted as part of '::' in %rz1Trailing ':' only permitted as part of '::' in %rz/Expected at most %d other parts with '::' in %rz,Exactly %d parts expected without '::' in %rr;r;r;) rr!r"r popr&r< _HEXTET_COUNTr, _parse_hextetr)rUrirZ _min_partsrZZipv4_intrZ _max_partsZ skip_indexr.Zparts_hiZparts_loZ parts_skippedr`r r r rhs ,            #     z_BaseV6._ip_int_from_stringcCs]|jj|s%td|nt|dkrPd}t||nt|dS)a&Convert an IPv6 hextet string into an integer. Args: hextet_str: A string, the number to parse. Returns: The hextet as an integer. Raises: ValueError: if the input isn't strictly a hex number from [0..FFFF]. zOnly hex digits permitted in %rrz$At most 4 characters permitted in %rr) _HEX_DIGITSrerr"rf)rUZ hextet_strrZr r r ras z_BaseV6._parse_hextetc Csd}d}d}d}xot|D]a\}}|dkrz|d7}|dkr\|}n||kr|}|}qq%d}d}q%W|dkr||}|t|kr|dg7}ndg|||<|dkrdg|}qn|S) aCompresses a list of hextets. Compresses a list of strings, replacing the longest continuous sequence of "0" in the list with "" and adding empty strings at the beginning or at the end of the string such that subsequently calling ":".join(hextets) will produce the compressed version of the IPv6 address. Args: hextets: A list of strings, the hextets to compress. Returns: A list of strings. r%rrr;r;r;r;)rr") rUhextetsZbest_doublecolon_startZbest_doublecolon_lenZdoublecolon_startZdoublecolon_lenrIZhextetZbest_doublecolon_endr r r _compress_hextetszs.         z_BaseV6._compress_hextetsNcs|dkrt|j}n||jkr<tdnd|fddtdddD}|j|}d j|S) a,Turns a 128-bit integer into hexadecimal notation. Args: ip_int: An integer, the IP address. Returns: A string, the hexadecimal representation of the address. Raises: ValueError: The address is bigger than 128 bits of all ones. NzIPv6 address is too largez%032xcs1g|]'}dt||ddqS)z%xrr)rf)rr~)hex_strr r rs z/_BaseV6._string_from_ip_int..rrrr)rfr&r8rr,rr)rUr`rr )rr rus  %z_BaseV6._string_from_ip_intcst|tr!t|j}n-t|trBt|j}n t|}|j|}d|fddtdddD}t|ttfrddj ||j fSdj |S) zExpand a shortened IPv6 address. Args: ip_str: A string, the IPv6 address. Returns: A string, the expanded IPv6 address. z%032xcs$g|]}||dqS)rr )rr~)rr r rs z8_BaseV6._explode_shorthand_ip_string..rrrz%s/%dr) r1rr r=rr*rhr,rLrrE)rUrir`rr )rr rTs   %z$_BaseV6._explode_shorthand_ip_stringcCs|jS)N)r5)rUr r r rsz_BaseV6.max_prefixlencCs|jS)N)rD)rUr r r r4sz_BaseV6.version)rrrrrr8rrrrmrhrrrurTrkrr4r r r r rs    g  / rc@seZdZdZddZeddZeddZedd Zed d Z ed d Z ee j ddZ eddZeddZeddZeddZeddZeddZdS)r z/Represent and manipulate single IPv6 Addresses.cCstj||tj||t|trI|j|||_dSt|tr|j|dtj |d|_dSt |}|j ||_dS)aInstantiate a new IPv6 address object. Args: address: A string or integer representing the IP Additionally, an integer can be passed, so IPv6Address('2001:db8::') == IPv6Address(42540766411282592856903984951653826560) or, more generally IPv6Address(int(IPv6Address('2001:db8::'))) == IPv6Address('2001:db8::') Raises: AddressValueError: If address isn't a valid IPv6 address. Nrr) r2rmrr1rfr[r&rlr\rr rh)rUrrr r r rms   zIPv6Address.__init__cCs t|jS)z*The binary representation of this address.)rr&)rUr r r r szIPv6Address.packedcCstd}||kS)zTest if the address is reserved for multicast use. Returns: A boolean, True if the address is a multicast address. See RFC 2373 2.7 for details. zff00::/8)r)rUrr r r rs zIPv6Address.is_multicastcstdtdtdtdtdtdtdtdtd td td td td tdtdg}tfdd|DS)zTest if the address is otherwise IETF reserved. Returns: A boolean, True if the address is within one of the reserved IPv6 Network ranges. z::/8z100::/8z200::/7z400::/6z800::/5z1000::/4z4000::/3z6000::/3z8000::/3zA000::/3zC000::/3zE000::/4zF000::/5zF800::/6zFE00::/9c3s|]}|kVqdS)Nr )rr~)rUr r /sz*IPv6Address.is_reserved..)rany)rUZreserved_networksr )rUr rs zIPv6Address.is_reservedcCstd}||kS)zTest if the address is reserved for link-local. Returns: A boolean, True if the address is reserved per RFC 4291. z fe80::/10)r)rUrr r r r1s zIPv6Address.is_link_localcCstd}||kS)a`Test if the address is reserved for site-local. Note that the site-local address space has been deprecated by RFC 3879. Use is_private to test if this address is in the space of unique local addresses as defined by RFC 4193. Returns: A boolean, True if the address is reserved per RFC 3513 2.5.6. z fec0::/10)r)rUZsitelocal_networkr r r is_site_local<s zIPv6Address.is_site_localcCs|tdkp|tdkp|tdkp|tdkp|tdkp|tdkp|tdkp|tdkp|td kp|td kS) zTest if this address is allocated for private networks. Returns: A boolean, True if the address is reserved per iana-ipv6-special-registry. z::1/128z::/128z ::ffff:0:0/96z100::/64z 2001::/23z 2001:2::/48z 2001:db8::/32z 2001:10::/28zfc00::/7z fe80::/10)r)rUr r r rKs zIPv6Address.is_privatecCs|j S)zTest if this address is allocated for public networks. Returns: A boolean, true if the address is not reserved per iana-ipv6-special-registry. )r)rUr r r r`s zIPv6Address.is_globalcCs |jdkS)zTest if the address is unspecified. Returns: A boolean, True if this is the unspecified address as defined in RFC 2373 2.5.2. r)r&)rUr r r rks zIPv6Address.is_unspecifiedcCs |jdkS)zTest if the address is a loopback address. Returns: A boolean, True if the address is a loopback address as defined in RFC 2373 2.5.3. r%)r&)rUr r r rvs zIPv6Address.is_loopbackcCs(|jd?dkrdSt|jd@S)zReturn the IPv4 mapped address. Returns: If the IPv6 address is a v4 mapped address, return the IPv4 mapped address. Return None otherwise. riNl)r&r )rUr r r ipv4_mappeds zIPv6Address.ipv4_mappedcCs@|jd?dkrdSt|jd?d@t|jd@fS)zTuple of embedded teredo IPs. Returns: Tuple of the (server, client) IPs or None if the address doesn't appear to be a teredo address (doesn't start with 2001::/32) `i N@l)r&r )rUr r r teredos zIPv6Address.teredocCs,|jd?dkrdSt|jd?d@S)zReturn the IPv4 6to4 embedded address. Returns: The IPv4 6to4-embedded address if present or None if the address doesn't appear to contain a 6to4 embedded address. pi NPl)r&r )rUr r r sixtofours zIPv6Address.sixtofourN)rrrrrmrkrrrrrrrrrrrrrrr r r r r s  %      r c@seZdZddZddZddZddZd d Zed d Z ed dZ eddZ eddZ eddZ eddZdS)rcCst|ttfrGtj||t|j|_|j|_ dSt |}tj||dt|dd|_|jj |_ |jj |_ |jj |_ dS)NrrF) r1rlrfr rmrr&r|r5rEr$rr)rUrr#r r r rms  zIPv6Interface.__init__cCs d|j|j|jjfS)Nz%s/%d)rur&r|r])rUr r r rvszIPv6Interface.__str__c CsZtj||}| s%|tkr)|Sy|j|jkSWntk rUdSYnXdS)NF)r rprPr|rF)rUrorr r r rps zIPv6Interface.__eq__c CsStj||}|tkr"tSy|j|jkSWntk rNdSYnXdS)NF)r rqrPr|rF)rUrorr r r rqs  zIPv6Interface.__lt__cCs|j|jAt|jjAS)N)r&rErfr|r=)rUr r r ryszIPv6Interface.__hash__cCs t|jS)N)r r&)rUr r r r*szIPv6Interface.ipcCsd|j|j|jfS)Nz%s/%s)rur&rE)rUr r r rszIPv6Interface.with_prefixlencCsd|j|j|jfS)Nz%s/%s)rur&r)rUr r r rszIPv6Interface.with_netmaskcCsd|j|j|jfS)Nz%s/%s)rur&r)rUr r r rszIPv6Interface.with_hostmaskcCs|jdko|jjS)Nr)r&r|r)rUr r r rszIPv6Interface.is_unspecifiedcCs|jdko|jjS)Nr%)r&r|r)rUr r r rszIPv6Interface.is_loopbackN)rrrrmrvrprqryrkr*rrrrrr r r r rs    rc@sIeZdZdZeZdddZddZeddZ d S) ravThis class represents and manipulates 128-bit IPv6 networks. Attributes: [examples for IPv6('2001:db8::1000/124')] .network_address: IPv6Address('2001:db8::1000') .hostmask: IPv6Address('::f') .broadcast_address: IPv6Address('2001:db8::100f') .netmask: IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0') .prefixlen: 124 TcCstj||tj||t|tr`t||_|j|_t|j |_ dSt|t rt||_|j|_t|j |_ dSt |}t|j |d|_t|dkr|j|d|_n |j|_t|j|j|_ |ratt|jt|j @|jkratd|qantt|jt|j @|_|j|jdkr|j|_ndS)aInstantiate a new IPv6 Network object. Args: address: A string or integer representing the IPv6 network or the IP and prefix/netmask. '2001:db8::/128' '2001:db8:0000:0000:0000:0000:0000:0000/128' '2001:db8::' are all functionally the same in IPv6. That is to say, failing to provide a subnetmask will create an object with a mask of /128. Additionally, an integer can be passed, so IPv6Network('2001:db8::') == IPv6Network(42540766411282592856903984951653826560) or, more generally IPv6Network(int(IPv6Network('2001:db8::'))) == IPv6Network('2001:db8::') strict: A boolean. If true, ensure that we have been passed A true network address, eg, 2001:db8::1000/124 and not an IP address on a network, eg, 2001:db8::1/124. Raises: AddressValueError: If address isn't a valid IPv6 address. NetmaskValueError: If the netmask isn't valid for an IPv6 address. ValueError: If strict was True and a network address was not supplied. Nrrr%z%s has host bits set)rrmrLr1rfr r=r5rEr8rrlr$rhr"rgr^rrr)rUrrr#r r r rms4      zIPv6Network.__init__ccsRt|j}t|j}x-t|d|dD]}|j|Vq6WdS)zGenerate Iterator over usable hosts in a network. This is like __iter__ except it doesn't return the Subnet-Router anycast address. r%N)rfr=r>r,r{)rUr|r}r~r r r rMszIPv6Network.hostscCs|jjo|jjS)a`Test if the address is reserved for site-local. Note that the site-local address space has been deprecated by RFC 3879. Use is_private to test if this address is in the space of unique local addresses as defined by RFC 4193. Returns: A boolean, True if the address is reserved per RFC 3513 2.5.6. )r=rr>)rUr r r rYs zIPv6Network.is_site_localN) rrrrr r{rmrrkrr r r r rs H r) r __version__rrrrrr rrrrrr$r+r/r:rBrNrRrStotal_orderingr2rLrcr rrrr rrr r r r  s@   #      8 0 9  : DsJ