Parcourir la source

Corrected all exceptions to use pep8 naming convention

master
David Winterbottom il y a 14 ans
Parent
révision
39dd0b6508

+ 0
- 2
oscar/apps/basket/models.py Voir le fichier

@@ -1,5 +1,3 @@
1
-from exceptions import Exception
2
-
3 1
 from oscar.apps.basket.abstract_models import (AbstractBasket, AbstractLine, AbstractLineAttribute,
4 2
                                                OPEN, MERGED, SAVED, SUBMITTED)
5 3
 

+ 5
- 5
oscar/apps/checkout/views.py Voir le fichier

@@ -26,8 +26,8 @@ import_module('address.models', ['UserAddress'], locals())
26 26
 import_module('address.forms', ['UserAddressForm'], locals())
27 27
 import_module('shipping.repository', ['Repository'], locals())
28 28
 import_module('customer.models', ['Email'], locals())
29
-import_module('payment.exceptions', ['RedirectRequiredException', 'UnableToTakePaymentException', 
30
-                                     'PaymentException'], locals())
29
+import_module('payment.exceptions', ['RedirectRequired', 'UnableToTakePayment', 
30
+                                     'PaymentError'], locals())
31 31
 import_module('basket.models', ['Basket'], locals())
32 32
 
33 33
 # Standard logger for checkout events
@@ -346,15 +346,15 @@ class PaymentDetailsView(CheckoutSessionMixin, TemplateView):
346 346
             total_incl_tax, total_excl_tax = self.get_order_totals(basket)
347 347
             self.handle_payment(order_number, total_incl_tax, **kwargs)
348 348
             post_payment.send_robust(sender=self, view=self)
349
-        except RedirectRequiredException, e:
349
+        except RedirectRequired, e:
350 350
             # Redirect required (eg PayPal, 3DS)
351 351
             return HttpResponseRedirect(e.url)
352
-        except UnableToTakePaymentException, e:
352
+        except UnableToTakePayment, e:
353 353
             # Something went wrong with payment, need to show
354 354
             # error to the user.  This type of exception is supposed
355 355
             # to set a friendly error message.
356 356
             return self.handle_GET(error=e.message)
357
-        except PaymentException:
357
+        except PaymentError:
358 358
             # Something went wrong which wasn't anticipated.
359 359
             return self.handle_GET(error="A problem occured processing payment.")
360 360
         else:

+ 7
- 7
oscar/apps/image/dynamic/__init__.py Voir le fichier

@@ -1,6 +1,6 @@
1 1
 from oscar.apps.image.dynamic.cache import DiskCache
2
-from oscar.apps.image.dynamic.exceptions import ResizerConfigurationException, \
3
-    ResizerSyntaxException, ResizerFormatException
2
+from oscar.apps.image.dynamic.exceptions import ResizerConfigurationError, \
3
+    ResizerSyntaxError, ResizerFormatError
4 4
 from oscar.apps.image.dynamic.mods import AutotrimMod, CropMod, ResizeMod
5 5
 from oscar.apps.image.dynamic.response_backends import DirectResponse
6 6
 from wsgiref.util import request_uri, application_uri
@@ -25,7 +25,7 @@ def get_class(kls):
25 25
             m = getattr(m, comp)
26 26
         return m
27 27
     except (ImportError, AttributeError), e:
28
-        raise ResizerConfigurationException('Error importing class "%s"' % kls)
28
+        raise ResizerConfigurationError('Error importing class "%s"' % kls)
29 29
 
30 30
 
31 31
 def error404(path, start_response):
@@ -119,12 +119,12 @@ class ImageModifier(object):
119 119
                     [(x.split("-")[0], x.split("-")[1]) for x in param_parts])
120 120
                 self._params['type'] = parts[3]
121 121
             except IndexError:
122
-                raise ResizerSyntaxException("Invalid filename syntax")
122
+                raise ResizerSyntaxError("Invalid filename syntax")
123 123
         else:
124
-            raise ResizerSyntaxException("Invalid filename syntax")
124
+            raise ResizerSyntaxError("Invalid filename syntax")
125 125
 
126 126
         if self._params['type'] not in self.output_formats:
127
-            raise ResizerFormatException("Invalid output format")
127
+            raise ResizerFormatError("Invalid output format")
128 128
 
129 129
     def source_path(self):
130 130
         return os.path.join(self._image_root, self.source_filename)
@@ -192,7 +192,7 @@ class BaseImageHandler(object):
192 192
         try:
193 193
             c = self.cache(path, config)
194 194
             m = self.modifier(path, config)
195
-        except (ResizerSyntaxException, ResizerFormatException), e:
195
+        except (ResizerSyntaxError, ResizerFormatError), e:
196 196
             return error500(path, e, start_response)
197 197
         try:
198 198
             if not c.check(m.source_path()):

+ 3
- 3
oscar/apps/image/dynamic/exceptions.py Voir le fichier

@@ -1,10 +1,10 @@
1
-class ResizerConfigurationException(Exception):
1
+class ResizerConfigurationError(Exception):
2 2
     pass
3 3
 
4 4
 
5
-class ResizerSyntaxException(Exception):
5
+class ResizerSyntaxError(Exception):
6 6
     pass
7 7
 
8 8
 
9
-class ResizerFormatException(Exception):
9
+class ResizerFormatError(Exception):
10 10
     pass

+ 3
- 3
oscar/apps/image/dynamic/response_backends.py Voir le fichier

@@ -1,4 +1,4 @@
1
-from oscar.apps.image.dynamic.exceptions import ResizerConfigurationException
1
+from oscar.apps.image.dynamic.exceptions import ResizerConfigurationError
2 2
 
3 3
 class BaseResponse(object):
4 4
     def __init__(self,config,mime_type,cache,start_response):
@@ -37,10 +37,10 @@ class NginxSendfileResponse(BaseResponse):
37 37
     def build_response(self):
38 38
         if not hasattr(self.cache, 'file_info'):
39 39
             msg = "Cache doesn't implements the method 'file_info'"
40
-            raise ResizerConfigurationException(msg)
40
+            raise ResizerConfigurationError(msg)
41 41
         if not self.config.get('nginx_sendfile_path',None):
42 42
             msg = 'Must provide nginx_sendfile_path in configuration'
43
-            raise ResizerConfigurationException(msg)
43
+            raise ResizerConfigurationError(msg)
44 44
 
45 45
         status = '200 OK'
46 46
         

+ 4
- 2
oscar/apps/image/exceptions.py Voir le fichier

@@ -1,8 +1,10 @@
1
-class ImageImportException(Exception):
1
+class ImageImportError(Exception):
2 2
     pass
3 3
 
4
-class IdenticalImageException(Exception):
4
+
5
+class IdenticalImageError(Exception):
5 6
     pass
6 7
 
8
+
7 9
 class InvalidImageArchive(Exception):
8 10
     pass    

+ 0
- 1
oscar/apps/image/management/commands/import_images.py Voir le fichier

@@ -7,7 +7,6 @@ from django.core.management.base import BaseCommand, CommandError
7 7
 
8 8
 from oscar.core.loading import import_module
9 9
 import_module('image.utils', ['Importer'], locals())
10
-import_module('image.exceptions', ['ImageImportException'], locals())
11 10
 
12 11
 
13 12
 class Command(BaseCommand):

+ 5
- 5
oscar/apps/image/utils.py Voir le fichier

@@ -11,7 +11,7 @@ from django.core.files import File
11 11
 from django.core.exceptions import FieldError
12 12
 
13 13
 from oscar.core.loading import import_module
14
-import_module('image.exceptions', ['ImageImportException', 'IdenticalImageException', 'InvalidImageArchive'], locals())
14
+import_module('image.exceptions', ['ImageImportError', 'IdenticalImageError', 'InvalidImageArchive'], locals())
15 15
 import_module('product.models', ['Item'], locals())
16 16
 import_module('image.models', ['Image'], locals())
17 17
 
@@ -43,14 +43,14 @@ class Importer(object):
43 43
                 except Item.DoesNotExist:
44 44
                     self.logger.warning("No item matching %s='%s'" % (self._field, lookup_value))
45 45
                     stats['num_skipped'] += 1
46
-                except IdenticalImageException:
46
+                except IdenticalImageError:
47 47
                     self.logger.warning(" - Identical image already exists for %s='%s', skipping" % (self._field, lookup_value))
48 48
                     stats['num_skipped'] += 1
49 49
                 except IOError, e:
50
-                    raise ImageImportException('%s is not a valid image (%s)' % (filename, e))    
50
+                    raise ImageImportError('%s is not a valid image (%s)' % (filename, e))    
51 51
                     stats['num_invalid'] += 1
52 52
                 except FieldError, e:
53
-                    raise ImageImportException(e)
53
+                    raise ImageImportError(e)
54 54
                     self._process_image(image_dir, filename)
55 55
             if image_dir != dirname:
56 56
                 shutil.rmtree(image_dir)
@@ -115,7 +115,7 @@ class Importer(object):
115 115
             next_index = existing.display_order + 1
116 116
             try:
117 117
                 if new_data == existing.original.read():
118
-                    raise IdenticalImageException()
118
+                    raise IdenticalImageError()
119 119
             except IOError:
120 120
                 # File probably doesn't exist
121 121
                 existing.delete()

+ 3
- 2
oscar/apps/partner/exceptions.py Voir le fichier

@@ -1,5 +1,6 @@
1
-class ImportException(Exception):
1
+class ImportError(Exception):
2 2
     pass
3 3
 
4
-class CatalogueImportException(Exception):
4
+
5
+class CatalogueImportError(Exception):
5 6
     pass

+ 2
- 2
oscar/apps/partner/management/commands/import_catalogue.py Voir le fichier

@@ -6,7 +6,7 @@ from django.core.management.base import BaseCommand, CommandError
6 6
 
7 7
 from oscar.core.loading import import_module
8 8
 import_module('partner.utils', ['CatalogueImporter'], locals())
9
-import_module('partner.exceptions', ['CatalogueImportException'], locals())
9
+import_module('partner.exceptions', ['CatalogueImportError'], locals())
10 10
 
11 11
 
12 12
 class Command(BaseCommand):
@@ -37,7 +37,7 @@ class Command(BaseCommand):
37 37
             logger.info(" - Importing records from '%s'" % file_path)
38 38
             try:
39 39
                 importer.handle(file_path)
40
-            except CatalogueImportException, e:
40
+            except CatalogueImportError, e:
41 41
                 raise CommandError(str(e))
42 42
             
43 43
     def _get_logger(self):

+ 2
- 2
oscar/apps/partner/management/commands/import_stock.py Voir le fichier

@@ -7,7 +7,7 @@ from django.core.management.base import BaseCommand, CommandError
7 7
 
8 8
 from oscar.core.loading import import_module
9 9
 import_module('partner.utils', ['StockImporter'], locals())
10
-import_module('partner.exceptions', ['ImportException'], locals())
10
+import_module('partner.exceptions', ['ImportError'], locals())
11 11
 
12 12
 
13 13
 class Command(BaseCommand):
@@ -33,7 +33,7 @@ class Command(BaseCommand):
33 33
             logger.info("Starting stock import")
34 34
             logger.info(" - Importing records from '%s'" % args[1])
35 35
             importer.handle(args[1])
36
-        except ImportException, e:
36
+        except ImportError, e:
37 37
             raise CommandError(str(e))
38 38
             
39 39
     def _get_logger(self):

+ 4
- 4
oscar/apps/partner/tests/import_catalogue.py Voir le fichier

@@ -4,7 +4,7 @@ from django.test import TestCase
4 4
 import logging
5 5
 
6 6
 from oscar.apps.partner.utils import CatalogueImporter
7
-from oscar.apps.partner.exceptions import ImportException
7
+from oscar.apps.partner.exceptions import ImportError
8 8
 from oscar.apps.product.models import ItemClass, Item
9 9
 from oscar.apps.partner.models import Partner, StockRecord
10 10
 from oscar.test.helpers import create_product
@@ -27,17 +27,17 @@ class CommandEdgeCasesTest(TestCase):
27 27
 
28 28
     def test_sending_no_file_argument_raises_exception(self):
29 29
         self.importer.afile = None
30
-        with self.assertRaises(ImportException):
30
+        with self.assertRaises(ImportError):
31 31
             self.importer.handle()
32 32
 
33 33
     def test_sending_directory_as_file_raises_exception(self):
34 34
         self.importer.afile = "/tmp"
35
-        with self.assertRaises(ImportException):
35
+        with self.assertRaises(ImportError):
36 36
             self.importer.handle()
37 37
 
38 38
     def test_importing_nonexistant_file_raises_exception(self):
39 39
         self.importer.afile = "/tmp/catalogue-import.zgvsfsdfsd"
40
-        with self.assertRaises(ImportException):
40
+        with self.assertRaises(ImportError):
41 41
             self.importer.handle()
42 42
 
43 43
 

+ 7
- 7
oscar/apps/partner/utils.py Voir le fichier

@@ -5,7 +5,7 @@ from decimal import Decimal as D
5 5
 
6 6
 from oscar.core.loading import import_module
7 7
 
8
-import_module('partner.exceptions', ['ImportException'], locals())
8
+import_module('partner.exceptions', ['ImportError'], locals())
9 9
 import_module('partner.models', ['Partner', 'StockRecord'], locals())
10 10
 import_module('product.models', ['ItemClass', 'Item'], locals())
11 11
 
@@ -20,12 +20,12 @@ class StockImporter(object):
20 20
             self._partner = Partner.objects.get(name=partner)
21 21
         except Partner.DoesNotExist:
22 22
             name_list = ", ".join([d['name'] for d in Partner.objects.values('name')])
23
-            raise ImportException("Partner named '%s' does not exist (existing partners: %s)" % (partner, name_list))
23
+            raise ImportError("Partner named '%s' does not exist (existing partners: %s)" % (partner, name_list))
24 24
         
25 25
     def handle(self, file_path=None):
26 26
         u"""Handles the actual import process"""
27 27
         if not file_path:
28
-            raise ImportException("No file path supplied")
28
+            raise ImportError("No file path supplied")
29 29
         Validator().validate(file_path)
30 30
         self._import(file_path)
31 31
 
@@ -97,7 +97,7 @@ class CatalogueImporter(object):
97 97
     def handle(self, file_path=None):
98 98
         u"""Handles the actual import process"""
99 99
         if not file_path:
100
-            raise ImportException("No file path supplied")
100
+            raise ImportError("No file path supplied")
101 101
         Validator().validate(file_path)
102 102
         if self._flush is True:
103 103
             self._flush_product_data()
@@ -177,12 +177,12 @@ class Validator(object):
177 177
     def _exists(self, file_path):
178 178
         u"""Check whether a file exists"""
179 179
         if not os.path.exists(file_path):
180
-            raise ImportException("%s does not exist" % (file_path))
180
+            raise ImportError("%s does not exist" % (file_path))
181 181
         
182 182
     def _is_file(self, file_path):
183 183
         u"""Check whether file is actually a file type"""
184 184
         if not os.path.isfile(file_path):
185
-            raise ImportException("%s is not a file" % (file_path))
185
+            raise ImportError("%s is not a file" % (file_path))
186 186
         
187 187
     def _is_readable(self, file_path):
188 188
         u"""Check file is readable"""
@@ -190,4 +190,4 @@ class Validator(object):
190 190
             f = open(file_path, 'r')
191 191
             f.close()
192 192
         except:
193
-            raise ImportException("%s is not readable" % (file_path))
193
+            raise ImportError("%s is not readable" % (file_path))

+ 5
- 5
oscar/apps/payment/datacash/utils.py Voir le fichier

@@ -10,8 +10,8 @@ from django.core.mail import mail_admins
10 10
 
11 11
 from oscar.core.loading import import_module
12 12
 import_module('payment.datacash.models', ['OrderTransaction'], locals())
13
-import_module('payment.exceptions', ['TransactionDeclinedException', 'GatewayException', 
14
-                                     'InvalidGatewayRequestException'], locals())
13
+import_module('payment.exceptions', ['TransactionDeclined', 'GatewayError', 
14
+                                     'InvalidGatewayRequestError'], locals())
15 15
 
16 16
 # Status codes
17 17
 ACCEPTED, DECLINED, INVALID_CREDENTIALS = '1', '7', '10'
@@ -36,7 +36,7 @@ class Gateway(object):
36 36
         response = conn.getresponse()
37 37
         response_xml = response.read()
38 38
         if response.status != httplib.OK:
39
-            raise GatewayException("Unable to communicate with payment gateway (code: %s, response: %s)" % (response.status, response_xml))
39
+            raise GatewayError("Unable to communicate with payment gateway (code: %s, response: %s)" % (response.status, response_xml))
40 40
         conn.close()
41 41
         
42 42
         # Save response XML
@@ -231,10 +231,10 @@ class Facade(object):
231 231
             import pprint
232 232
             msg = "Order #%s:\n%s" % (order_number, pprint.pprint(response))
233 233
             mail_admins("Datacash credentials are not valid", msg)
234
-            raise InvalidGatewayRequestException("Unable to communicate with payment gateway, please try again later")
234
+            raise InvalidGatewayRequestError("Unable to communicate with payment gateway, please try again later")
235 235
         
236 236
         if response['status'] == DECLINED:
237
-            raise TransactionDeclinedException("Your bank declined this transaction, please check your details and try again")
237
+            raise TransactionDeclined("Your bank declined this transaction, please check your details and try again")
238 238
         
239 239
         return response['datacash_reference']
240 240
         

+ 6
- 6
oscar/apps/payment/exceptions.py Voir le fichier

@@ -1,20 +1,20 @@
1
-class PaymentException(Exception):
1
+class PaymentError(Exception):
2 2
     pass
3 3
 
4 4
 
5
-class TransactionDeclinedException(PaymentException):
5
+class TransactionDeclined(PaymentError):
6 6
     pass
7 7
 
8 8
 
9
-class GatewayException(PaymentException):
9
+class GatewayError(PaymentError):
10 10
     pass
11 11
 
12 12
 
13
-class InvalidGatewayRequestException(PaymentException):
13
+class InvalidGatewayRequestError(PaymentError):
14 14
     pass
15 15
 
16 16
 
17
-class RedirectRequiredException(Exception):
17
+class RedirectRequired(PaymentError):
18 18
     """
19 19
     Exception to be used when payment processsing requires a redirect
20 20
     """
@@ -23,7 +23,7 @@ class RedirectRequiredException(Exception):
23 23
         self.url = url
24 24
 
25 25
 
26
-class UnableToTakePaymentException(Exception):
26
+class UnableToTakePayment(PaymentError):
27 27
     """
28 28
     Exception to be used for ANTICIPATED payment errors (eg card number wrong, expiry date
29 29
     has passed).  The message passed here will be shown to the end user.

+ 0
- 1
oscar/core/loading.py Voir le fichier

@@ -1,4 +1,3 @@
1
-from exceptions import Exception
2 1
 from imp import new_module
3 2
 
4 3
 from django.conf import settings

Chargement…
Annuler
Enregistrer