Skip to content

Commit f201d15

Browse files
committed
Make a pass w/ python-modernize.
1 parent eee0978 commit f201d15

File tree

268 files changed

+342
-53
lines changed

Some content is hidden

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

268 files changed

+342
-53
lines changed

readthedocs/api/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""API resources"""
2+
from __future__ import absolute_import
23
import logging
34
import json
45
import redis

readthedocs/api/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Slumber API client"""
2+
from __future__ import absolute_import
23
import logging
34

45
from slumber import API

readthedocs/api/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utility classes for api module"""
2+
from __future__ import absolute_import
23
import logging
34

45
from django.core.paginator import Paginator, InvalidPage

readthedocs/bookmarks/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Django admin interface for `~bookmarks.models.Bookmark`."""
22

3+
from __future__ import absolute_import
34
from django.contrib import admin
45
from readthedocs.bookmarks.models import Bookmark
56

readthedocs/bookmarks/migrations/0001_initial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
from __future__ import absolute_import
45
from django.db import models, migrations
56
from django.conf import settings
67

readthedocs/bookmarks/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Models for the bookmarks app."""
22

3+
from __future__ import absolute_import
34
from django.db import models
45
from django.contrib.auth.models import User
56
from django.utils.translation import ugettext_lazy as _, ugettext

readthedocs/bookmarks/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""URL config for the bookmarks app."""
22

3+
from __future__ import absolute_import
34
from django.conf.urls import url
45
from readthedocs.bookmarks.views import BookmarkListView
56
from readthedocs.bookmarks.views import BookmarkAddView, BookmarkRemoveView

readthedocs/bookmarks/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Views for the bookmarks app."""
22

3+
from __future__ import absolute_import
34
from django.contrib.auth.decorators import login_required
45
from django.http import HttpResponse, HttpResponseRedirect
56
from django.http import HttpResponseBadRequest

readthedocs/builds/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Django admin interface for `~builds.models.Build` and related models."""
22

3+
from __future__ import absolute_import
34
from django.contrib import admin
45
from readthedocs.builds.models import Build, VersionAlias, Version, BuildCommandResult
56
from guardian.admin import GuardedModelAdmin

readthedocs/builds/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Constants for the builds app."""
22

3+
from __future__ import absolute_import
34
from django.utils.translation import ugettext_lazy as _
45

56
BUILD_STATE_TRIGGERED = 'triggered'

readthedocs/builds/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Django forms for the builds app."""
22

3+
from __future__ import absolute_import
34
from django import forms
45

56
from readthedocs.builds.models import VersionAlias, Version

readthedocs/builds/migrations/0001_initial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
from __future__ import absolute_import
45
from django.db import models, migrations
56
import readthedocs.builds.version_slug
67
import taggit.managers

readthedocs/builds/migrations/0002_build_command_initial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
from __future__ import absolute_import
45
from django.db import models, migrations
56
import readthedocs.builds.models
67

readthedocs/builds/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Models for the builds app."""
22

3+
from __future__ import absolute_import
34
import logging
45
import re
56
import os.path

readthedocs/builds/signals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Build signals"""
22

3+
from __future__ import absolute_import
34
import django.dispatch
45

56

readthedocs/builds/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""URL configuration for builds app."""
22

3+
from __future__ import absolute_import
34
from django.conf.urls import url
45

56
from .views import builds_redirect_detail, builds_redirect_list

readthedocs/builds/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Utilities for the builds app."""
22

3+
from __future__ import absolute_import
34
import re
45

56

readthedocs/builds/version_slug.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
another number would be confusing.
1717
"""
1818

19+
from __future__ import absolute_import
1920
import math
2021
import re
2122
import string
2223
from operator import truediv
2324
from django.db import models
2425
from django.utils.encoding import force_text
26+
from six.moves import range
2527

2628

2729
# Regex breakdown:
@@ -97,7 +99,7 @@ def uniquifying_suffix(self, iteration):
9799
power = int(math.log(iteration, length))
98100
current = iteration
99101
suffix = ''
100-
for exp in reversed(range(0, power + 1)):
102+
for exp in reversed(list(range(0, power + 1))):
101103
digit = int(truediv(current, length ** exp))
102104
suffix += alphabet[digit]
103105
current = current % length ** exp

readthedocs/builds/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Views for builds app."""
22

3+
from __future__ import absolute_import
34
import logging
45

56
from django.shortcuts import get_object_or_404

readthedocs/cdn/purge.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Utility to purge MaxCDN files, if configured."""
22

3+
from __future__ import absolute_import
34
import logging
45

56
from django.conf import settings
7+
from six.moves import range
68

79
log = logging.getLogger(__name__)
810

@@ -14,7 +16,7 @@
1416

1517
def chunks(in_list, chunk_size):
1618
"""Yield successive n-sized chunks from l."""
17-
for i in xrange(0, len(in_list), chunk_size):
19+
for i in range(0, len(in_list), chunk_size):
1820
yield in_list[i:i + chunk_size]
1921

2022
if CDN_USERNAME and CDN_KEY and CDN_SECRET and CDN_SERVICE == 'maxcdn':

readthedocs/comments/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""ModelAdmin configurations for comments app."""
22

3+
from __future__ import absolute_import
34
from django.contrib import admin
45
from .models import DocumentNode, DocumentComment, NodeSnapshot
56

readthedocs/comments/backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Storage backends for the comments app."""
22

3+
from __future__ import absolute_import
34
import json
45

56
from django.core import serializers

readthedocs/comments/migrations/0001_initial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
from __future__ import absolute_import
45
from django.db import models, migrations
56
from django.conf import settings
67

readthedocs/comments/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Models for the comments app."""
22

3+
from __future__ import absolute_import
34
from django.contrib.auth.models import User
45
from django.db import models
56
from django.utils.translation import ugettext_lazy as _

readthedocs/comments/session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Authentication backends for DRF."""
22

3+
from __future__ import absolute_import
34
from rest_framework.authentication import SessionAuthentication
45

56

readthedocs/comments/tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Replace this with more appropriate tests for your application.
66
"""
77

8+
from __future__ import absolute_import
89
from django.test import TestCase
910

1011

readthedocs/comments/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""URL configuration for comments app."""
22

3+
from __future__ import absolute_import
34
from django.conf.urls import url
45

56
from readthedocs.comments import views

readthedocs/comments/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Views for comments app."""
22

3+
from __future__ import absolute_import
34
from django.contrib.auth.decorators import login_required
45
from django.shortcuts import render_to_response
56
from django.template import RequestContext

readthedocs/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Common constants"""
22

3+
from __future__ import absolute_import
34
from readthedocs.builds.version_slug import VERSION_SLUG_REGEX
45
from readthedocs.projects.constants import LANGUAGES_REGEX, PROJECT_SLUG_REGEX
56

readthedocs/core/adapters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Allauth overrides"""
22

3+
from __future__ import absolute_import
34
import pickle
45
import logging
56

readthedocs/core/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Django admin interface for core models"""
22

3+
from __future__ import absolute_import
34
from datetime import datetime, timedelta
45

56
from django.contrib import admin

readthedocs/core/apps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""App configurations for core app."""
22

3+
from __future__ import absolute_import
34
from django.apps import AppConfig
45

56

readthedocs/core/backends.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Email backends for core app."""
22

3+
from __future__ import absolute_import
34
import smtplib
45

56
from django.core.mail.utils import DNS_NAME

readthedocs/core/context_processors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Template context processors for core app."""
22

3+
from __future__ import absolute_import
34
from django.conf import settings
45

56

readthedocs/core/fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Shared model fields and defaults"""
22

3+
from __future__ import absolute_import
34
import binascii
45
import os
56

readthedocs/core/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Forms for core app."""
22

3+
from __future__ import absolute_import
34
import logging
45

56
from haystack.forms import SearchForm

readthedocs/core/management/commands/archive.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Rebuild documentation for all projects"""
22

3+
from __future__ import absolute_import
4+
from __future__ import print_function
35
from glob import glob
46
import os
57
import logging
@@ -31,4 +33,4 @@ def handle(self, *args, **options):
3133
'MEDIA_URL': settings.MEDIA_URL,
3234
}
3335
html = template_loader.get_template('archive/index.html').render(context)
34-
print html
36+
print(html)

readthedocs/core/management/commands/clean_builds.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Clean up stable build paths per project version"""
22

3+
from __future__ import absolute_import
34
from datetime import datetime, timedelta
45
import logging
56
from optparse import make_option

readthedocs/core/management/commands/import_github.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Resync GitHub project for user"""
22

3+
from __future__ import absolute_import
34
from django.core.management.base import BaseCommand
45
from django.contrib.auth.models import User
56

readthedocs/core/management/commands/import_github_language.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
which should contain a proper GitHub Oauth Token for rate limiting.
99
"""
1010

11+
from __future__ import absolute_import
12+
from __future__ import print_function
1113
import os
1214
import requests
1315

@@ -31,7 +33,7 @@ def handle(self, *args, **options):
3133
# pylint: disable=too-many-locals
3234
token = os.environ.get('GITHUB_AUTH_TOKEN')
3335
if not token:
34-
print 'Invalid GitHub token, exiting'
36+
print('Invalid GitHub token, exiting')
3537
return
3638

3739
for project in Project.objects.filter(
@@ -48,7 +50,7 @@ def handle(self, *args, **options):
4850
break
4951

5052
if not user:
51-
print 'No GitHub repo for %s' % repo_url
53+
print('No GitHub repo for %s' % repo_url)
5254
continue
5355

5456
cache_key = '%s-%s' % (user, repo)
@@ -64,15 +66,15 @@ def handle(self, *args, **options):
6466
languages = resp.json()
6567
if not languages:
6668
continue
67-
sorted_langs = sorted(languages.items(), key=lambda x: x[1], reverse=True)
68-
print 'Sorted langs: %s ' % sorted_langs
69+
sorted_langs = sorted(list(languages.items()), key=lambda x: x[1], reverse=True)
70+
print('Sorted langs: %s ' % sorted_langs)
6971
top_lang = sorted_langs[0][0]
7072
else:
71-
print 'Cached top_lang: %s' % top_lang
73+
print('Cached top_lang: %s' % top_lang)
7274
if top_lang in PL_DICT:
7375
slug = PL_DICT[top_lang]
74-
print 'Setting %s to %s' % (repo_url, slug)
76+
print('Setting %s to %s' % (repo_url, slug))
7577
Project.objects.filter(pk=project.pk).update(programming_language=slug)
7678
else:
77-
print 'Language unknown: %s' % top_lang
79+
print('Language unknown: %s' % top_lang)
7880
cache.set(cache_key, top_lang, 60 * 600)

readthedocs/core/management/commands/pull.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Trigger build for project slug"""
22

3+
from __future__ import absolute_import
34
import logging
45

56
from django.core.management.base import BaseCommand

readthedocs/core/management/commands/reindex_elasticsearch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Reindex Elastic Search indexes"""
22

3+
from __future__ import absolute_import
34
import logging
45
from optparse import make_option
56

readthedocs/core/management/commands/set_metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Generate metadata for all projects"""
22

3+
from __future__ import absolute_import
34
import logging
45

56
from django.core.management.base import BaseCommand

readthedocs/core/management/commands/symlink.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Update symlinks for projects"""
22

3+
from __future__ import absolute_import
34
import logging
45

56
from django.core.management.base import BaseCommand

readthedocs/core/management/commands/update_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
./manage.py update_api <slug>
77
"""
88

9+
from __future__ import absolute_import
910
import logging
1011

1112
from django.core.management.base import BaseCommand

0 commit comments

Comments
 (0)