Package mobi :: Package mtld :: Package da :: Package carrier :: Module carrier_api :: Class CarrierApi
[hide private]
[frames] | no frames]

Class CarrierApi

object --+
         |
        CarrierApi

A list of HTTP headers to choose the original client IP address from. In addition to these the REMOTE_ADDR is also used as a final fallback.

Instance Methods [hide private]
 
load_data_from_file(self, path)
Load the data file from the provided path.
 
get_data_file_copyright(self)
Returns the data file copyright text
 
get_data_file_creation_date(self)
Returns the data file creation date in ISO8601 format
 
get_data_file_version(self)
Returns the version of the data file
 
get_properties(self, ipv4)
Get the Carrier properties for a given IP address.
 
get_property(self, ipv4, propertyName)
Try and get a specific property for a given IP address.
 
get_property_names(self)
A set of all the possible property names.
 
_dataLoaded(self)
Checks to make sure the data file is loaded.
 
_property_name_exists(self, propertyName)
Check if the given propertyName is not None and exists in the data file.
 
get_ip(self, keyVals)
Extracts and cleans an IP address from the headerValue.
 
property_name_exists(self, propertyName)
 
is_public_ip(self, ipv4)
An IP address is considered public if it is not in any of the following ranges: 1) any local address IP: 0
 
extract_ip(self, headerName, headerValue)
 
is_ip_special(self, ip)

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
_normaliseKeys(keyVals)
Normalise the keys in the passed in key value map.
Class Variables [hide private]
  _HEADERS_TO_CHECK = [u'x-forwarded-for', u'client-ip', u'x-cli...
  _VERSION = u'CARRIER_API_VERSION'
  _PRIVATE = ([0, 4278190080], [2130706432, 4278190080], [323223...
  _data = None
hash(x)
  _ip_special = None
hash(x)
  _SPECIAL_RANGE_LOW_LIMIT = 10
  _SPECIAL_RANGE_HIGH_LIMIT = 18
  _MISSING_DATA_EX = u'No data file loaded, load data with load_...
  _INVALID_PROP_EX = u'Property name "%s" does not exist'
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

load_data_from_file(self, path)

 

Load the data file from the provided path. The data file is reloaded every tme this method is called.

get_property(self, ipv4, propertyName)

 

Try and get a specific property for a given IP address. Note : If mutiple properties are needed for the same IP it is more efficient to call properties() once than repeated calls to property()

get_property_names(self)

 

A set of all the possible property names. The set contains PropertyName objects that each have a string name and an associated data type.

_property_name_exists(self, propertyName)

 

Check if the given propertyName is not None and exists in the data file. Calls to this method must be sure that the data object is already loaded.

_normaliseKeys(keyVals)
Static Method

 

Normalise the keys in the passed in key value map. This lower-cases the keys, replaces "_" with "-" and removes any HTTP_ prefix.

get_ip(self, keyVals)

 

Extracts and cleans an IP address from the headerValue. Some headers such as "X-Forwarded-For" can contain multiple IP addresses such as: clientIP, proxy1, proxy2...

is_public_ip(self, ipv4)

 

An IP address is considered public if it is not
in any of the following ranges:
1) any local address
  IP:  0

2) a local loopback address
  range:  127/8

3) a site local address i.e. IP is in any of the ranges:
  range:  10/8
  range:  172.16/12
  range:  192.168/16

4) a link local address


Class Variable Details [hide private]

_HEADERS_TO_CHECK

Value:
[u'x-forwarded-for',
 u'client-ip',
 u'x-client-ip',
 u'rlnclientipaddr',
 u'proxy-client-ip',
 u'wl-proxy-client-ip',
 u'x-Forwarded',
 u'forwarded-for',
...

_PRIVATE

Value:
([0, 4278190080],
 [2130706432, 4278190080],
 [3232235520, 4294901760],
 [2886729728, 4293918720],
 [167772160, 4278190080],
 [2851995648, 4294901760],
 [1681915904, 4290772992],
 [3221225472, 4294967288],
...

_MISSING_DATA_EX

Value:
u'No data file loaded, load data with load_data_from_file()'