From 0a49b0a52b20b1ad9a073ffa421bb45c8600ddef Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 16 Jan 2015 10:31:35 +0100 Subject: [PATCH] PEP8 fixes --- modoboa/core/commands/__init__.py | 1 + modoboa/core/commands/postfix_maps.py | 12 ++++++++---- modoboa/core/extensions.py | 2 ++ modoboa/core/models.py | 5 +++-- modoboa/core/password_hashers/advanced.py | 3 +++ modoboa/core/password_hashers/base.py | 6 ++++++ modoboa/core/templatetags/core_tags.py | 1 + modoboa/extensions/webmail/lib/fetch_parser.py | 4 ++-- modoboa/tools/pfxadmin_migrate/models.py | 11 ++++++++--- 9 files changed, 34 insertions(+), 11 deletions(-) diff --git a/modoboa/core/commands/__init__.py b/modoboa/core/commands/__init__.py index e95f987b2..b1b2cf62e 100644 --- a/modoboa/core/commands/__init__.py +++ b/modoboa/core/commands/__init__.py @@ -9,6 +9,7 @@ from django.template import Context, Template class Command(object): + """Base command class A valid administrative command must inherit from this class. diff --git a/modoboa/core/commands/postfix_maps.py b/modoboa/core/commands/postfix_maps.py index 0cf9e9fb2..c663841fe 100644 --- a/modoboa/core/commands/postfix_maps.py +++ b/modoboa/core/commands/postfix_maps.py @@ -1,18 +1,22 @@ # coding: utf-8 + +"""postfix_maps command.""" + +import datetime import getpass import inspect import os import sys -import datetime + from django.template import Context, Template + from . import Command class MapFilesGenerator(object): def __init__(self, dbinfo=None): - """Constructor. - """ + """Constructor.""" self.template = Template("""user = {{ dbuser }} password = {{ dbpass }} dbname = {{ dbname }} @@ -69,7 +73,7 @@ query = {{ query|safe }} continue if v is MapFile: continue - if not v.category in args.categories: + if v.category not in args.categories: continue self.__render_map(args, v) diff --git a/modoboa/core/extensions.py b/modoboa/core/extensions.py index 99a89f7a3..96d3096cf 100644 --- a/modoboa/core/extensions.py +++ b/modoboa/core/extensions.py @@ -5,6 +5,7 @@ from django.conf.urls import include class ModoExtension(object): + """Base extension class. Each Modoboa extension must inherit from this class to be @@ -37,6 +38,7 @@ class ModoExtension(object): class ExtensionsPool(object): + """The extensions manager""" def __init__(self): diff --git a/modoboa/core/models.py b/modoboa/core/models.py index 93f32451f..8d4aed543 100644 --- a/modoboa/core/models.py +++ b/modoboa/core/models.py @@ -37,6 +37,7 @@ except ImportError: class User(PermissionsMixin): + """Custom User model. It overloads the way passwords are stored into the database. The @@ -114,7 +115,7 @@ class User(PermissionsMixin): load_core_settings() scheme = parameters.get_admin("PASSWORD_SCHEME") - if type(raw_value) is unicode: + if isinstance(raw_value, unicode): raw_value = raw_value.encode("utf-8") return get_password_hasher(scheme.upper())().encrypt(raw_value) @@ -146,7 +147,7 @@ class User(PermissionsMixin): match = self.password_expr.match(self.password) if match is None: return False - if type(raw_value) is unicode: + if isinstance(raw_value, unicode): raw_value = raw_value.encode("utf-8") scheme = match.group(1) val2 = match.group(2) diff --git a/modoboa/core/password_hashers/advanced.py b/modoboa/core/password_hashers/advanced.py index 3bb632ad2..73b5ef493 100644 --- a/modoboa/core/password_hashers/advanced.py +++ b/modoboa/core/password_hashers/advanced.py @@ -9,6 +9,7 @@ from modoboa.lib import parameters class MD5CRYPTHasher(PasswordHasher): + """ MD5-CRYPT password hasher. @@ -29,6 +30,7 @@ class MD5CRYPTHasher(PasswordHasher): class SHA256CRYPTHasher(PasswordHasher): + """ SHA256-CRYPT password hasher. @@ -51,6 +53,7 @@ class SHA256CRYPTHasher(PasswordHasher): class SHA512CRYPTHasher(PasswordHasher): + """ SHA512-CRYPT password hasher. diff --git a/modoboa/core/password_hashers/base.py b/modoboa/core/password_hashers/base.py index 156a35616..b0902c926 100644 --- a/modoboa/core/password_hashers/base.py +++ b/modoboa/core/password_hashers/base.py @@ -12,9 +12,11 @@ from django.utils.crypto import constant_time_compare class PasswordHasher(object): + """ Base class of all hashers. """ + def __init__(self, target='local'): self._target = target @@ -61,6 +63,7 @@ class PasswordHasher(object): class PLAINHasher(PasswordHasher): + """ Plain (ie. clear) password hasher. """ @@ -73,6 +76,7 @@ class PLAINHasher(PasswordHasher): class CRYPTHasher(PasswordHasher): + """ crypt password hasher. @@ -89,6 +93,7 @@ class CRYPTHasher(PasswordHasher): class MD5Hasher(PasswordHasher): + """ MD5 password hasher. @@ -104,6 +109,7 @@ class MD5Hasher(PasswordHasher): class SHA256Hasher(PasswordHasher): + """ SHA256 password hasher. diff --git a/modoboa/core/templatetags/core_tags.py b/modoboa/core/templatetags/core_tags.py index 9c9830c33..bd50c7eb7 100644 --- a/modoboa/core/templatetags/core_tags.py +++ b/modoboa/core/templatetags/core_tags.py @@ -158,6 +158,7 @@ def get_version(): class ConnectedUsers(template.Node): + def __init__(self, varname): self.varname = varname diff --git a/modoboa/extensions/webmail/lib/fetch_parser.py b/modoboa/extensions/webmail/lib/fetch_parser.py index 12bfadfc8..8d83cdf2d 100644 --- a/modoboa/extensions/webmail/lib/fetch_parser.py +++ b/modoboa/extensions/webmail/lib/fetch_parser.py @@ -212,9 +212,9 @@ def dump_bodystructure(bs, depth=0): if __name__ == "__main__": - # resp = [('855 (UID 46931 BODYSTRUCTURE ((("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 886 32 NIL NIL NIL NIL)("text" "html" ("charset" "us-ascii") NIL NIL "quoted-printable" 1208 16 NIL NIL NIL NIL) "alternative" ("boundary" "----=_NextPart_001_0003_01CCC564.B2F64FF0") NIL NIL NIL)("application" "octet-stream" ("name" "Carte Verte_2.pdf") NIL NIL "base64" 285610 NIL ("attachment" ("filename" "Carte Verte_2.pdf")) NIL NIL) "mixed" ("boundary" "----=_NextPart_000_0002_01CCC564.B2F64FF0") NIL NIL NIL) BODY[HEADER.FIELDS (DATE FROM TO CC SUBJECT)] {153}', 'From: \r\nTo: \r\nCc: \r\nSubject: Notre contact du 28/12/2011 - 192175092\r\nDate: Wed, 28 Dec 2011 13:29:17 +0100\r\n\r\n'), ')'] +# resp = [('855 (UID 46931 BODYSTRUCTURE ((("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 886 32 NIL NIL NIL NIL)("text" "html" ("charset" "us-ascii") NIL NIL "quoted-printable" 1208 16 NIL NIL NIL NIL) "alternative" ("boundary" "----=_NextPart_001_0003_01CCC564.B2F64FF0") NIL NIL NIL)("application" "octet-stream" ("name" "Carte Verte_2.pdf") NIL NIL "base64" 285610 NIL ("attachment" ("filename" "Carte Verte_2.pdf")) NIL NIL) "mixed" ("boundary" "----=_NextPart_000_0002_01CCC564.B2F64FF0") NIL NIL NIL) BODY[HEADER.FIELDS (DATE FROM TO CC SUBJECT)] {153}', 'From: \r\nTo: \r\nCc: \r\nSubject: Notre contact du 28/12/2011 - 192175092\r\nDate: Wed, 28 Dec 2011 13:29:17 +0100\r\n\r\n'), ')'] - # #resp = [('856 (UID 46936 BODYSTRUCTURE (("text" "plain" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 724 22 NIL NIL NIL NIL)("text" "html" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 2662 48 NIL NIL NIL NIL) "alternative" ("boundary" "----=_Part_1326887_254624357.1325083973970") NIL NIL NIL) BODY[HEADER.FIELDS (DATE FROM TO CC SUBJECT)] {258}', 'Date: Wed, 28 Dec 2011 15:52:53 +0100 (CET)\r\nFrom: =?ISO-8859-1?Q?Malakoff_M=E9d=E9ric?= \r\nTo: Antoine Nguyen \r\nSubject: =?ISO-8859-1?Q?Votre_inscription_au_grand_Jeu_Malakoff_M=E9d=E9ric?=\r\n\r\n'), ')'] +# resp = [('856 (UID 46936 BODYSTRUCTURE (("text" "plain" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 724 22 NIL NIL NIL NIL)("text" "html" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 2662 48 NIL NIL NIL NIL) "alternative" ("boundary" "----=_Part_1326887_254624357.1325083973970") NIL NIL NIL) BODY[HEADER.FIELDS (DATE FROM TO CC SUBJECT)] {258}', 'Date: Wed, 28 Dec 2011 15:52:53 +0100 (CET)\r\nFrom: =?ISO-8859-1?Q?Malakoff_M=E9d=E9ric?= \r\nTo: Antoine Nguyen \r\nSubject: =?ISO-8859-1?Q?Votre_inscription_au_grand_Jeu_Malakoff_M=E9d=E9ric?=\r\n\r\n'), ')'] resp = [ ('856 (UID 11111 BODYSTRUCTURE ((("text" "plain" ("charset" "UTF-8") NIL NIL "7bit" 0 0 NIL NIL NIL NIL) "mixed" ("boundary" "----=_Part_407172_3159001.1321948277321") NIL NIL NIL)("application" "octet-stream" ("name" "26274308.pdf") NIL NIL "base64" 14906 NIL ("attachment" ("filename" "26274308.pdf")) NIL NIL) "mixed" ("boundary" "----=_Part_407171_9686991.1321948277321") NIL NIL NIL)', diff --git a/modoboa/tools/pfxadmin_migrate/models.py b/modoboa/tools/pfxadmin_migrate/models.py index c95f46216..f94e2f775 100755 --- a/modoboa/tools/pfxadmin_migrate/models.py +++ b/modoboa/tools/pfxadmin_migrate/models.py @@ -1,15 +1,20 @@ # coding: utf-8 + +"""postfixadmin models.""" + # This is an auto-generated Django model module. # You'll have to do the following manually to clean this up: # * Rearrange models' order # * Make sure each model has one field with primary_key=True -# Feel free to rename the models, but don't rename db_table values or field names. +# Feel free to rename the models, but don't rename db_table values or +# field names. # -# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]' -# into your database. +# Also note: You'll have to insert the output of 'django-admin.py +# sqlcustom [appname]' into your database. from django.db import models + class Admin(models.Model): username = models.CharField(max_length=255, primary_key=True) password = models.CharField(max_length=255)