Repository URL to install this package:
Version:
3.4.50 ▾
|
ó ®EYc @ s d Z d d l m Z m Z d d l m Z m Z m Z m Z d d l m Z d Z d Z d Z d Z d Z d Z d e f d YZ d S( sb Routines and classes for supporting and expressing IP address ranges using a glob style syntax. iÿÿÿÿ( t AddrFormatErrort AddrConversionError( t IPRanget IPAddresst IPNetworkt iprange_to_cidrs( t _is_strc C s t | s t St } t } | j d } t | d k rA t SxB| D]:} d | k r| rd t St } | rt t Sy2 g | j d D] } t | ^ q \ } } Wn t k rº t SX| | k rË t Sd | k oâ d k n së t Sd | k od k n st SqH | d k r#t } qH | t k r3t S| t k rCt Sy* d t | k ocd k n slt SWqH t k rt SXqH Wt S( s :param ipglob: An IP address range in a glob-style format. :return: ``True`` if IP range glob is valid, ``False`` otherwise. t .i t -i iþ i iÿ t *( R t Falset splitt lent Truet intt ValueError( t ipglobt seen_hyphent seen_asteriskt octetst octett it octet1t octet2( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyt valid_glob sH 2 " c C sð t | s t d | n g } g } x | j d D] } d | k r | j d } | j | d | j | d q; | d k rª | j d | j d q; | j | | j | q; Wt d j | t d j | f S( s÷ A function that accepts a glob-style IP range and returns the component lower and upper bound IP address. :param ipglob: an IP address range in a glob-style format. :return: a tuple contain lower and upper bound IP objects. s# not a recognised IP glob range: %r!R R i i R t 0t 255( R R R t appendR t join( R t start_tokenst end_tokensR t tokens( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyt glob_to_iptupleF s c C sç t | s t d | n g } g } x | j d D] } d | k r | j d } | j | d | j | d q; | d k rª | j d | j d q; | j | | j | q; Wt d j | d j | S( sÁ A function that accepts a glob-style IP range and returns the equivalent IP range. :param ipglob: an IP address range in a glob-style format. :return: an IPRange object. s# not a recognised IP glob range: %r!R R i i R R R ( R R R R R R ( R R R R R ( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyt glob_to_ipranged s c C så t | } t | } | j d k rE | j d k rE t d n d } g } y; | | | } t | s t d n | j | WnO t k rà x? t | | D]* } | | d | d } | j | q¯ Wn X| S( s A function that accepts an arbitrary start and end IP address or subnet and returns one or more glob-style IP ranges. :param start: the start IP address or subnet. :param end: the end IP address or subnet. :return: a list containing one or more IP globs. i s! IP glob ranges only support IPv4!c S sE g t | j d D] } t | ^ q } g t | j d D] } t | ^ qD } g } t } t } xÇ t d D]¹ } | | | | k r¯ | j t | | q{ | | d k rå | | d k rå | j d t } q{ | s(| s| j d | | | | f t } q4t d q{ t d q{ Wd j | S( NR i i iÿ R s %s-%ss, only 1 hyphenated octet per IP glob allowed!s3 asterisks are not allowed before hyphenated octets!( t strR R R t rangeR R R R ( t lbt ubt _t t1t t2R R R R ( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyt _iprange_to_glob s( .. s invalid ip glob createdi iÿÿÿÿ( R t versionR R R R ( t startt endR) t globsR t cidr( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyt iprange_to_globs s ! c C s t t | S( sï A function that accepts a glob-style IP range and returns a list of one or more IP CIDRs that exactly matches it. :param ipglob: an IP address range in a glob-style format. :return: a list of one or more IP objects. ( R R ( R ( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyt glob_to_cidrsÌ s c C sL t | } t | d | d } t | d k rD t d n | d S( sÿ A function that accepts an IP subnet in a glob-style format and returns a list of CIDR subnets that exactly matches the specified glob. :param cidr: an IP object CIDR subnet. :return: a list of one or more IP addresses and subnets. i iÿÿÿÿi s bad CIDR to IP glob conversion!( R R/ R R ( R. t ipR- ( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyt cidr_to_globØ s t IPGlobc B sh e Z d Z d Z d Z d Z d Z d Z d Z e e e d d Z d Z d Z RS( s½ Represents an IP address range using a glob-style syntax ``x.x.x-y.*`` Individual octets can be represented using the following shortcuts : 1. ``*`` - the asterisk octet (represents values ``0`` through ``255``) 2. ``x-y`` - the hyphenated octet (represents values ``x`` through ``y``) A few basic rules also apply : 1. ``x`` must always be greater than ``y``, therefore : - ``x`` can only be ``0`` through ``254`` - ``y`` can only be ``1`` through ``255`` 2. only one hyphenated octet per IP glob is allowed 3. only asterisks are permitted after a hyphenated octet Examples: +------------------+------------------------------+ | IP glob | Description | +==================+==============================+ | ``192.0.2.1`` | a single address | +------------------+------------------------------+ | ``192.0.2.0-31`` | 32 addresses | +------------------+------------------------------+ | ``192.0.2.*`` | 256 addresses | +------------------+------------------------------+ | ``192.0.2-3.*`` | 512 addresses | +------------------+------------------------------+ | ``192.0-1.*.*`` | 131,072 addresses | +------------------+------------------------------+ | ``*.*.*.*`` | the whole IPv4 address space | +------------------+------------------------------+ .. note :: IP glob ranges are not directly equivalent to CIDR blocks. They can represent address ranges that do not fall on strict bit mask boundaries. They are suitable for use in configuration files, being more obvious and readable than their CIDR counterparts, especially for admins and end users with little or no networking knowledge or experience. All CIDR addresses can always be represented as IP globs but the reverse is not always true. t _globc C sK t | \ } } t t | j | | t | j | j d | _ d S( Ni ( R t superR3 t __init__R/ t _startt _endt glob( t selfR R+ R, ( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyR6 s c C s t t | j S( s- :return: Pickled state of an `IPGlob` object.( R5 R3 t __getstate__( R: ( ( sD /home/tvault/.virtenv/lib/python2.7/site-packages/netaddr/ip/glob.pyR; s c C s6 t t | j | t | j | j d | _ d S( s>