mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-19 05:58:34 +02:00
make modoboa-admin deploy work with python 3.4
This commit is contained in:
@@ -11,6 +11,8 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from os.path import isfile
|
||||
|
||||
try:
|
||||
import pip
|
||||
except ImportError:
|
||||
@@ -108,8 +110,10 @@ class DeployCommand(Command):
|
||||
output = None
|
||||
if p.returncode:
|
||||
if output:
|
||||
print("\n".join(
|
||||
[l for l in output if l is not None]), file=sys.stderr)
|
||||
print(
|
||||
"\n".join([l.decode() for l in output if l is not None]),
|
||||
file=sys.stderr
|
||||
)
|
||||
print("%s failed, check your configuration" % cmd, file=sys.stderr)
|
||||
|
||||
def ask_db_info(self, name='default'):
|
||||
@@ -250,7 +254,8 @@ class DeployCommand(Command):
|
||||
)
|
||||
os.mkdir("%s/media" % parsed_args.name)
|
||||
|
||||
os.unlink("%s/settings.pyc" % path)
|
||||
if isfile("%s/settings.pyc" % path):
|
||||
os.unlink("%s/settings.pyc" % path)
|
||||
self._exec_django_command(
|
||||
"migrate", parsed_args.name, '--noinput'
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# coding: utf-8
|
||||
"""Crypto related utilities."""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import random
|
||||
import string
|
||||
@@ -17,7 +19,7 @@ def random_key(l=16):
|
||||
:return: a string
|
||||
"""
|
||||
punctuation = """!#$%&'()*+,-./:;<=>?@[]^_`{|}~"""
|
||||
population = string.digits + string.letters + punctuation
|
||||
population = string.digits + string.ascii_letters + punctuation
|
||||
while True:
|
||||
key = "".join(random.sample(population * l, l))
|
||||
if len(key) == l:
|
||||
@@ -27,7 +29,7 @@ def random_key(l=16):
|
||||
def encrypt(clear):
|
||||
key = param_tools.get_global_parameter("secret_key", app="core")
|
||||
obj = AES.new(key, AES.MODE_ECB)
|
||||
if type(clear) is unicode:
|
||||
if type(clear) is str:
|
||||
clear = clear.encode("utf-8")
|
||||
if len(clear) % AES.block_size:
|
||||
clear += " " * (AES.block_size - len(clear) % AES.block_size)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
"""Form management utilities."""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import abc
|
||||
from builtins import object, range
|
||||
from collections import OrderedDict
|
||||
@@ -12,7 +14,7 @@ from django.forms.fields import Field
|
||||
from django.forms.widgets import RadioSelect
|
||||
from django.forms.widgets import RadioChoiceInput
|
||||
from django.shortcuts import render
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.html import conditional_escape
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
@@ -376,7 +378,7 @@ class CustomRadioInput(RadioChoiceInput):
|
||||
label_for = ' for="%s"' % self.attrs["id"]
|
||||
else:
|
||||
label_for = ""
|
||||
choice_label = conditional_escape(force_unicode(self.choice_label))
|
||||
choice_label = conditional_escape(force_text(self.choice_label))
|
||||
return mark_safe(
|
||||
u"<label class='radio-inline' %s>%s %s</label>"
|
||||
% (label_for, self.tag(), choice_label)
|
||||
@@ -394,7 +396,7 @@ class InlineRadioRenderer(RadioSelect.renderer):
|
||||
|
||||
def render(self):
|
||||
return mark_safe(
|
||||
u"\n".join([u"%s\n" % force_unicode(w) for w in self])
|
||||
u"\n".join([u"%s\n" % force_text(w) for w in self])
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# coding: utf-8
|
||||
"""Object level permissions."""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
@@ -143,7 +145,7 @@ def get_object_owner(obj):
|
||||
|
||||
def add_permissions_to_group(group, permissions):
|
||||
"""Add the specified permissions to a django group."""
|
||||
if isinstance(group, basestring):
|
||||
if isinstance(group, str):
|
||||
group = Group.objects.get(name=group)
|
||||
|
||||
for appname, modelname, permname in permissions:
|
||||
|
||||
@@ -33,7 +33,7 @@ def decode_mime(m):
|
||||
|
||||
|
||||
def u2u_decode(s):
|
||||
ur"""utility function for (final) decoding of mime header
|
||||
"""utility function for (final) decoding of mime header
|
||||
|
||||
note: resulting string is in one line (no \n within)
|
||||
note2: spaces between enc_words are stripped (see RFC2047)
|
||||
|
||||
@@ -45,9 +45,9 @@ class UTF8EmailValidator(EmailValidator):
|
||||
ascii_set = u"-!#$%&'*+/=?^_`{}|~0-9A-Z"
|
||||
user_regex_raw = (
|
||||
# dot-atom
|
||||
ur"^[" + ascii_set + ul + "]+(\.[" + ascii_set + ul + "]+)*\Z"
|
||||
r"^[" + ascii_set + ul + "]+(\.[" + ascii_set + ul + "]+)*\Z"
|
||||
# quoted-string
|
||||
ur'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)'
|
||||
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)'
|
||||
)
|
||||
user_regex = re.compile("(" + user_regex_raw, re.IGNORECASE)
|
||||
|
||||
@@ -59,6 +59,6 @@ class UTF8AndEmptyUserEmailValidator(UTF8EmailValidator):
|
||||
"""Same as upper + allows empty local part."""
|
||||
|
||||
user_regex = re.compile(
|
||||
ur"(^$|" + UTF8EmailValidator.user_regex_raw, re.IGNORECASE)
|
||||
r"(^$|" + UTF8EmailValidator.user_regex_raw, re.IGNORECASE)
|
||||
|
||||
validate_utf8_and_empty_user_email = UTF8AndEmptyUserEmailValidator()
|
||||
|
||||
Reference in New Issue
Block a user