l.s.g.helpers : module documentation

Part of lp.services.geoip

No module docstring
Function request_country Adapt a request to the country in which the request was made.
Function ipaddress_from_request Determine the IP address for this request.
def request_country(request):
Adapt a request to the country in which the request was made.

Return None if the remote IP address is unknown or its country is not in our database.

This information is not reliable and trivially spoofable - use it only for selecting sane defaults.

def ipaddress_from_request(request):

Determine the IP address for this request.

Returns None if the IP address cannot be determined or is localhost.

The remote IP address is determined by the X-Forwarded-For: header, or failing that, the REMOTE_ADDR CGI environment variable.

Because this information is unreliable and trivially spoofable, we don't bother to do much error checking to ensure the IP address is at all valid.

>>> google = '66.102.7.104'
>>> ipaddress_from_request({'REMOTE_ADDR': '1.1.1.1'})
'1.1.1.1'
>>> ipaddress_from_request({
...     'HTTP_X_FORWARDED_FOR': '666.666.666.666',
...     'REMOTE_ADDR': '1.1.1.1'
...     })
'666.666.666.666'
>>> ipaddress_from_request({'HTTP_X_FORWARDED_FOR':
...     'localhost, 127.0.0.1, 255.255.255.255,1.1.1.1'
...     })
'255.255.255.255'
API Documentation for Launchpad, generated by pydoctor at 2018-10-19 00:00:06.