Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
c06e1df76c

+ 1
- 0
oscar/apps/address/abstract_models.py Dosyayı Görüntüle

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

+ 1
- 1
oscar/apps/catalogue/reviews/abstract_models.py Dosyayı Görüntüle

39
     email = models.EmailField(_("Email"), null=True, blank=True)
39
     email = models.EmailField(_("Email"), null=True, blank=True)
40
     homepage = models.URLField(_("URL"), null=True, blank=True)
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
     STATUS_CHOICES = (
43
     STATUS_CHOICES = (
44
         (FOR_MODERATION, _("Requires moderation")),
44
         (FOR_MODERATION, _("Requires moderation")),
45
         (APPROVED, _("Approved")),
45
         (APPROVED, _("Approved")),

+ 0
- 1
oscar/apps/customer/forms.py Dosyayı Görüntüle

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

+ 2
- 0
oscar/apps/dashboard/catalogue/widgets.py Dosyayı Görüntüle

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

+ 1
- 0
oscar/apps/dashboard/ranges/models.py Dosyayı Görüntüle

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

+ 1
- 1
oscar/apps/dashboard/reports/csv_utils.py Dosyayı Görüntüle

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

+ 1
- 1
oscar/apps/dashboard/views.py Dosyayı Görüntüle

123
 
123
 
124
             y_range = []
124
             y_range = []
125
             y_axis_steps = max_value / D(str(segments))
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
                 y_range.append(idx * y_axis_steps)
127
                 y_range.append(idx * y_axis_steps)
128
         else:
128
         else:
129
             y_range = []
129
             y_range = []

+ 1
- 1
oscar/apps/offer/models.py Dosyayı Görüntüle

1208
     # (a) Give a discount off the BASKET total
1208
     # (a) Give a discount off the BASKET total
1209
     # (b) Give a discount off the SHIPPING total
1209
     # (b) Give a discount off the SHIPPING total
1210
     # (a) Trigger a post-order action
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
     affects = None
1212
     affects = None
1213
 
1213
 
1214
     @property
1214
     @property

+ 11
- 10
oscar/apps/payment/bankcards.py Dosyayı Görüntüle

1
+from six.moves import map
1
 VISA, VISA_ELECTRON, MASTERCARD, AMEX, MAESTRO, DISCOVER = (
2
 VISA, VISA_ELECTRON, MASTERCARD, AMEX, MAESTRO, DISCOVER = (
2
     'Visa', 'Visa Electron', 'Mastercard', 'American Express',
3
     'Visa', 'Visa Electron', 'Mastercard', 'American Express',
3
     'Maestro', 'Discover')
4
     'Maestro', 'Discover')
16
     (DINERS_CLUB, (14,), ('300', '301', '302', '303', '304', '305')),
17
     (DINERS_CLUB, (14,), ('300', '301', '302', '303', '304', '305')),
17
     (DINERS_CLUB, (14,), ('36',)),
18
     (DINERS_CLUB, (14,), ('36',)),
18
     (DISCOVER, (16,),
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
     # Diners Club cards match the same pattern as Mastercard.  They are treated
27
     # Diners Club cards match the same pattern as Mastercard.  They are treated
27
     # as Mastercard normally so we put the mastercard pattern first.
28
     # as Mastercard normally so we put the mastercard pattern first.
28
     (DINERS_CLUB, (16,), ('54', '55')),
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
     (VISA, (13, 16), ('4',)),
33
     (VISA, (13, 16), ('4',)),
33
     (VISA_ELECTRON, (16,), ('4026', '417500', '4405', '4508',
34
     (VISA_ELECTRON, (16,), ('4026', '417500', '4405', '4508',
34
                             '4844', '4913', '4917')),
35
                             '4844', '4913', '4917')),

+ 1
- 0
oscar/apps/search/facets.py Dosyayı Görüntüle

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

+ 1
- 0
oscar/core/ajax.py Dosyayı Görüntüle

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

+ 3
- 1
oscar/core/compat.py Dosyayı Görüntüle

4
 from django.utils import six
4
 from django.utils import six
5
 from django.utils.html import conditional_escape
5
 from django.utils.html import conditional_escape
6
 from django.utils.safestring import mark_safe
6
 from django.utils.safestring import mark_safe
7
+from six.moves import map
7
 
8
 
8
 
9
 
9
 def get_user_model():
10
 def get_user_model():
73
 # Code from http://python3porting.com/problems.html
74
 # Code from http://python3porting.com/problems.html
74
 # Classes renamed to include CSV. Unused 'codecs' import is dropped.
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
 PY3 = sys.version > '3'
80
 PY3 = sys.version > '3'
79
 
81
 

+ 5
- 3
oscar/management/commands/oscar_fork_statics.py Dosyayı Görüntüle

1
+from __future__ import print_function
2
+from __future__ import print_function
1
 import logging
3
 import logging
2
 import os
4
 import os
3
 import shutil
5
 import shutil
30
 
32
 
31
         source = os.path.realpath(
33
         source = os.path.realpath(
32
             os.path.join(os.path.dirname(__file__), '../../static'))
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
         shutil.copytree(source, destination)
36
         shutil.copytree(source, destination)
35
 
37
 
36
         # Check if this new folder is in STATICFILES_DIRS
38
         # Check if this new folder is in STATICFILES_DIRS
37
         if destination not in settings.STATICFILES_DIRS:
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 Dosyayı Görüntüle

1
+from __future__ import print_function
1
 from django.core.management.base import BaseCommand, CommandError
2
 from django.core.management.base import BaseCommand, CommandError
2
 from django.db.models import get_model
3
 from django.db.models import get_model
3
 
4
 
26
         }
27
         }
27
         messages = CommunicationEventType.objects.get_and_render(
28
         messages = CommunicationEventType.objects.get_and_render(
28
             args[0], ctx)
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 Dosyayı Görüntüle

1
+from __future__ import print_function
2
+from __future__ import print_function
1
 import cProfile
3
 import cProfile
2
 import pstats
4
 import pstats
3
 import time
5
 import time
18
         result = prof.runcall(fn, *args, **kwargs)
20
         result = prof.runcall(fn, *args, **kwargs)
19
         duration = time.time() - start
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
         prof.dump_stats(filepath)
25
         prof.dump_stats(filepath)
24
 
26
 
25
-        print "Printing stats"
27
+        print("Printing stats")
26
         stats = pstats.Stats(filepath)
28
         stats = pstats.Stats(filepath)
27
         stats.sort_stats('cumulative')
29
         stats.sort_stats('cumulative')
28
         stats.print_stats()
30
         stats.print_stats()

+ 4
- 2
oscar/profiling/middleware.py Dosyayı Görüntüle

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

+ 2
- 2
oscar/templatetags/category_tags.py Dosyayı Görüntüle

102
             # Update previous node's info
102
             # Update previous node's info
103
             info['has_children'] = prev_depth is None or depth > prev_depth
103
             info['has_children'] = prev_depth is None or depth > prev_depth
104
             if prev_depth is not None and depth < prev_depth:
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
             info = {'num_to_close': [],
107
             info = {'num_to_close': [],
108
                     'level': depth - start_depth}
108
                     'level': depth - start_depth}
111
 
111
 
112
         if prev_depth is not None:
112
         if prev_depth is not None:
113
             # close last leaf
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
             info['has_children'] = prev_depth > prev_depth
115
             info['has_children'] = prev_depth > prev_depth
116
 
116
 
117
         return annotated_categories
117
         return annotated_categories

+ 1
- 0
oscar/views/generic.py Dosyayı Görüntüle

12
 
12
 
13
 import phonenumbers
13
 import phonenumbers
14
 from oscar.core.phonenumber import PhoneNumber
14
 from oscar.core.phonenumber import PhoneNumber
15
+from six.moves import map
15
 
16
 
16
 
17
 
17
 class PostActionMixin(object):
18
 class PostActionMixin(object):

+ 1
- 0
runtests.py Dosyayı Görüntüle

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

+ 2
- 1
setup.py Dosyayı Görüntüle

6
 - Ensure the version is correctly set in oscar.__init__.py
6
 - Ensure the version is correctly set in oscar.__init__.py
7
 - Run: python setup.py sdist upload
7
 - Run: python setup.py sdist upload
8
 """
8
 """
9
+from __future__ import print_function
9
 
10
 
10
 from setuptools import setup, find_packages
11
 from setuptools import setup, find_packages
11
 import os
12
 import os
94
         "    %s\n\nHappy hacking!") % (mailing_list, mailing_list_url,
95
         "    %s\n\nHappy hacking!") % (mailing_list, mailing_list_url,
95
                                        docs_url, twitter_url)
96
                                        docs_url, twitter_url)
96
     line = '=' * 82
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 Dosyayı Görüntüle

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

+ 1
- 1
sites/demo/apps/order/processing.py Dosyayı Görüntüle

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

+ 1
- 1
sites/demo/urls.py Dosyayı Görüntüle

5
 from stores.app import application as stores_app
5
 from stores.app import application as stores_app
6
 from stores.dashboard.app import application as dashboard_app
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
 from datacash.dashboard.app import application as datacash_app
9
 from datacash.dashboard.app import application as datacash_app
10
 
10
 
11
 # These need to be imported into this namespace
11
 # These need to be imported into this namespace

+ 1
- 1
sites/sandbox/settings_mysql.py Dosyayı Görüntüle

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

+ 1
- 1
sites/sandbox/settings_postgres.py Dosyayı Görüntüle

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

+ 1
- 1
sites/sandbox/settings_sphinx.py Dosyayı Görüntüle

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

Loading…
İptal
Kaydet