/opt/alt/python37/lib/python3.7/site-packages/paste/util
NameSizeModeActions
looper/-0755rm
template/-0755rm
__pycache__/-0755rm
classinit.py18490644editdlrm
classinit.pyc19310644editdlrm
classinit.pyo19310644editdlrm
classinstance.py13730644editdlrm
classinstance.pyc23230644editdlrm
classinstance.pyo21610644editdlrm
converters.py8630644editdlrm
converters.pyc11740644editdlrm
converters.pyo11740644editdlrm
dateinterval.py24140644editdlrm
dateinterval.pyc31500644editdlrm
dateinterval.pyo31500644editdlrm
datetimeutil.py111700644editdlrm
datetimeutil.pyc102530644editdlrm
datetimeutil.pyo102530644editdlrm
doctest24.py994180644editdlrm
doctest24.pyc844030644editdlrm
doctest24.pyo841150644editdlrm
filemixin.py14310644editdlrm
filemixin.pyc20620644editdlrm
filemixin.pyo20620644editdlrm
finddata.py38410644editdlrm
finddata.pyc29560644editdlrm
finddata.pyo29560644editdlrm
findpackage.py7860644editdlrm
findpackage.pyc9140644editdlrm
findpackage.pyo9140644editdlrm
import_string.py31100644editdlrm
import_string.pyc33450644editdlrm
import_string.pyo33450644editdlrm
intset.py191310644editdlrm
intset.pyc195320644editdlrm
intset.pyo195320644editdlrm
ip4.py92710644editdlrm
ip4.pyc92430644editdlrm
ip4.pyo92430644editdlrm
killthread.py12290644editdlrm
killthread.pyc14310644editdlrm
killthread.pyo14310644editdlrm
looper.py.tmpta39690644editdlrm
mimeparse.py65920644editdlrm
mimeparse.pyc71580644editdlrm
mimeparse.pyo71580644editdlrm
multidict.py114090644editdlrm
multidict.pyc167200644editdlrm
multidict.pyo167200644editdlrm
PySourceColor.py858650644editdlrm
PySourceColor.pyc556160644editdlrm
PySourceColor.pyo556160644editdlrm
quoting.py24760644editdlrm
quoting.pyc30140644editdlrm
quoting.pyo30140644editdlrm
scgiserver.py56360644editdlrm
scgiserver.pyc61260644editdlrm
scgiserver.pyo60150644editdlrm
string24.py167430644editdlrm
string24.pyc186850644editdlrm
string24.pyo186850644editdlrm
template.py.tmpta242950644editdlrm
threadedprint.py82110644editdlrm
threadedprint.pyc103980644editdlrm
threadedprint.pyo90510644editdlrm
threadinglocal.py14840644editdlrm
threadinglocal.pyc20580644editdlrm
threadinglocal.pyo20580644editdlrm
UserDict24.py55160644editdlrm
UserDict24.pyc105130644editdlrm
UserDict24.pyo105130644editdlrm
__init__.py860644editdlrm
__init__.pyc2570644editdlrm
__init__.pyo2570644editdlrm
Edit: /opt/alt/python37/lib/python3.7/site-packages/paste/util/ip4.py (9271B)
# -*- coding: iso-8859-15 -*- """IP4 address range set implementation. Implements an IPv4-range type. Copyright (C) 2006, Heiko Wundram. Released under the MIT-license. """ # Version information # ------------------- __author__ = "Heiko Wundram " __version__ = "0.2" __revision__ = "3" __date__ = "2006-01-20" # Imports # ------- import intset import socket # IP4Range class # -------------- class IP4Range(intset.IntSet): """IP4 address range class with efficient storage of address ranges. Supports all set operations.""" _MINIP4 = 0 _MAXIP4 = (1<<32) - 1 _UNITYTRANS = "".join([chr(n) for n in range(256)]) _IPREMOVE = "0123456789." def __init__(self,*args): """Initialize an ip4range class. The constructor accepts an unlimited number of arguments that may either be tuples in the form (start,stop), integers, longs or strings, where start and stop in a tuple may also be of the form integer, long or string. Passing an integer or long means passing an IPv4-address that's already been converted to integer notation, whereas passing a string specifies an address where this conversion still has to be done. A string address may be in the following formats: - 1.2.3.4 - a plain address, interpreted as a single address - 1.2.3 - a set of addresses, interpreted as 1.2.3.0-1.2.3.255 - localhost - hostname to look up, interpreted as single address - 1.2.3<->5 - a set of addresses, interpreted as 1.2.3.0-1.2.5.255 - 1.2.0.0/16 - a set of addresses, interpreted as 1.2.0.0-1.2.255.255 Only the first three notations are valid if you use a string address in a tuple, whereby notation 2 is interpreted as 1.2.3.0 if specified as lower bound and 1.2.3.255 if specified as upper bound, not as a range of addresses. Specifying a range is done with the <-> operator. This is necessary because '-' might be present in a hostname. '<->' shouldn't be, ever. """ # Special case copy constructor. if len(args) == 1 and isinstance(args[0],IP4Range): super(IP4Range,self).__init__(args[0]) return # Convert arguments to tuple syntax. args = list(args) for i in range(len(args)): argval = args[i] if isinstance(argval,str): if "<->" in argval: # Type 4 address. args[i] = self._parseRange(*argval.split("<->",1)) continue elif "/" in argval: # Type 5 address. args[i] = self._parseMask(*argval.split("/",1)) else: # Type 1, 2 or 3. args[i] = self._parseAddrRange(argval) elif isinstance(argval,tuple): if len(tuple) <> 2: raise ValueError("Tuple is of invalid length.") addr1, addr2 = argval if isinstance(addr1,str): addr1 = self._parseAddrRange(addr1)[0] elif not isinstance(addr1,(int,long)): raise TypeError("Invalid argument.") if isinstance(addr2,str): addr2 = self._parseAddrRange(addr2)[1] elif not isinstance(addr2,(int,long)): raise TypeError("Invalid argument.") args[i] = (addr1,addr2) elif not isinstance(argval,(int,long)): raise TypeError("Invalid argument.") # Initialize the integer set. super(IP4Range,self).__init__(min=self._MINIP4,max=self._MAXIP4,*args) # Parsing functions # ----------------- def _parseRange(self,addr1,addr2): naddr1, naddr1len = _parseAddr(addr1) naddr2, naddr2len = _parseAddr(addr2) if naddr2len < naddr1len: naddr2 += naddr1&(((1<<((naddr1len-naddr2len)*8))-1)<< (naddr2len*8)) naddr2len = naddr1len elif naddr2len > naddr1len: raise ValueError("Range has more dots than address.") naddr1 <<= (4-naddr1len)*8 naddr2 <<= (4-naddr2len)*8 naddr2 += (1<<((4-naddr2len)*8))-1 return (naddr1,naddr2) def _parseMask(self,addr,mask): naddr, naddrlen = _parseAddr(addr) naddr <<= (4-naddrlen)*8 try: if not mask: masklen = 0 else: masklen = int(mask) if not 0 <= masklen <= 32: raise ValueError except ValueError: try: mask = _parseAddr(mask,False) except ValueError: raise ValueError("Mask isn't parseable.") remaining = 0 masklen = 0 if not mask: masklen = 0 else: while not (mask&1): remaining += 1 while (mask&1): mask >>= 1 masklen += 1 if remaining+masklen <> 32: raise ValueError("Mask isn't a proper host mask.") naddr1 = naddr & (((1<>= 8 return ".".join(reversed(rv)) # Iterating # --------- def iteraddresses(self): """Returns an iterator which iterates over ips in this iprange. An IP is returned in string form (e.g. '1.2.3.4').""" for v in super(IP4Range,self).__iter__(): yield self._int2ip(v) def iterranges(self): """Returns an iterator which iterates over ip-ip ranges which build this iprange if combined. An ip-ip pair is returned in string form (e.g. '1.2.3.4-2.3.4.5').""" for r in self._ranges: if r[1]-r[0] == 1: yield self._int2ip(r[0]) else: yield '%s-%s' % (self._int2ip(r[0]),self._int2ip(r[1]-1)) def itermasks(self): """Returns an iterator which iterates over ip/mask pairs which build this iprange if combined. An IP/Mask pair is returned in string form (e.g. '1.2.3.0/24').""" for r in self._ranges: for v in self._itermasks(r): yield v def _itermasks(self,r): ranges = [r] while ranges: cur = ranges.pop() curmask = 0 while True: curmasklen = 1<<(32-curmask) start = (cur[0]+curmasklen-1)&(((1<= cur[0] and start+curmasklen <= cur[1]: break else: curmask += 1 yield "%s/%s" % (self._int2ip(start),curmask) if cur[0] < start: ranges.append((cur[0],start)) if cur[1] > start+curmasklen: ranges.append((start+curmasklen,cur[1])) __iter__ = iteraddresses # Printing # -------- def __repr__(self): """Returns a string which can be used to reconstruct this iprange.""" rv = [] for start, stop in self._ranges: if stop-start == 1: rv.append("%r" % (self._int2ip(start),)) else: rv.append("(%r,%r)" % (self._int2ip(start), self._int2ip(stop-1))) return "%s(%s)" % (self.__class__.__name__,",".join(rv)) def _parseAddr(addr,lookup=True): if lookup and addr.translate(IP4Range._UNITYTRANS, IP4Range._IPREMOVE): try: addr = socket.gethostbyname(addr) except socket.error: raise ValueError("Invalid Hostname as argument.") naddr = 0 for naddrpos, part in enumerate(addr.split(".")): if naddrpos >= 4: raise ValueError("Address contains more than four parts.") try: if not part: part = 0 else: part = int(part) if not 0 <= part < 256: raise ValueError except ValueError: raise ValueError("Address part out of range.") naddr <<= 8 naddr += part return naddr, naddrpos+1 def ip2int(addr, lookup=True): return _parseAddr(addr, lookup=lookup)[0] if __name__ == "__main__": # Little test script. x = IP4Range("172.22.162.250/24") y = IP4Range("172.22.162.250","172.22.163.250","172.22.163.253<->255") print x for val in x.itermasks(): print val for val in y.itermasks(): print val for val in (x|y).itermasks(): print val for val in (x^y).iterranges(): print val for val in x: print val