Viewing File: /usr/lib/python3.6/site-packages/netaddr/strategy/__pycache__/ipv4.cpython-36.opt-1.pyc
3
��]� � @ s� d Z ddlZddlZddlmZ ejd8kr<ddl m
ZmZ nddlm
ZmZ ddl
mZmZmZ ddlmZmZmZmZmZmZmZ dd l m!Z! d
Z"dZ#dZ$d
Z%eZ&dZ'dZ(dZ)de" d Z*e"e# Z+de# d Z,e-dd� e.de"d �D ��Z/e-dd� e.de"d �D ��Z0e-dd� e.de"d �D ��Z1e-dd� e.de"d �D ��Z2d9dd�Z3d:dd�Z4d;dd�Z5dd� Z6d d!� Z7d"d#� Z8d$d%� Zd&d'� Z9d(d)� Z:d*d+� Zd,d-� Zd<d.d/�Zd0d1� Zd2d3� Zd4d5� Zd6d7� Z;dS )=zIPv4 address logic.� N)� inet_aton�win32�cygwin)� inet_pton�AF_INET)�AddrFormatError�ZEROFILL� INET_PTON)�valid_words�
valid_bits�bits_to_int�int_to_bits� valid_bin�
int_to_bin�
bin_to_int)� _str_type� � z%d�.ZIPv4� �
� � c C s$ g | ]}|t d t| d A f�qS )r r )�max_int�width)�.0�i� r �/usr/lib/python3.6/ipv4.py�
<listcomp>B s r c C s$ g | ]}t d t| d A |f�qS )r r )r r )r r r r r r F s c C s g | ]}|d t | d f�qS )r r )r )r r r r r r J s c C s g | ]}d t | d |f�qS )r r )r )r r r r r r N s c C st | dkrt d��d}|t@ r6djdd� | jd�D ��} y |t@ rLtt| � nt| � W n tk
rn d}Y nX |S )aP
:param addr: An IPv4 address in presentation (string) format.
:param flags: decides which rules are applied to the interpretation of the
addr value. Supported constants are INET_PTON and ZEROFILL. See the
netaddr.core docs for details.
:return: ``True`` if IPv4 address is valid, ``False`` otherwise.
� z Empty strings are not supported!Tr c S s g | ]}d t |� �qS )z%d)�int)r r r r r r a s zvalid_str.<locals>.<listcomp>F) r r �join�splitr �
_inet_ptonr �
_inet_aton� Exception)�addr�flagsZvalidityr r r � valid_strQ s
r) c C s~ |t @ r"djdd� | jd�D ��} y6|t@ rBtjdtt| ��d S tjdt| ��d S W n t k
rx t
d| ��Y nX dS )aP
:param addr: An IPv4 dotted decimal address in string form.
:param flags: decides which rules are applied to the interpretation of the
addr value. Supported constants are INET_PTON and ZEROFILL. See the
netaddr.core docs for details.
:return: The equivalent unsigned integer for a given IPv4 address.
r c S s g | ]}d t |� �qS )z%d)r! )r r r r r r y s zstr_to_int.<locals>.<listcomp>z>Ir z&%r is not a valid IPv4 address string!N)r r"