Skip to content

Commit 59d9e3e

Browse files
authored
Merge pull request #5065 from rtfd/humitos/deprecate-python2
Upgrade all code to be Python3 only
2 parents 28845c7 + f68d84a commit 59d9e3e

File tree

352 files changed

+7362
-8181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

352 files changed

+7362
-8181
lines changed

.travis.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
language: python
22
python:
3-
- 2.7
43
- 3.6
5-
env:
6-
- ES_VERSION=1.3.9 ES_DOWNLOAD_URL=https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
74
matrix:
85
include:
6+
- python: 3.6
7+
env: TOXENV=py36 ES_VERSION=1.3.9 ES_DOWNLOAD_URL=https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
98
- python: 3.6
109
env: TOXENV=docs
1110
- python: 3.6
@@ -45,6 +44,6 @@ notifications:
4544

4645
branches:
4746
only:
48-
- master
47+
- master
4948
- rel # Community release branch
5049
- relcorp # Corporate release branch

common

readthedocs/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
23
"""Read the Docs."""
34

45
import os.path
56

6-
from future.moves.configparser import RawConfigParser
7+
from configparser import RawConfigParser
78

89

910
def get_version(setupcfg_path):

readthedocs/analytics/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
"""App init"""
1+
# -*- coding: utf-8 -*-
22

3-
default_app_config = 'readthedocs.analytics.apps.AnalyticsAppConfig' # noqa
3+
"""App init."""
4+
5+
default_app_config = 'readthedocs.analytics.apps.AnalyticsAppConfig' # noqa

readthedocs/analytics/apps.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
13
"""Django app config for the analytics app."""
24

3-
from __future__ import absolute_import
45
from django.apps import AppConfig
56

67

78
class AnalyticsAppConfig(AppConfig):
89

9-
"""Analytics app init code"""
10+
"""Analytics app init code."""
1011

1112
name = 'readthedocs.analytics'
1213
verbose_name = 'Analytics'

readthedocs/analytics/tasks.py

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"""Tasks for Read the Docs' analytics"""
1+
# -*- coding: utf-8 -*-
22

3-
from __future__ import absolute_import
3+
"""Tasks for Read the Docs' analytics."""
44

55
from django.conf import settings
66

@@ -11,24 +11,24 @@
1111

1212

1313
DEFAULT_PARAMETERS = {
14-
'v': '1', # analytics version (always 1)
15-
'aip': '1', # anonymize IP
14+
'v': '1', # analytics version (always 1)
15+
'aip': '1', # anonymize IP
1616
'tid': settings.GLOBAL_ANALYTICS_CODE,
1717

1818
# User data
19-
'uip': None, # User IP address
20-
'ua': None, # User agent
19+
'uip': None, # User IP address
20+
'ua': None, # User agent
2121

2222
# Application info
2323
'an': 'Read the Docs',
24-
'av': readthedocs.__version__, # App version
24+
'av': readthedocs.__version__, # App version
2525
}
2626

2727

2828
@app.task(queue='web')
2929
def analytics_pageview(url, title=None, **kwargs):
3030
"""
31-
Send a pageview to Google Analytics
31+
Send a pageview to Google Analytics.
3232
3333
:see: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
3434
:param url: the URL of the pageview
@@ -37,18 +37,21 @@ def analytics_pageview(url, title=None, **kwargs):
3737
"""
3838
data = {
3939
't': 'pageview',
40-
'dl': url, # URL of the pageview (required)
41-
'dt': title, # Title of the page
40+
'dl': url, # URL of the pageview (required)
41+
'dt': title, # Title of the page
4242
}
4343
data.update(DEFAULT_PARAMETERS)
4444
data.update(kwargs)
4545
send_to_analytics(data)
4646

4747

4848
@app.task(queue='web')
49-
def analytics_event(event_category, event_action, event_label=None, event_value=None, **kwargs):
49+
def analytics_event(
50+
event_category, event_action, event_label=None, event_value=None,
51+
**kwargs
52+
):
5053
"""
51-
Send an analytics event to Google Analytics
54+
Send an analytics event to Google Analytics.
5255
5356
:see: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event
5457
:param event_category: the category of the event
@@ -58,11 +61,11 @@ def analytics_event(event_category, event_action, event_label=None, event_value=
5861
:param kwargs: extra event parameters to send to GA
5962
"""
6063
data = {
61-
't': 'event', # GA event - don't change
62-
'ec': event_category, # Event category (required)
63-
'ea': event_action, # Event action (required)
64-
'el': event_label, # Event label
65-
'ev': event_value, # Event value (numeric)
64+
't': 'event', # GA event - don't change
65+
'ec': event_category, # Event category (required)
66+
'ea': event_action, # Event action (required)
67+
'el': event_label, # Event label
68+
'ev': event_value, # Event value (numeric)
6669
}
6770
data.update(DEFAULT_PARAMETERS)
6871
data.update(kwargs)

readthedocs/analytics/tests.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from __future__ import absolute_import, unicode_literals
2-
1+
# -*- coding: utf-8 -*-
32
from django.test import TestCase
43

54
from .utils import anonymize_ip_address, anonymize_user_agent
@@ -29,4 +28,3 @@ def test_anonymize_ua(self):
2928
anonymize_user_agent('Some rare user agent'),
3029
'Rare user agent',
3130
)
32-

readthedocs/analytics/utils.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
"""Utilities related to analytics"""
1+
# -*- coding: utf-8 -*-
2+
3+
"""Utilities related to analytics."""
24

3-
from __future__ import absolute_import, unicode_literals
45
import hashlib
6+
import ipaddress
57
import logging
68

9+
import requests
710
from django.conf import settings
8-
from django.utils.encoding import force_text, force_bytes
911
from django.utils.crypto import get_random_string
10-
import requests
12+
from django.utils.encoding import force_bytes, force_text
1113
from user_agents import parse
1214

13-
try:
14-
# Python 3.3+ only
15-
import ipaddress
16-
except ImportError:
17-
from .vendor import ipaddress
1815

19-
log = logging.getLogger(__name__) # noqa
16+
log = logging.getLogger(__name__) # noqa
2017

2118

2219
def get_client_ip(request):
23-
"""Gets the real IP based on a request object"""
20+
"""Gets the real IP based on a request object."""
2421
ip_address = request.META.get('REMOTE_ADDR')
2522

2623
# Get the original IP address (eg. "X-Forwarded-For: client, proxy1, proxy2")
@@ -32,7 +29,7 @@ def get_client_ip(request):
3229

3330

3431
def anonymize_ip_address(ip_address):
35-
"""Anonymizes an IP address by zeroing the last 2 bytes"""
32+
"""Anonymizes an IP address by zeroing the last 2 bytes."""
3633
# Used to anonymize an IP by zero-ing out the last 2 bytes
3734
ip_mask = int('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000', 16)
3835

@@ -46,7 +43,7 @@ def anonymize_ip_address(ip_address):
4643

4744

4845
def anonymize_user_agent(user_agent):
49-
"""Anonymizes rare user agents"""
46+
"""Anonymizes rare user agents."""
5047
# If the browser family is not recognized, this is a rare user agent
5148
parsed_ua = parse(user_agent)
5249
if parsed_ua.browser.family == 'Other' or parsed_ua.os.family == 'Other':
@@ -56,7 +53,7 @@ def anonymize_user_agent(user_agent):
5653

5754

5855
def send_to_analytics(data):
59-
"""Sends data to Google Analytics"""
56+
"""Sends data to Google Analytics."""
6057
if data.get('uip') and data.get('ua'):
6158
data['cid'] = generate_client_id(data['uip'], data['ua'])
6259

@@ -74,7 +71,7 @@ def send_to_analytics(data):
7471
resp = requests.post(
7572
'https://www.google-analytics.com/collect',
7673
data=data,
77-
timeout=3, # seconds
74+
timeout=3, # seconds
7875
)
7976
except requests.Timeout:
8077
log.warning('Timeout sending to Google Analytics')
@@ -85,10 +82,10 @@ def send_to_analytics(data):
8582

8683
def generate_client_id(ip_address, user_agent):
8784
"""
88-
Create an advertising ID
85+
Create an advertising ID.
8986
90-
This simplifies things but essentially if a user has the same IP and same UA,
91-
this will treat them as the same user for analytics purposes
87+
This simplifies things but essentially if a user has the same IP and same
88+
UA, this will treat them as the same user for analytics purposes
9289
"""
9390
salt = b'advertising-client-id'
9491

readthedocs/analytics/vendor/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)