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

Class CarrierApi

source code

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.
source code
 
get_data_file_copyright(self)
Returns the data file copyright text
source code
 
get_data_file_creation_date(self)
Returns the data file creation date in ISO8601 format
source code
 
get_data_file_version(self)
Returns the version of the data file
source code
 
get_properties(self, ipv4)
Get the Carrier properties for a given IP address.
source code
 
get_property(self, ipv4, propertyName)
Try and get a specific property for a given IP address.
source code
 
get_property_names(self)
A set of all the possible property names.
source code
 
_dataLoaded(self)
Checks to make sure the data file is loaded.
source code
 
_property_name_exists(self, propertyName)
Check if the given propertyName is not None and exists in the data file.
source code
 
property_name_exists(self, propertyName) source code

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.
source code
 
get_ip(keyVals)
Extracts and cleans an IP address from the headerValue.
source code
 
is_public_ip(ipv4)
An IP address is considered public if it is not in any of the following ranges: 1) any local address IP: 0
source code
 
extract_ip(headerName, headerValue) source code
Class Variables [hide private]
  _HEADERS_TO_CHECK = ['x-forwarded-for', 'client-ip', 'x-client...
  _VERSION = '1.0.1'
  _PRIVATE = ([0, 4294967295], [2130706432, 4278190080], [323223...
  _data = None
hash(x)
  _MISSING_DATA_EX = 'No data file loaded, load data with load_d...
  _INVALID_PROP_EX = 'Property name "%s" does not exist'
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

load_data_from_file(self, path)

source code 

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

get_property(self, ipv4, propertyName)

source code 

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)

source code 

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)

source code 

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

source code 

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

get_ip(keyVals)
Static Method

source code 

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(ipv4)
Static Method

source code 

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:
['x-forwarded-for',
 'client-ip',
 'x-client-ip',
 'rlnclientipaddr',
 'proxy-client-ip',
 'wl-proxy-client-ip',
 'x-Forwarded',
 'forwarded-for',
...

_PRIVATE

Value:
([0, 4294967295],
 [2130706432, 4278190080],
 [3232235520, 4294901760],
 [2886729728, 4293918720],
 [167772160, 4278190080],
 [2851995648, 65535])

_MISSING_DATA_EX

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