mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-22 10:34:10 +01:00
pep8 fixes
- B007 Loop control variable not used within the loop body. If this is intended, start the name with an underscore.
* modoboa/admin/lib.py
* modoboa/admin/templatetags/admin_tags.py
* modoboa/admin/tests/test_account.py
* modoboa/admin/views/domain.py
* modoboa/admin/views/identity.py
* modoboa/core/views/dashboard.py
* modoboa/limits/forms.py
* modoboa/limits/handlers.py
* modoboa/limits/tests/test_api.py
* modoboa/limits/tests/test_domain_limits.py
* modoboa/limits/tests/test_import.py
* modoboa/limits/tests/test_user_limits.py
* modoboa/limits/utils.py
* modoboa/parameters/tools.py
* modoboa/relaydomains/tests.py
- C402 Unnecessary generator - rewrite as a dict comprehension.
* modoboa/admin/models/domain.py
* modoboa/admin/views/domain.py
* modoboa/admin/views/identity.py
* modoboa/limits/searializers.py
- C407 Unnecessary list comprehension - can take a generator.
* modoboa/core/password_validation.py
* modoboa/parameters/tools.py
* modoboa/transport/backends.py
- C408 Unnecessary dict call - rewrite as a literal.
* modoboa/admin/tests/test_account.py
* modoboa/admin/tests/test_alias.py
* modoboa/admin/tests/test_password_schemes.py
* modoboa/admin/views/domain.py
* modoboa/admin/views/identity.py
* modoboa/core/extensions.py
* modoboa/lib/middleware.py
* modoboa/lib/templatetags/form_tags.py
* modoboa/lib/templatetags/lib_tags.py
* modoboa/lib/web_utils.py
* modoboa/limits/handlers.py
* modoboa/limits/tests/test_user_limits.py
- E741 ambiguous variable name
* modoboa/core/management/commands/cleanlogs.py
* modoboa/limits/forms.py
* modoboa/limits/tests/test_user_limits.py
* modoboa/limits/utils.py
* modoboa/relaydomains/tests.py
- F401 imported but unused
* doc/conf.py
* modoboa/admin/views/domain.py
* modoboa/core/app_settings.py
* modoboa/core/management/commands/load_initial_data.py
- F821 undefined name 'raw_input'
* modoboa/core/commands/deploy.py
- F841 local variable 'test' is assigned to but never used
* modoboa/core/app_settings.py
- N802 function name 'setUpTestData' should be lowercase xxx
* modoboa/lib/email_utils.py - __ for name mangeling, _ for internal
- N805 first argument of a method should be named 'self'
* modoboa/lib/connections.py
* modoboa/lib/singleton.py
Ignore the following
- A001 "copyright" is a python builtin and is being shadowed, consider renaming the variable
* doc/conf.py
- A003 is a python builtin, consider renaming the class attribute
* modoboa/admin/factories.py
* modoboa/admin/forms/domain.py
* modoboa/admin/management/commands/handle_mailbox_operations.py
* modoboa/admin/management/commands/modo.py
* modoboa/admin/management/commands/subcommands/_repair.py
* modoboa/admin/models/domain.py
* modoboa/admin/models/mailbox.py
* modoboa/core/commands/__init__.py
* modoboa/core/commands/deploy.py
* modoboa/core/commands/help.py
* modoboa/core/management/commands/clean_inactive_accounts.py
* modoboa/core/management/commands/cleanlogs.py
* modoboa/core/management/commands/communicate_with_public_api.py
* modoboa/core/management/commands/generate_postfix_maps.py
* modoboa/core/management/commands/load_initial_data.py
* modoboa/core/management/commands/set_default_site.py
- F401 imported but unused
* modoboa/admin/apps.py - used to load handlers
* modoboa/core/password_hashers/__init__.py - dynamically loaded
* modoboa/limits/apps.py - used to load handlers
* modoboa/relaydomains/apps.py - used to load handlers
* modoboa/transport/apps.py - used to load handlers
- N802 function name should be lowercase xxx
* modoboa/admin/tests/test_account.py
* modoboa/admin/tests/test_alias.py
* modoboa/admin/tests/test_domain_alias.py
* modoboa/admin/tests/test_export.py
* modoboa/admin/tests/test_mailbox_operations.py
* modoboa/admin/tests/test_password_schemas.py
* modoboa/admin/tests/test_repair.py
* modoboa/core/tests/test_authentication.py
* modoboa/core/tests/test_core.py
* modoboa/core/tests/test_ldap.py
* modoboa/core/tests/test_views.py
* modoboa/lib/imap_utf7.py
* modoboa/limits/tests/test_api.py
* modoboa/limits/tests/test_domain_limits.py
* modoboa/limits/tests/test_import.py
* modoboa/limits/tests/test_user_limits.py
* modoboa/relaydomains/tests.py
other fixes:
- use isinstance() instead of type() == Class
This commit is contained in:
+11
-11
@@ -11,27 +11,27 @@ class ConnectionsManager(type):
|
||||
This class is specialized in connection management.
|
||||
"""
|
||||
|
||||
def __init__(cls, name, bases, ctx):
|
||||
super(ConnectionsManager, cls).__init__(name, bases, ctx)
|
||||
cls.instances = {}
|
||||
def __init__(self, name, bases, ctx):
|
||||
super(ConnectionsManager, self).__init__(name, bases, ctx)
|
||||
self.instances = {}
|
||||
|
||||
def __call__(cls, **kwargs):
|
||||
def __call__(self, **kwargs):
|
||||
key = None
|
||||
if "user" in kwargs:
|
||||
key = kwargs["user"]
|
||||
else:
|
||||
return None
|
||||
if key not in cls.instances:
|
||||
cls.instances[key] = None
|
||||
if key not in self.instances:
|
||||
self.instances[key] = None
|
||||
if "password" in kwargs:
|
||||
kwargs["password"] = decrypt(kwargs["password"])
|
||||
|
||||
if cls.instances[key] is None:
|
||||
cls.instances[key] = \
|
||||
super(ConnectionsManager, cls).__call__(**kwargs)
|
||||
if self.instances[key] is None:
|
||||
self.instances[key] = \
|
||||
super(ConnectionsManager, self).__call__(**kwargs)
|
||||
else:
|
||||
cls.instances[key].refresh(key, kwargs["password"])
|
||||
return cls.instances[key]
|
||||
self.instances[key].refresh(key, kwargs["password"])
|
||||
return self.instances[key]
|
||||
|
||||
|
||||
class ConnectionError(Exception):
|
||||
|
||||
@@ -387,7 +387,7 @@ def set_email_headers(msg, subject, sender, rcpt):
|
||||
msg["Date"] = formatdate(time.time(), True)
|
||||
|
||||
|
||||
def __sendmail(sender, rcpt, msgstring, server="localhost", port=25):
|
||||
def _sendmail(sender, rcpt, msgstring, server="localhost", port=25):
|
||||
"""Message sending
|
||||
|
||||
Return a tuple (True, None) on success, (False, error message)
|
||||
@@ -426,7 +426,7 @@ def sendmail_simple(
|
||||
"""
|
||||
msg = MIMEText(content, _charset="utf-8")
|
||||
set_email_headers(msg, subject, sender, rcpt)
|
||||
return __sendmail(sender, rcpt, msg.as_string(), **kwargs)
|
||||
return _sendmail(sender, rcpt, msg.as_string(), **kwargs)
|
||||
|
||||
|
||||
def sendmail_fromfile(sender, rcpt, fname):
|
||||
@@ -452,4 +452,4 @@ To: %s
|
||||
content += fp.read()
|
||||
fp.close()
|
||||
|
||||
return __sendmail(sender, rcpt, content)
|
||||
return _sendmail(sender, rcpt, content)
|
||||
|
||||
+19
-19
@@ -65,7 +65,7 @@ def modified_utf7(s):
|
||||
return s_utf7[1:-1].replace(b"/", b",")
|
||||
|
||||
|
||||
def doB64(_in, r):
|
||||
def doB64(_in, r): # NOQA:N802
|
||||
if _in:
|
||||
r.extend([b"&", modified_utf7("".join(_in)), b"-"])
|
||||
del _in[:]
|
||||
@@ -137,32 +137,32 @@ codecs.register(imap4_utf_7)
|
||||
|
||||
# testing methods
|
||||
|
||||
def imapUTF7Encode(ust):
|
||||
def imapUTF7Encode(ust): # NOQA:N802
|
||||
"Returns imap utf-7 encoded version of string"
|
||||
return ust.encode("imap4-utf-7")
|
||||
|
||||
|
||||
def imapUTF7EncodeSequence(seq):
|
||||
def imapUTF7EncodeSequence(seq): # NOQA:N802
|
||||
"Returns imap utf-7 encoded version of strings in sequence"
|
||||
return [imapUTF7Encode(itm) for itm in seq]
|
||||
|
||||
|
||||
def imapUTF7Decode(st):
|
||||
def imapUTF7Decode(st): # NOQA:N802
|
||||
"Returns utf7 encoded version of imap utf-7 string"
|
||||
return st.decode("imap4-utf-7")
|
||||
|
||||
|
||||
def imapUTF7DecodeSequence(seq):
|
||||
def imapUTF7DecodeSequence(seq): # NOQA:N802
|
||||
"Returns utf7 encoded version of imap utf-7 strings in sequence"
|
||||
return [imapUTF7Decode(itm) for itm in seq]
|
||||
|
||||
|
||||
def utf8Decode(st):
|
||||
def utf8Decode(st): # NOQA:N802
|
||||
"Returns utf7 encoded version of imap utf-7 string"
|
||||
return st.decode("utf-8")
|
||||
|
||||
|
||||
def utf7SequenceToUTF8(seq):
|
||||
def utf7SequenceToUTF8(seq): # NOQA:N802
|
||||
"Returns utf7 encoded version of imap utf-7 strings in sequence"
|
||||
return [itm.decode("imap4-utf-7").encode("utf-8") for itm in seq]
|
||||
|
||||
@@ -171,33 +171,33 @@ __all__ = ["imapUTF7Encode", "imapUTF7Decode", ]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# print u'bøx'.encode('imap4-utf-7')
|
||||
# print u'bøx'.encode('imap4-utf-7')
|
||||
# print 'expected b&APg-x'
|
||||
|
||||
# print u'båx'.encode('imap4-utf-7')
|
||||
# print u'båx'.encode('imap4-utf-7')
|
||||
# print 'expected b&AOU-x'
|
||||
|
||||
print("#######")
|
||||
print("bøx")
|
||||
e = imapUTF7Encode(u'bøx')
|
||||
print("bøx")
|
||||
e = imapUTF7Encode(u'bøx')
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
print("#######")
|
||||
print("båx")
|
||||
e = imapUTF7Encode(u'båx')
|
||||
print("båx")
|
||||
e = imapUTF7Encode(u'båx')
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
print("#######")
|
||||
print("~/bågø")
|
||||
e = imapUTF7Encode(u'~/bågø')
|
||||
print("~/bågø")
|
||||
e = imapUTF7Encode(u'~/bågø')
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
print("#######")
|
||||
print("Ting & Såger")
|
||||
e = imapUTF7Encode(u'Ting & Såger')
|
||||
print("Ting & Såger")
|
||||
e = imapUTF7Encode(u'Ting & Såger')
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
@@ -208,8 +208,8 @@ if __name__ == "__main__":
|
||||
# print e.encode('latin-1')
|
||||
|
||||
print("#######")
|
||||
print("~/Følder/mailbåx & stuff + more")
|
||||
n = u'~/Følder/mailbåx & stuff + more'
|
||||
print("~/Følder/mailbåx & stuff + more")
|
||||
n = u'~/Følder/mailbåx & stuff + more'
|
||||
e = imapUTF7Encode(n)
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
@@ -19,7 +19,7 @@ class AjaxLoginRedirect(MiddlewareMixin):
|
||||
|
||||
def process_response(self, request, response):
|
||||
if request.is_ajax():
|
||||
if type(response) == HttpResponseRedirect:
|
||||
if isinstance(response, HttpResponseRedirect):
|
||||
response.status_code = 278
|
||||
return response
|
||||
|
||||
@@ -41,7 +41,7 @@ class CommonExceptionCatcher(MiddlewareMixin):
|
||||
smart_text(exception), status=exception.http_code
|
||||
)
|
||||
return _render_error(
|
||||
request, user_context=dict(error=smart_text(exception))
|
||||
request, user_context={"error": smart_text(exception)}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ from __future__ import unicode_literals
|
||||
class _Singleton(type):
|
||||
_instances = {}
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls not in cls._instances:
|
||||
cls._instances[cls] = \
|
||||
super(_Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instances[cls]
|
||||
def __call__(self, *args, **kwargs):
|
||||
if self not in self._instances:
|
||||
self._instances[self] = \
|
||||
super(_Singleton, self).__call__(*args, **kwargs)
|
||||
return self._instances[self]
|
||||
|
||||
|
||||
class Singleton(_Singleton("SingletonMeta", (object,), {})):
|
||||
|
||||
@@ -18,7 +18,7 @@ register = template.Library()
|
||||
def render_form(form, tpl=None):
|
||||
"""Render a form."""
|
||||
if tpl is not None:
|
||||
return render_to_string(tpl, dict(form=form))
|
||||
return render_to_string(tpl, {"form": form})
|
||||
|
||||
ret = ""
|
||||
for field in form:
|
||||
@@ -44,7 +44,7 @@ def render_field(
|
||||
"""Render a field."""
|
||||
from modoboa.core.templatetags.core_tags import visirule
|
||||
|
||||
if type(field.field) is SeparatorField:
|
||||
if isinstance(field.field, SeparatorField):
|
||||
return "<h5%s>%s</h5>" % (visirule(field), smart_text(field.label))
|
||||
configure_field_classes(field)
|
||||
context = {
|
||||
@@ -75,10 +75,11 @@ def render_fields_group(form, pattern):
|
||||
group += [bfield]
|
||||
cpt += 1
|
||||
|
||||
return render_to_string("common/generic_fields_group.html", dict(
|
||||
label=label, help_text=first.help_text, group=group, haserror=haserror,
|
||||
pattern=pattern
|
||||
))
|
||||
return render_to_string(
|
||||
"common/generic_fields_group.html",
|
||||
{"label": label, "help_text": first.help_text, "group": group,
|
||||
"haserror": haserror, "pattern": pattern}
|
||||
)
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
|
||||
@@ -36,7 +36,7 @@ def alert(msg, typ):
|
||||
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||
{{ msg }}
|
||||
</div>""")
|
||||
return t.render(Context(dict(type=typ, msg=msg)))
|
||||
return t.render(Context({"type": typ, "msg": msg}))
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
@@ -51,7 +51,7 @@ class="{{ mdclass }}{% if link.class %} {{ link.class }}{% endif %}"
|
||||
>
|
||||
{% if link.img %}<i class="{{ link.img }}"></i>{% endif %}
|
||||
{{ link.label }}</a>""")
|
||||
return t.render(Context(dict(link=linkdef, mdclass=mdclass)))
|
||||
return t.render(Context({"link": linkdef, "mdclass": mdclass}))
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
|
||||
@@ -29,7 +29,7 @@ def render_actions(actions):
|
||||
t = template.Template("""{% load lib_tags %}
|
||||
{% for a in actions %}{% render_link a %}{% endfor %}
|
||||
""")
|
||||
return t.render(template.Context(dict(actions=actions)))
|
||||
return t.render(template.Context({"actions": actions}))
|
||||
|
||||
|
||||
def getctx(status, level=1, callback=None, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user