ӊ^(vdZddlmZmZddlmZmZmZmZddl m Z dZ dZ dZ dZd Zd ZGd d eZy )zb Routines and classes for supporting and expressing IP address ranges using a glob style syntax. )AddrFormatErrorAddrConversionError)IPRange IPAddress IPNetworkiprange_to_cidrs)_is_strct|syd}d}|jd}t|dk7ry|D]}d|vr^|ryd}|ry |jdDcgc] }t|c}\}}||k\ryd|cxkrdksyyd|cxkrd kr`yy|d k(rd}m|dury|dury dt|cxkrd ksyyycc}w#t$rYywxYw#t$rYywxYw) z :param ipglob: An IP address range in a glob-style format. :return: ``True`` if IP range glob is valid, ``False`` otherwise. F.-Tr*)r splitlenint ValueError)ipglob seen_hyphen seen_asteriskoctetsoctetioctet1octet2s 1/usr/lib/python3/dist-packages/netaddr/ip/glob.py valid_globrs8 6?KM \\# F 6{a %<K 49KK4D#EqCF#E %#%&%#%& c\ Md"$ CJ-#- . .5< +$F  $  s<CC *C-CC C CC C+*C+ct|std|dg}g}|jdD]}d|vr:|jd}|j|d|j|dA|dk(r#|jd|jd i|j||j|t dj |t dj |fS) z 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. not a recognised IP glob range: !r r rrr0255)rrrappendrjoinr start_tokens end_tokensrtokenss rglob_to_iptupler+Fs f vOPPLJc" % %<[[%F   q *   fQi ( c\    $   e $    &   e $ % SXXl+ ,i8L.M MMct|std|dg}g}|jdD]}d|vr:|jd}|j|d|j|dA|dk(r#|jd|jd i|j||j|t dj |dj |S) z 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. r!r"r r rrrr#r$)rrrr%rr&r's rglob_to_ipranger.ds f vOPPLJc" % %<[[%F   q *   fQi ( c\    $   e $    &   e $ % 388L)388J+? @@r,crt|}t|}|jdk7r|jdk7r tdd}g} |||}t|s td|j ||S#t$r5t ||D]"}||d|d}|j |$Y|SwxYw)a 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. r z!IP glob ranges only support IPv4!c.t|jdDcgc] }t|}}t|jdDcgc] }t|}}g}d}d}tdD]}||||k(r|j t||,||dk(r||dk(r|j dd}P|s,|s|j ||d||d}st d t d dj |Scc}wcc}w) Nr Fr rrrTr z,only 1 hyphenated octet per IP glob allowed!z3asterisks are not allowed before hyphenated octets!)strrrranger%rr&) lbub_t1t2r*rrrs r_iprange_to_globz*iprange_to_globs.._iprange_to_globs!"gmmC0 1c!f 1 1!"gmmC0 1c!f 1 1  q OA!u1~ c"Q%j)Q%1*2a5C< c" $ %& A1&>?&* 1JLL.MOO% O*xx;2 1s D  Dzinvalid ip glob createdr)rversionrrr%r)startendr8globsrcidrs riprange_to_globsr?s e E C.C }}ckkQ.!"EFF B E!!%-&!&&?@ @ V L ! %UC0 !D%d1gtBx8F LL  ! L!s0A88:B65B6c$tt|S)z 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. )rr+)rs r glob_to_cidrsrAs _V4 55r,cxt|}t|d|d}t|dk7r td|dS)z 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. rr9rzbad CIDR to IP glob conversion!)rr?rr)r>ipr=s r cidr_to_globrDsC 4B RUBrF +E 5zQ""CDD 8Or,cheZdZdZdZfdZfdZfdZdZdZ e ee dd Z d Z d Z xZS) IPGloba 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 less 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. _globct|\}}tt|||t |j |j d|_yNr)r+superrF__init__r?_start_endglob)selfrr;r< __class__s rrLzIPGlob.__init__s=&v.  fd$UC0$T[[$)):param state: data used to unpickle a pickled `IPGlob` object.rN)rKrF __setstate__r?rMrNrO)rPstaterQs rrUzIPGlob.__setstate__#s- fd(/$T[[$))rksK  >FF"3lN<A