Переглянути джерело

Python 3 fixes caught by python-modernize

python-modernize (https://github.com/mitsuhiko/python-modernize) is a
useful wrapper around 2to3 which comes with sane defaults.

The fixes below were generated by running

    python-modernize --compat-unicode -w .

and then fixing all lint errors.
master
Maik Hoepfel 11 роки тому
джерело
коміт
c06e1df76c

+ 1
- 0
oscar/apps/address/abstract_models.py Переглянути файл

@@ -7,6 +7,7 @@ from django.core import exceptions
7 7
 
8 8
 from oscar.core.compat import AUTH_USER_MODEL
9 9
 from oscar.models.fields import UppercaseCharField, PhoneNumberField
10
+from six.moves import filter
10 11
 
11 12
 
12 13
 class AbstractAddress(models.Model):

+ 1
- 1
oscar/apps/catalogue/reviews/abstract_models.py Переглянути файл

@@ -39,7 +39,7 @@ class AbstractProductReview(models.Model):
39 39
     email = models.EmailField(_("Email"), null=True, blank=True)
40 40
     homepage = models.URLField(_("URL"), null=True, blank=True)
41 41
 
42
-    FOR_MODERATION, APPROVED, REJECTED = range(0, 3)
42
+    FOR_MODERATION, APPROVED, REJECTED = list(range(0, 3))
43 43
     STATUS_CHOICES = (
44 44
         (FOR_MODERATION, _("Requires moderation")),
45 45
         (APPROVED, _("Approved")),

+ 0
- 1
oscar/apps/customer/forms.py Переглянути файл

@@ -5,7 +5,6 @@ from django import forms
5 5
 from django.conf import settings
6 6
 from django.contrib.auth import forms as auth_forms
7 7
 from django.contrib.auth.forms import AuthenticationForm
8
-from django.contrib.auth.tokens import default_token_generator
9 8
 from django.contrib.sites.models import get_current_site
10 9
 from django.core import validators
11 10
 from django.core.exceptions import ObjectDoesNotExist

+ 2
- 0
oscar/apps/dashboard/catalogue/widgets.py Переглянути файл

@@ -3,6 +3,8 @@ from django.forms.util import flatatt
3 3
 from django.core.urlresolvers import reverse
4 4
 from django.utils.safestring import mark_safe
5 5
 from django import forms
6
+from six.moves import filter
7
+from six.moves import map
6 8
 
7 9
 
8 10
 class ProductSelect(forms.Widget):

+ 1
- 0
oscar/apps/dashboard/ranges/models.py Переглянути файл

@@ -4,6 +4,7 @@ from django.utils.translation import ugettext_lazy as _
4 4
 from django.db import models
5 5
 from django.utils.timezone import now
6 6
 from oscar.core.compat import AUTH_USER_MODEL
7
+from six.moves import filter
7 8
 
8 9
 Product = models.get_model('catalogue', 'Product')
9 10
 

+ 1
- 1
oscar/apps/dashboard/reports/csv_utils.py Переглянути файл

@@ -82,7 +82,7 @@ class CsvUnicodeReader(object):
82 82
         self.reader = csv.reader(f, dialect=dialect, **kwargs)
83 83
 
84 84
     def next(self):
85
-        row = self.reader.next()
85
+        row = six.advance_iterator(self.reader)
86 86
         return [six.text_type(s).encode("utf-8") for s in row]
87 87
 
88 88
     def __iter__(self):

+ 1
- 1
oscar/apps/dashboard/views.py Переглянути файл

@@ -123,7 +123,7 @@ class IndexView(TemplateView):
123 123
 
124 124
             y_range = []
125 125
             y_axis_steps = max_value / D(str(segments))
126
-            for idx in reversed(range(segments + 1)):
126
+            for idx in reversed(list(range(segments + 1))):
127 127
                 y_range.append(idx * y_axis_steps)
128 128
         else:
129 129
             y_range = []

+ 1
- 1
oscar/apps/offer/models.py Переглянути файл

@@ -1208,7 +1208,7 @@ class ApplicationResult(object):
1208 1208
     # (a) Give a discount off the BASKET total
1209 1209
     # (b) Give a discount off the SHIPPING total
1210 1210
     # (a) Trigger a post-order action
1211
-    BASKET, SHIPPING, POST_ORDER = range(0, 3)
1211
+    BASKET, SHIPPING, POST_ORDER = list(range(0, 3))
1212 1212
     affects = None
1213 1213
 
1214 1214
     @property

+ 11
- 10
oscar/apps/payment/bankcards.py Переглянути файл

@@ -1,3 +1,4 @@
1
+from six.moves import map
1 2
 VISA, VISA_ELECTRON, MASTERCARD, AMEX, MAESTRO, DISCOVER = (
2 3
     'Visa', 'Visa Electron', 'Mastercard', 'American Express',
3 4
     'Maestro', 'Discover')
@@ -16,19 +17,19 @@ CARD_TYPES = [
16 17
     (DINERS_CLUB, (14,), ('300', '301', '302', '303', '304', '305')),
17 18
     (DINERS_CLUB, (14,), ('36',)),
18 19
     (DISCOVER, (16,),
19
-     list(map(str, range(622126, 622926))) +
20
-     list(map(str, range(644, 650))) + ['6011', '65']),
21
-    (JCB, (16,), map(str, range(3528, 3590))),
22
-    (LASER, range(16, 20), ('6304', '6706', '6771', '6709')),
23
-    (MAESTRO, range(12, 20), ('5018', '5020', '5038', '5893', '6304',
24
-                              '6759', '6761', '6762', '6763', '0604')),
25
-    (MASTERCARD, (16,), list(map(str, range(51, 56)))),
20
+     list(map(str, list(range(622126, 622926)))) +
21
+     list(map(str, list(range(644, 650)))) + ['6011', '65']),
22
+    (JCB, (16,), map(str, list(range(3528, 3590)))),
23
+    (LASER, list(range(16, 20)), ('6304', '6706', '6771', '6709')),
24
+    (MAESTRO, list(range(12, 20)), ('5018', '5020', '5038', '5893', '6304',
25
+                                    '6759', '6761', '6762', '6763', '0604')),
26
+    (MASTERCARD, (16,), list(map(str, list(range(51, 56))))),
26 27
     # Diners Club cards match the same pattern as Mastercard.  They are treated
27 28
     # as Mastercard normally so we put the mastercard pattern first.
28 29
     (DINERS_CLUB, (16,), ('54', '55')),
29
-    (SOLO, range(16, 20), ('6334', '6767')),
30
-    (SWITCH, range(16, 20), ('4903', '4905', '4911', '4936',
31
-                             '564182', '633110', '6333', '6759')),
30
+    (SOLO, list(range(16, 20)), ('6334', '6767')),
31
+    (SWITCH, list(range(16, 20)), ('4903', '4905', '4911', '4936',
32
+                                   '564182', '633110', '6333', '6759')),
32 33
     (VISA, (13, 16), ('4',)),
33 34
     (VISA_ELECTRON, (16,), ('4026', '417500', '4405', '4508',
34 35
                             '4844', '4913', '4917')),

+ 1
- 0
oscar/apps/search/facets.py Переглянути файл

@@ -1,5 +1,6 @@
1 1
 from django.conf import settings
2 2
 from purl import URL
3
+from six.moves import map
3 4
 
4 5
 
5 6
 def facet_data(request, form, results):  # noqa (too complex (10))

+ 1
- 0
oscar/core/ajax.py Переглянути файл

@@ -1,5 +1,6 @@
1 1
 import six
2 2
 from django.contrib import messages
3
+from six.moves import map
3 4
 
4 5
 
5 6
 class FlashMessages(object):

+ 3
- 1
oscar/core/compat.py Переглянути файл

@@ -4,6 +4,7 @@ from django.core.exceptions import ImproperlyConfigured
4 4
 from django.utils import six
5 5
 from django.utils.html import conditional_escape
6 6
 from django.utils.safestring import mark_safe
7
+from six.moves import map
7 8
 
8 9
 
9 10
 def get_user_model():
@@ -73,7 +74,8 @@ urlparse = _urlparse
73 74
 # Code from http://python3porting.com/problems.html
74 75
 # Classes renamed to include CSV. Unused 'codecs' import is dropped.
75 76
 
76
-import sys, csv
77
+import sys
78
+import csv
77 79
 
78 80
 PY3 = sys.version > '3'
79 81
 

+ 5
- 3
oscar/management/commands/oscar_fork_statics.py Переглянути файл

@@ -1,3 +1,5 @@
1
+from __future__ import print_function
2
+from __future__ import print_function
1 3
 import logging
2 4
 import os
3 5
 import shutil
@@ -30,10 +32,10 @@ class Command(BaseCommand):
30 32
 
31 33
         source = os.path.realpath(
32 34
             os.path.join(os.path.dirname(__file__), '../../static'))
33
-        print "Copying Oscar's static files to %s" % (destination,)
35
+        print("Copying Oscar's static files to %s" % (destination,))
34 36
         shutil.copytree(source, destination)
35 37
 
36 38
         # Check if this new folder is in STATICFILES_DIRS
37 39
         if destination not in settings.STATICFILES_DIRS:
38
-            print ("You need to add %s to STATICFILES_DIRS in order for your "
39
-                   "local overrides to be picked up") % destination
40
+            print(("You need to add %s to STATICFILES_DIRS in order for your "
41
+                   "local overrides to be picked up") % destination)

+ 3
- 2
oscar/management/commands/oscar_generate_email_content.py Переглянути файл

@@ -1,3 +1,4 @@
1
+from __future__ import print_function
1 2
 from django.core.management.base import BaseCommand, CommandError
2 3
 from django.db.models import get_model
3 4
 
@@ -26,5 +27,5 @@ class Command(BaseCommand):
26 27
         }
27 28
         messages = CommunicationEventType.objects.get_and_render(
28 29
             args[0], ctx)
29
-        print "Subject: %s\nBody:\n\n%s\nBody HTML:\n\n%s" % (
30
-            messages['subject'], messages['body'], messages['html'])
30
+        print("Subject: %s\nBody:\n\n%s\nBody HTML:\n\n%s" % (
31
+            messages['subject'], messages['body'], messages['html']))

+ 5
- 3
oscar/profiling/decorators.py Переглянути файл

@@ -1,3 +1,5 @@
1
+from __future__ import print_function
2
+from __future__ import print_function
1 3
 import cProfile
2 4
 import pstats
3 5
 import time
@@ -18,11 +20,11 @@ def profile(fn):
18 20
         result = prof.runcall(fn, *args, **kwargs)
19 21
         duration = time.time() - start
20 22
 
21
-        print "Function ran in %.6f seconds - output written to %s" % (
22
-            duration, filepath)
23
+        print("Function ran in %.6f seconds - output written to %s" % (
24
+            duration, filepath))
23 25
         prof.dump_stats(filepath)
24 26
 
25
-        print "Printing stats"
27
+        print("Printing stats")
26 28
         stats = pstats.Stats(filepath)
27 29
         stats.sort_stats('cumulative')
28 30
         stats.print_stats()

+ 4
- 2
oscar/profiling/middleware.py Переглянути файл

@@ -1,3 +1,5 @@
1
+from __future__ import print_function
2
+from __future__ import print_function
1 3
 import sys
2 4
 import tempfile
3 5
 import hotshot
@@ -13,10 +15,10 @@ def profile_this(fn):
13 15
         filepath = "/tmp/%s.profile" % fn.__name__
14 16
         prof = cProfile.Profile()
15 17
         ret = prof.runcall(fn, *args, **kwargs)
16
-        print "Writing to %s" % filepath
18
+        print("Writing to %s" % filepath)
17 19
         prof.dump_stats(filepath)
18 20
 
19
-        print "Printing stats"
21
+        print("Printing stats")
20 22
         stats = pstats.Stats(filepath)
21 23
         stats.sort_stats('cumulative')
22 24
         stats.print_stats()

+ 2
- 2
oscar/templatetags/category_tags.py Переглянути файл

@@ -102,7 +102,7 @@ class CategoryTreeNode(template.Node):
102 102
             # Update previous node's info
103 103
             info['has_children'] = prev_depth is None or depth > prev_depth
104 104
             if prev_depth is not None and depth < prev_depth:
105
-                info['num_to_close'] = range(0, prev_depth - depth)
105
+                info['num_to_close'] = list(range(0, prev_depth - depth))
106 106
 
107 107
             info = {'num_to_close': [],
108 108
                     'level': depth - start_depth}
@@ -111,7 +111,7 @@ class CategoryTreeNode(template.Node):
111 111
 
112 112
         if prev_depth is not None:
113 113
             # close last leaf
114
-            info['num_to_close'] = range(0, prev_depth - start_depth)
114
+            info['num_to_close'] = list(range(0, prev_depth - start_depth))
115 115
             info['has_children'] = prev_depth > prev_depth
116 116
 
117 117
         return annotated_categories

+ 1
- 0
oscar/views/generic.py Переглянути файл

@@ -12,6 +12,7 @@ from django.views.generic.base import View
12 12
 
13 13
 import phonenumbers
14 14
 from oscar.core.phonenumber import PhoneNumber
15
+from six.moves import map
15 16
 
16 17
 
17 18
 class PostActionMixin(object):

+ 1
- 0
runtests.py Переглянути файл

@@ -35,6 +35,7 @@ import logging
35 35
 import warnings
36 36
 
37 37
 from tests.config import configure
38
+from six.moves import map
38 39
 
39 40
 # No logging
40 41
 logging.disable(logging.CRITICAL)

+ 2
- 1
setup.py Переглянути файл

@@ -6,6 +6,7 @@ To release a new version to PyPi:
6 6
 - Ensure the version is correctly set in oscar.__init__.py
7 7
 - Run: python setup.py sdist upload
8 8
 """
9
+from __future__ import print_function
9 10
 
10 11
 from setuptools import setup, find_packages
11 12
 import os
@@ -94,4 +95,4 @@ if len(sys.argv) > 1 and sys.argv[1] == 'develop':
94 95
         "    %s\n\nHappy hacking!") % (mailing_list, mailing_list_url,
95 96
                                        docs_url, twitter_url)
96 97
     line = '=' * 82
97
-    print("\n%s\n%s\n%s" % (line, msg, line))
98
+    print(("\n%s\n%s\n%s" % (line, msg, line)))

+ 7
- 5
sites/demo/apps/bigbang/management/commands/import_product_images.py Переглянути файл

@@ -1,6 +1,8 @@
1
+from __future__ import print_function
2
+from __future__ import print_function
1 3
 import os
2 4
 
3
-from django.core.management.base import BaseCommand, CommandError
5
+from django.core.management.base import BaseCommand
4 6
 from django.core.files import File
5 7
 from PIL import Image
6 8
 
@@ -26,11 +28,11 @@ class Command(BaseCommand):
26 28
 
27 29
     def import_image(self, filepath):
28 30
         try:
29
-	    trial = Image.open(filepath)
31
+            trial = Image.open(filepath)
30 32
             trial.verify()
31 33
         except IOError:
32
-            print "%s is not a valid image file" % filepath
33
-	    return
34
+            print("%s is not a valid image file" % filepath)
35
+            return
34 36
 
35 37
         filename = os.path.basename(filepath)
36 38
         name, __ = os.path.splitext(filename)
@@ -44,7 +46,7 @@ class Command(BaseCommand):
44 46
         try:
45 47
             product = models.Product.objects.get(upc=upc)
46 48
         except Exception:
47
-            print "Product not found: %s" % upc
49
+            print("Product not found: %s" % upc)
48 50
             return
49 51
         try:
50 52
             product_image = models.ProductImage.objects.get(

+ 1
- 1
sites/demo/apps/order/processing.py Переглянути файл

@@ -39,7 +39,7 @@ class EventHandler(processing.EventHandler):
39 39
             datacash_ref = f.fulfill_transaction(
40 40
                 order.number, amount, txn.datacash_reference,
41 41
                 txn.auth_code)
42
-        except exceptions.PaymentError, e:
42
+        except exceptions.PaymentError as e:
43 43
             self.create_note(order, "Attempt to settle %.2f failed: %s" % (
44 44
                 amount, e))
45 45
             raise

+ 1
- 1
sites/demo/urls.py Переглянути файл

@@ -5,7 +5,7 @@ from django.conf.urls.static import static
5 5
 from stores.app import application as stores_app
6 6
 from stores.dashboard.app import application as dashboard_app
7 7
 
8
-from apps.app import application
8
+from .apps.app import application
9 9
 from datacash.dashboard.app import application as datacash_app
10 10
 
11 11
 # These need to be imported into this namespace

+ 1
- 1
sites/sandbox/settings_mysql.py Переглянути файл

@@ -1,4 +1,4 @@
1
-from settings import *
1
+from .settings import *
2 2
 
3 3
 DATABASES = {
4 4
     'default': {

+ 1
- 1
sites/sandbox/settings_postgres.py Переглянути файл

@@ -1,4 +1,4 @@
1
-from settings import *
1
+from .settings import *
2 2
 
3 3
 DATABASES = {
4 4
     'default': {

+ 1
- 1
sites/sandbox/settings_sphinx.py Переглянути файл

@@ -1,4 +1,4 @@
1
-from settings import *
1
+from .settings import *
2 2
 
3 3
 # Remove debug toolbar
4 4
 try:

Завантаження…
Відмінити
Зберегти