Andriy Kornatskyy avatar Andriy Kornatskyy committed 656d024

Fixed PEP8 warnings.

Comments (0)

Files changed (10)

 dist/
 env/
 src/*.egg-info/
+.cache
 .coverage
 *.pyc
 *.pyo
 	find src/ -type d -name __pycache__ | xargs rm -rf
 	find src/ -name '*.py[co]' -delete
 	find src/ -name '*.mo' -delete
-	rm -rf dist/ build/ MANIFEST src/*.egg-info
+	rm -rf dist/ build/ MANIFEST src/*.egg-info .cache .coverage
 
 release:
 	$(PYTHON) setup.py -q bdist_egg

i18n/en/LC_MESSAGES/validation.po

 msgstr "%Y/%m/%d"
 
 #. fallback date input formats: 5/18/2008. Use | to separate multiple values.
-#: src/wheezy/validation/format.py:13 src/wheezy/validation/format.py:15
+#: src/wheezy/validation/format.py:13 src/wheezy/validation/format.py:14
+#: src/wheezy/validation/format.py:15
 msgid "%m/%d/%Y|%Y-%m-%d|%m/%d/%y"
 msgstr "%m/%d/%Y|%Y-%m-%d|%m/%d/%y"
 
 msgstr "%Y/%m/%d %H:%M"
 
 #. fallback datetime input formats: 2008/5/18 16:34:52. Use | to separate.
-#: src/wheezy/validation/format.py:22 src/wheezy/validation/format.py:27
+#: src/wheezy/validation/format.py:22 src/wheezy/validation/format.py:23
+#: src/wheezy/validation/format.py:27
 msgid ""
 "%Y/%m/%d %H:%M:%S|%m/%d/%Y %H:%M|%m/%d/%Y %H:%M:%S|%Y-%m-%d %H:%M|%Y-%m-%d "
 "%H:%M:%S|%m/%d/%y %H:%M|%m/%d/%y %H:%M:%S"
 msgid "Required to match validation pattern."
 msgstr "Required to match validation pattern."
 
-#: src/wheezy/validation/rules.py:478
+#: src/wheezy/validation/rules.py:478 src/wheezy/validation/rules.py:479
 msgid ""
 "Invalid slug. The value must consist of letters, digits, underscopes and/or "
 "hyphens."
 "Invalid slug. The value must consist of letters, digits, underscopes and/or "
 "hyphens."
 
-#: src/wheezy/validation/rules.py:509
+#: src/wheezy/validation/rules.py:509 src/wheezy/validation/rules.py:510
 msgid "Required to be a valid email address."
 msgstr "Required to be a valid email address."
 
-#: src/wheezy/validation/rules.py:556
+#: src/wheezy/validation/rules.py:556 src/wheezy/validation/rules.py:557
 #, python-format
 msgid "Required to be greater or equal to %(min)s."
 msgstr "Required to be greater or equal to %(min)s."
 
-#: src/wheezy/validation/rules.py:561
+#: src/wheezy/validation/rules.py:561 src/wheezy/validation/rules.py:562
 #, python-format
 msgid "The value must fall within the range %(min)s - %(max)s"
 msgstr "The value must fall within the range %(min)s - %(max)s"
 
-#: src/wheezy/validation/rules.py:568
+#: src/wheezy/validation/rules.py:568 src/wheezy/validation/rules.py:569
 #, python-format
 msgid "Exceeds maximum allowed value of %(max)s."
 msgstr "Exceeds maximum allowed value of %(max)s."
 
-#: src/wheezy/validation/rules.py:809
+#: src/wheezy/validation/rules.py:809 src/wheezy/validation/rules.py:810
 msgid "The value does not belong to the list of known items."
 msgstr "The value does not belong to the list of known items."
 
 #: src/wheezy/validation/rules.py:812 src/wheezy/validation/rules.py:840
+#: src/wheezy/validation/rules.py:841
 msgid "Required to be above a minimum allowed."
 msgstr "Required to be above a minimum allowed."
 
 #: src/wheezy/validation/rules.py:817 src/wheezy/validation/rules.py:845
+#: src/wheezy/validation/rules.py:846
 msgid "Must fall within a valid range."
 msgstr "Must fall within a valid range."
 
 #: src/wheezy/validation/rules.py:823 src/wheezy/validation/rules.py:851
+#: src/wheezy/validation/rules.py:852
 msgid "Exceeds maximum allowed."
 msgstr "Exceeds maximum allowed."

i18n/validation.po

 msgstr "%Y/%m/%d"
 
 #. fallback date input formats: 5/18/2008. Use | to separate multiple values.
-#: src/wheezy/validation/format.py:13 src/wheezy/validation/format.py:15
+#: src/wheezy/validation/format.py:13 src/wheezy/validation/format.py:14
+#: src/wheezy/validation/format.py:15
 msgid "%m/%d/%Y|%Y-%m-%d|%m/%d/%y"
 msgstr "%m/%d/%Y|%Y-%m-%d|%m/%d/%y"
 
 msgstr "%Y/%m/%d %H:%M"
 
 #. fallback datetime input formats: 2008/5/18 16:34:52. Use | to separate.
-#: src/wheezy/validation/format.py:22 src/wheezy/validation/format.py:27
+#: src/wheezy/validation/format.py:22 src/wheezy/validation/format.py:23
+#: src/wheezy/validation/format.py:27
 msgid ""
 "%Y/%m/%d %H:%M:%S|%m/%d/%Y %H:%M|%m/%d/%Y %H:%M:%S|%Y-%m-%d %H:%M|%Y-%m-%d "
 "%H:%M:%S|%m/%d/%y %H:%M|%m/%d/%y %H:%M:%S"
 msgid "Required to match validation pattern."
 msgstr "Required to match validation pattern."
 
-#: src/wheezy/validation/rules.py:478
+#: src/wheezy/validation/rules.py:478 src/wheezy/validation/rules.py:479
 msgid ""
 "Invalid slug. The value must consist of letters, digits, underscopes and/or "
 "hyphens."
 "Invalid slug. The value must consist of letters, digits, underscopes and/or "
 "hyphens."
 
-#: src/wheezy/validation/rules.py:509
+#: src/wheezy/validation/rules.py:509 src/wheezy/validation/rules.py:510
 msgid "Required to be a valid email address."
 msgstr "Required to be a valid email address."
 
-#: src/wheezy/validation/rules.py:556
+#: src/wheezy/validation/rules.py:556 src/wheezy/validation/rules.py:557
 #, python-format
 msgid "Required to be greater or equal to %(min)s."
 msgstr "Required to be greater or equal to %(min)s."
 
-#: src/wheezy/validation/rules.py:561
+#: src/wheezy/validation/rules.py:561 src/wheezy/validation/rules.py:562
 #, python-format
 msgid "The value must fall within the range %(min)s - %(max)s"
 msgstr "The value must fall within the range %(min)s - %(max)s"
 
-#: src/wheezy/validation/rules.py:568
+#: src/wheezy/validation/rules.py:568 src/wheezy/validation/rules.py:569
 #, python-format
 msgid "Exceeds maximum allowed value of %(max)s."
 msgstr "Exceeds maximum allowed value of %(max)s."
 
-#: src/wheezy/validation/rules.py:809
+#: src/wheezy/validation/rules.py:809 src/wheezy/validation/rules.py:810
 msgid "The value does not belong to the list of known items."
 msgstr "The value does not belong to the list of known items."
 
 #: src/wheezy/validation/rules.py:812 src/wheezy/validation/rules.py:840
+#: src/wheezy/validation/rules.py:841
 msgid "Required to be above a minimum allowed."
 msgstr "Required to be above a minimum allowed."
 
 #: src/wheezy/validation/rules.py:817 src/wheezy/validation/rules.py:845
+#: src/wheezy/validation/rules.py:846
 msgid "Must fall within a valid range."
 msgstr "Must fall within a valid range."
 
 #: src/wheezy/validation/rules.py:823 src/wheezy/validation/rules.py:851
+#: src/wheezy/validation/rules.py:852
 msgid "Exceeds maximum allowed."
 msgstr "Exceeds maximum allowed."
 upload-dir = doc/_build
 
 [pytest]
+pep8ignore =

src/wheezy/validation/format.py

 # default date input format: 2008/5/18.
 default_date_input_format = lambda gettext: gettext('%Y/%m/%d')
 # fallback date input formats: 5/18/2008. Use | to separate multiple values.
-fallback_date_input_formats = lambda gettext: gettext('%m/%d/%Y|'
-        '%Y-%m-%d|%m/%d/%y')
+fallback_date_input_formats = lambda gettext: gettext(
+    '%m/%d/%Y|%Y-%m-%d|%m/%d/%y')
 # default time input format: 16:34.
 default_time_input_format = lambda gettext: gettext('%H:%M')
 # fallback time input formats: 16:34:52. Use | to separate multiple values.
 # default datetime input format: 2008/5/18 16:34
 default_datetime_input_format = lambda gettext: gettext('%Y/%m/%d %H:%M')
 # fallback datetime input formats: 2008/5/18 16:34:52. Use | to separate.
-fallback_datetime_input_formats = lambda gettext: gettext('%Y/%m/%d %H:%M:%S|'
-        '%m/%d/%Y %H:%M|%m/%d/%Y %H:%M:%S|'
-        '%Y-%m-%d %H:%M|%Y-%m-%d %H:%M:%S|%m/%d/%y %H:%M|%m/%d/%y %H:%M:%S')
+fallback_datetime_input_formats = lambda gettext: gettext(
+    '%Y/%m/%d %H:%M:%S|%m/%d/%Y %H:%M|%m/%d/%Y %H:%M:%S|'
+    '%Y-%m-%d %H:%M|%Y-%m-%d %H:%M:%S|%m/%d/%y %H:%M|%m/%d/%y %H:%M:%S')

src/wheezy/validation/mixin.py

 
     def validate(self, model, validator):
         return validator.validate(
-                model,
-                self.errors,
-                translations=self.translations['validation'])
+            model,
+            self.errors,
+            translations=self.translations['validation'])

src/wheezy/validation/model.py

     else:
         attribute_names = list(model.__dict__)
         attribute_names.extend([name for name in model.__class__.__dict__
-                                    if name[:1] != '_'])
+                                if name[:1] != '_'])
         getter = getattr
         setter = setattr
     succeed = True
                 attr[:] = items
             except (ArithmeticError, ValueError):
                 results[name] = [gettext(
-                        "Multiple input was not in a correct format.")]
+                    "Multiple input was not in a correct format.")]
                 succeed = False
         else:  # A simple value attribute
             provider_name = type(attr).__name__
                     setter(model, name, value)
                 except (ArithmeticError, ValueError):
                     results[name] = [gettext(
-                            "Input was not in a correct format.")]
+                        "Input was not in a correct format.")]
                     succeed = False
     return succeed
 
 
 
 value_providers = {
-        'str': lambda str_value, gettext: str_value.strip(),
-        'unicode': lambda str_value, gettext: \
-                str_value.strip().decode('UTF-8'),
-        'int': int_value_provider,
-        'Decimal': decimal_value_provider,
-        'bool': bool_value_provider,
-        'float': float_value_provider,
-        'date': date_value_provider,
-        'time': time_value_provider,
-        'datetime': datetime_value_provider
+    'str': lambda str_value, gettext: str_value.strip(),
+    'unicode': lambda str_value, gettext: str_value.strip().decode('UTF-8'),
+    'int': int_value_provider,
+    'Decimal': decimal_value_provider,
+    'bool': bool_value_provider,
+    'float': float_value_provider,
+    'date': date_value_provider,
+    'time': time_value_provider,
+    'datetime': datetime_value_provider
 }

src/wheezy/validation/rules.py

 
     def __init__(self, message_template=None):
         self.message_template = message_template or _(
-                'Required field cannot be left blank.')
+            'Required field cannot be left blank.')
 
     def __call__(self, message_template):
         """ Let you customize message template.
 
     def __init__(self, message_template=None):
         self.message_template = message_template or _(
-                'Field cannot have a value.')
+            'Field cannot have a value.')
 
     def __call__(self, message_template):
         """ Let you customize message template.
                 self.min = min
                 self.validate = self.check_min
                 self.message_template = message_template or _(
-                        'Required to be a minimum of %(min)d characters'
-                        ' in length.')
+                    'Required to be a minimum of %(min)d characters'
+                    ' in length.')
             else:
                 self.max = max
                 self.validate = self.check
                 self.message_template = message_template or _(
-                        'The length must fall within the range %(min)d'
-                        ' - %(max)d characters.')
+                    'The length must fall within the range %(min)d'
+                    ' - %(max)d characters.')
         else:
             if max:
                 self.max = max
                 self.validate = self.check_max
                 self.message_template = message_template or _(
-                        'Exceeds maximum length of %(max)d.')
+                    'Exceeds maximum length of %(max)d.')
             else:
                 self.validate = self.succeed
 
             return True
         if len(value) < self.min:
             result.append(gettext(self.message_template)
-                    % {'min': self.min})
+                          % {'min': self.min})
             return False
         return True
 
             return True
         if len(value) > self.max:
             result.append(gettext(self.message_template)
-                    % {'max': self.max})
+                          % {'max': self.max})
             return False
         return True
 
         l = len(value)
         if l < self.min or l > self.max:
             result.append(gettext(self.message_template)
-                    % {'min': self.min, 'max': self.max})
+                          % {'min': self.min, 'max': self.max})
             return False
         return True
 
             self.comparand = equal
             self.validate = self.check_equal
             self.message_template = message_template or _(
-                    'The value failed equality comparison'
-                    ' with "%(comparand)s".')
+                'The value failed equality comparison'
+                ' with "%(comparand)s".')
         elif not_equal:
             self.comparand = not_equal
             self.validate = self.check_not_equal
             self.message_template = message_template or _(
-                    'The value failed not equal comparison'
-                    ' with "%(comparand)s".')
+                'The value failed not equal comparison'
+                ' with "%(comparand)s".')
         else:
             self.validate = self.check
 
         comparand_value = getter(model, self.comparand)
         if value != comparand_value:
             result.append(gettext(self.message_template)
-                    % {'comparand': self.comparand})
+                          % {'comparand': self.comparand})
             return False
         return True
 
         comparand_value = getter(model, self.comparand)
         if value == comparand_value:
             result.append(gettext(self.message_template)
-                    % {'comparand': self.comparand})
+                          % {'comparand': self.comparand})
             return False
         return True
 
     def __init__(self, predicate, message_template=None):
         self.predicate = predicate
         self.message_template = message_template or _(
-                'Required to satisfy validation predicate condition.')
+            'Required to satisfy validation predicate condition.')
 
     def validate(self, value, name, model, result, gettext):
         if not self.predicate(model):
         if negated:
             self.validate = self.check_not_found
             self.message_template = message_template or _(
-                    'Required to not match validation pattern.')
+                'Required to not match validation pattern.')
         else:
             self.validate = self.check_found
             self.message_template = message_template or _(
-                    'Required to match validation pattern.')
+                'Required to match validation pattern.')
 
     def check_found(self, value, name, model, result, gettext):
         """
     __slots__ = ()
 
     def __init__(self, message_template=None):
-        super(SlugRule, self).__init__(r'^[-\w]+$', False,
-                message_template or _(
-        'Invalid slug. The value must consist of letters, '
-        'digits, underscopes and/or hyphens.'))
+        super(SlugRule, self).__init__(
+            r'^[-\w]+$', False,
+            message_template or _(
+                'Invalid slug. The value must consist of letters, '
+                'digits, underscopes and/or hyphens.'))
 
     def __call__(self, message_template):
         """ Let you customize message template.
 
     def __init__(self, message_template=None):
         super(EmailRule, self).__init__(
-                re.compile(r'[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,5}',
-                    re.IGNORECASE), False,
-                message_template or
-                _('Required to be a valid email address.'))
+            re.compile(r'[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,5}',
+                       re.IGNORECASE), False,
+            message_template or
+            _('Required to be a valid email address.'))
 
     def __call__(self, message_template):
         """ Let you customize message template.
                 self.min = min
                 self.validate = self.check_min
                 self.message_template = message_template or _(
-                        'Required to be greater or equal to %(min)s.')
+                    'Required to be greater or equal to %(min)s.')
             else:
                 self.max = max
                 self.validate = self.check
                 self.message_template = message_template or _(
-                        'The value must fall within the range %(min)s'
-                        ' - %(max)s')
+                    'The value must fall within the range %(min)s'
+                    ' - %(max)s')
         else:
             if max:
                 self.max = max
                 self.validate = self.check_max
                 self.message_template = message_template or _(
-                        'Exceeds maximum allowed value of %(max)s.')
+                    'Exceeds maximum allowed value of %(max)s.')
             else:
                 self.validate = self.succeed
 
             return True
         if value < self.min:
             result.append(gettext(self.message_template)
-                    % {'min': self.min})
+                          % {'min': self.min})
             return False
         return True
 
             return True
         if value > self.max:
             result.append(gettext(self.message_template)
-                    % {'max': self.max})
+                          % {'max': self.max})
             return False
         return True
 
             return True
         if value < self.min or value > self.max:
             result.append(gettext(self.message_template)
-                    % {'min': self.min, 'max': self.max})
+                          % {'min': self.min, 'max': self.max})
             return False
         return True
 
         for rule in self.rules:
             for item in value:
                 rule_succeed = rule.validate(item, name, model,
-                        result, gettext)
+                                             result, gettext)
                 succeed &= rule_succeed
                 if not rule_succeed and self.stop:
                     break
         """
         self.items = tuple(items)
         self.message_template = message_template or _(
-                'The value does not belong to the list of known items.')
+            'The value does not belong to the list of known items.')
 
     def validate(self, value, name, model, result, gettext):
         """ Check whenever value belongs to ``self.items``.
                 self.min = min
                 self.validate = self.check_min
                 self.message_template = message_template or _(
-                        'Required to be above a minimum allowed.')
+                    'Required to be above a minimum allowed.')
             else:
                 self.max = max
                 self.validate = self.check
                 self.message_template = message_template or _(
-                        'Must fall within a valid range.')
+                    'Must fall within a valid range.')
         else:
             if max:
                 self.max = max
                 self.validate = self.check_max
                 self.message_template = message_template or _(
-                        'Exceeds maximum allowed.')
+                    'Exceeds maximum allowed.')
             else:
                 self.validate = self.succeed
 
             return True
         if value < self.now() + self.min:
             result.append(gettext(self.message_template)
-                    % {'min': self.min})
+                          % {'min': self.min})
             return False
         return True
 
             return True
         if value > self.now() + self.max:
             result.append(gettext(self.message_template)
-                    % {'max': self.max})
+                          % {'max': self.max})
             return False
         return True
 
         now = self.now()
         if value < now + self.min or value > now + self.max:
             result.append(gettext(self.message_template)
-                    % {'min': self.min, 'max': self.max})
+                          % {'min': self.min, 'max': self.max})
             return False
         return True
 

src/wheezy/validation/validator.py

         self.inner = tuple(inner)
 
     def validate(self, model, results, stop=True, translations=None,
-            gettext=None):
+                 gettext=None):
         """
             Here is a class and object we are going to validate.
 
             result = []
             for rule in rules:
                 rule_succeed = rule.validate(value, name,
-                        model, result, gettext)
+                                             model, result, gettext)
                 succeed &= rule_succeed
                 if not rule_succeed and stop:
                     break
                 results[name] = result
         for name, validator in self.inner:
             succeed &= validator.validate(getter(model, name),
-                    results, stop, None, gettext)
+                                          results, stop, None, gettext)
         return succeed
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.