Package DebTorrent :: Module iprangeparse :: Class IP_List
[hide private]
[frames] | no frames]

Class IP_List

source code

Stores mutltiple IP address ranges.

Instance Methods [hide private]
 
__init__(self, entrylist=None)
Initialize the instance.
source code
boolean
__nonzero__(self)
Check whether there are any IP address ranges stored.
source code
 
append(self, ip_beg, ip_end=None)
Add a new IP address range.
source code
 
_import_ipv4(self, entrylist)
Initialize an empty IPv4 storage with IPv4 address ranges.
source code
 
_import_ipv6(self, entrylist)
Initialize an empty IPv6 storage with IPv6 address ranges.
source code
boolean
includes(self, ip)
Determine whether the IP address is included in any of the ranges.
source code
 
read_rangelist(self, file)
Parse a file for lists of IPv4 address ranges to initialize the empty storage with.
source code
Instance Variables [hide private]
dictionary of {long: long} ipv4dict
the IP address ranges, keys are the starting IP addresses, values are the ends of the IP address ranges
list of long ipv4list
the starting IP addresses of the ranges
dictionary of {long: long} ipv6dict
the IPv6 address ranges, keys are the starting IPv6 addresses, values are the ends of the IPv6 address ranges
list of long ipv6list
the starting IPv6 addresses of the ranges
Method Details [hide private]

__init__(self, entrylist=None)
(Constructor)

source code 
Initialize the instance.
Parameters:
  • entrylist (list of (string, string)) - the IP address ranges to start with (optional, defaults to None)

__nonzero__(self)
(Boolean test operator)

source code 
Check whether there are any IP address ranges stored.
Returns: boolean
whether there are IP address ranges stored

append(self, ip_beg, ip_end=None)

source code 
Add a new IP address range.
Parameters:
  • ip_beg (string) - the beginning IP address for the range
  • ip_end (string) - the ending IP address for the range (optional, defaults to the beginning IP address)

_import_ipv4(self, entrylist)

source code 
Initialize an empty IPv4 storage with IPv4 address ranges.
Parameters:
  • entrylist (list of (long, long)) - the IPv4 address ranges to start with

_import_ipv6(self, entrylist)

source code 
Initialize an empty IPv6 storage with IPv6 address ranges.
Parameters:
  • entrylist (list of (long, long)) - the IPv6 address ranges to start with

includes(self, ip)

source code 
Determine whether the IP address is included in any of the ranges.
Parameters:
  • ip (string) - the IP address to check
Returns: boolean
whether the IP address is in one of the ranges

read_rangelist(self, file)

source code 

Parse a file for lists of IPv4 address ranges to initialize the empty storage with.

The file to parse must have lines in the format 'whatever:whatever:ip-ip'. The 'whatever' will be ignored, and the IP addresses must be in IPv4 format. If the range is only a single IP address, omit the '-' and the second 'ip'. Empty lines will be ignored, as will lines beginning with '#' which can be used for comments.
Parameters:
  • file (string) - the name of the file to parse