~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to tracking/utils.py

  • Committer: franku
  • Author(s): GunChleoc
  • Date: 2016-12-13 18:30:38 UTC
  • mfrom: (438.1.6 pyformat_util)
  • Revision ID: somal@arcor.de-20161213183038-5cgmvfh2fkgmoc1s
adding a script to run pyformat over the code base

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
# this is not intended to be an all-knowing IP address regex
6
6
IP_RE = re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
7
7
 
 
8
 
8
9
def get_ip(request):
9
 
    """
10
 
    Retrieves the remote IP address from the request data.  If the user is
 
10
    """Retrieves the remote IP address from the request data.
 
11
 
 
12
    If the user is
11
13
    behind a proxy, they may have a comma-separated list of IP addresses, so
12
14
    we need to account for that.  In such a case, only the first IP in the
13
15
    list will be retrieved.  Also, some hosts that use a proxy will put the
14
16
    REMOTE_ADDR into HTTP_X_FORWARDED_FOR.  This will handle pulling back the
15
17
    IP from the proper place.
 
18
 
16
19
    """
17
20
 
18
21
    # if neither header contain a value, just use local loopback
33
36
 
34
37
    return ip_address
35
38
 
 
39
 
36
40
def get_timeout():
37
 
    """
38
 
    Gets any specified timeout from the settings file, or use 10 minutes by
39
 
    default
40
 
    """
 
41
    """Gets any specified timeout from the settings file, or use 10 minutes by
 
42
    default."""
41
43
    return getattr(settings, 'TRACKING_TIMEOUT', 10)
42
44
 
 
45
 
43
46
def get_cleanup_timeout():
44
47
    """
45
48
    Gets any specified visitor clean-up timeout from the settings file, or
47
50
    """
48
51
    return getattr(settings, 'TRACKING_CLEANUP_TIMEOUT', 24)
49
52
 
 
53
 
50
54
def u_clean(s):
51
 
    """A strange attempt at cleaning up unicode"""
 
55
    """A strange attempt at cleaning up unicode."""
52
56
 
53
57
    uni = ''
54
58
    try:
68
72
                        uni += '-'
69
73
 
70
74
    return uni.encode('ascii', 'xmlcharrefreplace')
71