summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/kolab_parse_telemetry.py5
-rwxr-xr-xbin/kolab_smtp_access_policy.py26
-rwxr-xr-xconf.py8
-rw-r--r--configure.ac2
-rw-r--r--cyruslib.py34
-rw-r--r--ext/python/Tools/freeze/checkextensions.py6
-rw-r--r--ext/python/Tools/freeze/checkextensions_win32.py2
-rwxr-xr-xext/python/Tools/freeze/freeze.py28
-rw-r--r--ext/python/Tools/freeze/hello.py2
-rw-r--r--ext/python/Tools/freeze/makeconfig.py4
-rw-r--r--ext/python/Tools/freeze/makefreeze.py4
-rw-r--r--ext/python/Tools/freeze/parsesetup.py12
-rw-r--r--ext/python/Tools/freeze/winmakemakefile.py126
-rwxr-xr-xkolab-cli.py8
-rw-r--r--kolabd/__init__.py4
-rw-r--r--pykolab/__init__.py3
-rw-r--r--pykolab/auth/ldap/__init__.py29
-rw-r--r--pykolab/auth/ldap/auth_cache.py52
-rw-r--r--pykolab/auth/ldap/syncrepl.py11
-rw-r--r--pykolab/cli/__init__.py14
-rw-r--r--pykolab/cli/cmd_acl_cleanup.py8
-rw-r--r--pykolab/cli/cmd_add_alias.py35
-rw-r--r--pykolab/cli/cmd_add_domain.py4
-rw-r--r--pykolab/cli/cmd_add_user.py2
-rw-r--r--pykolab/cli/cmd_add_user_subscription.py14
-rw-r--r--pykolab/cli/cmd_check_quota.py12
-rw-r--r--pykolab/cli/cmd_count_domain_mailboxes.py8
-rw-r--r--pykolab/cli/cmd_create_mailbox.py4
-rw-r--r--pykolab/cli/cmd_delete_domain.py4
-rw-r--r--pykolab/cli/cmd_delete_mailbox.py12
-rw-r--r--pykolab/cli/cmd_delete_mailbox_acl.py10
-rw-r--r--pykolab/cli/cmd_delete_message.py2
-rw-r--r--pykolab/cli/cmd_export_mailbox.py8
-rw-r--r--pykolab/cli/cmd_find_domain.py4
-rw-r--r--pykolab/cli/cmd_list_deleted_mailboxes.py8
-rw-r--r--pykolab/cli/cmd_list_domain_mailboxes.py8
-rw-r--r--pykolab/cli/cmd_list_domains.py12
-rw-r--r--pykolab/cli/cmd_list_mailbox_acls.py14
-rw-r--r--pykolab/cli/cmd_list_mailbox_metadata.py18
-rw-r--r--pykolab/cli/cmd_list_mailboxes.py6
-rw-r--r--pykolab/cli/cmd_list_messages.py14
-rw-r--r--pykolab/cli/cmd_list_ous.py4
-rw-r--r--pykolab/cli/cmd_list_quota.py34
-rw-r--r--pykolab/cli/cmd_list_user_subscriptions.py16
-rw-r--r--pykolab/cli/cmd_list_users.py4
-rw-r--r--pykolab/cli/cmd_mailbox_cleanup.py119
-rw-r--r--pykolab/cli/cmd_remove_mailaddress.py15
-rw-r--r--pykolab/cli/cmd_remove_user_subscription.py24
-rw-r--r--pykolab/cli/cmd_rename_mailbox.py18
-rw-r--r--pykolab/cli/cmd_server_info.py4
-rw-r--r--pykolab/cli/cmd_set_language.py2
-rw-r--r--pykolab/cli/cmd_set_mail.py2
-rw-r--r--pykolab/cli/cmd_set_mailbox_acl.py12
-rw-r--r--pykolab/cli/cmd_set_mailbox_metadata.py12
-rw-r--r--pykolab/cli/cmd_set_quota.py12
-rw-r--r--pykolab/cli/cmd_sync.py4
-rw-r--r--pykolab/cli/cmd_sync_mailhost_attrs.py12
-rw-r--r--pykolab/cli/cmd_transfer_mailbox.py2
-rw-r--r--pykolab/cli/cmd_undelete_mailbox.py2
-rw-r--r--pykolab/cli/cmd_user_info.py14
-rw-r--r--pykolab/cli/commands.py47
-rw-r--r--pykolab/cli/sieve/cmd_list.py13
-rw-r--r--pykolab/cli/sieve/cmd_put.py5
-rw-r--r--pykolab/cli/sieve/cmd_refresh.py30
-rw-r--r--pykolab/cli/sieve/cmd_test.py23
-rw-r--r--pykolab/cli/telemetry/cmd_examine_command_issue.py14
-rw-r--r--pykolab/cli/telemetry/cmd_examine_session.py10
-rw-r--r--pykolab/cli/telemetry/cmd_list_sessions.py4
-rw-r--r--pykolab/cli/wap/cmd_system_capabilities.py10
-rw-r--r--pykolab/cli/wap/cmd_user_types_list.py2
-rw-r--r--pykolab/conf/__init__.py24
-rw-r--r--pykolab/conf/entitlement.py39
-rw-r--r--pykolab/constants.py.in4
-rw-r--r--pykolab/imap/__init__.py53
-rw-r--r--pykolab/imap/cyrus.py31
-rw-r--r--pykolab/imap/dovecot.py13
-rw-r--r--pykolab/imap_utf7.py54
-rw-r--r--pykolab/logger.py6
-rw-r--r--pykolab/plugins/__init__.py20
-rw-r--r--pykolab/plugins/defaultfolders/__init__.py4
-rw-r--r--pykolab/plugins/dynamicquota/__init__.py2
-rw-r--r--pykolab/plugins/recipientpolicy/__init__.py24
-rw-r--r--pykolab/plugins/roundcubedb/__init__.py2
-rw-r--r--pykolab/plugins/sievemgmt/__init__.py32
-rw-r--r--pykolab/setup/__init__.py4
-rw-r--r--pykolab/setup/components.py47
-rw-r--r--pykolab/setup/setup_freebusy.py18
-rw-r--r--pykolab/setup/setup_guam.py2
-rw-r--r--pykolab/setup/setup_imap.py2
-rw-r--r--pykolab/setup/setup_kolabd.py2
-rw-r--r--pykolab/setup/setup_ldap.py58
-rw-r--r--pykolab/setup/setup_manticore.py2
-rw-r--r--pykolab/setup/setup_mta.py13
-rw-r--r--pykolab/setup/setup_mysql.py18
-rw-r--r--pykolab/setup/setup_php.py7
-rw-r--r--pykolab/setup/setup_roundcube.py14
-rw-r--r--pykolab/setup/setup_syncroton.py10
-rw-r--r--pykolab/telemetry.py4
-rw-r--r--pykolab/translit.py18
-rw-r--r--pykolab/utils.py6
-rw-r--r--pykolab/wap_client/__init__.py78
-rw-r--r--pykolab/xml/__init__.py58
-rw-r--r--pykolab/xml/attendee.py36
-rw-r--r--pykolab/xml/contact.py32
-rw-r--r--pykolab/xml/contact_reference.py2
-rw-r--r--pykolab/xml/event.py105
-rw-r--r--pykolab/xml/note.py14
-rw-r--r--pykolab/xml/recurrence_rule.py16
-rw-r--r--pykolab/xml/todo.py24
-rw-r--r--pykolab/xml/utils.py26
-rwxr-xr-xsaslauthd.py8
-rw-r--r--saslauthd/__init__.py47
-rwxr-xr-xsetup-kolab.py8
-rw-r--r--tests/functional/resource_func.py6
-rw-r--r--tests/functional/test_kolabd/test_001_user_sync.py6
-rw-r--r--tests/functional/test_kolabd/test_002_user_rename.py4
-rw-r--r--tests/functional/test_wallace/test_002_footer.py2
-rw-r--r--tests/functional/test_wallace/test_006_resource_performance.py4
-rw-r--r--tests/functional/test_wap_client/test_002_user_add.py6
-rw-r--r--tests/functional/test_wap_client/test_003_user_add_fr_FR.py2
-rw-r--r--tests/functional/test_wap_client/test_007_policy_uid.py5
-rw-r--r--tests/functional/user_add.py6
-rw-r--r--tests/unit/test-002-attendee.py48
-rw-r--r--tests/unit/test-003-event.py24
-rw-r--r--tests/unit/test-008-sievelib.py2
-rw-r--r--tests/unit/test-011-wallace_resources.py56
-rwxr-xr-xucs/kolab_sieve.py6
-rwxr-xr-xucs/listener.py6
-rwxr-xr-xwallace.py8
-rw-r--r--wallace/__init__.py9
-rw-r--r--wallace/module_footer.py6
-rw-r--r--wallace/module_gpgencrypt.py6
-rw-r--r--wallace/module_invitationpolicy.py72
-rw-r--r--wallace/module_optout.py19
-rw-r--r--wallace/module_resources.py86
-rw-r--r--wallace/module_signature.py4
-rw-r--r--wallace/modules.py15
137 files changed, 1379 insertions, 1073 deletions
diff --git a/bin/kolab_parse_telemetry.py b/bin/kolab_parse_telemetry.py
index 4832f87..a02182a 100755
--- a/bin/kolab_parse_telemetry.py
+++ b/bin/kolab_parse_telemetry.py
@@ -25,7 +25,10 @@ import sys
import time
from optparse import OptionParser
-from ConfigParser import SafeConfigParser
+try:
+ from ConfigParser import SafeConfigParser
+except ImportError:
+ from configparser import SafeConfigParser
import sqlalchemy
from sqlalchemy import Boolean
diff --git a/bin/kolab_smtp_access_policy.py b/bin/kolab_smtp_access_policy.py
index e03bad0..4299c98 100755
--- a/bin/kolab_smtp_access_policy.py
+++ b/bin/kolab_smtp_access_policy.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import datetime
import os
@@ -25,8 +26,11 @@ import sys
import time
from optparse import OptionParser
-from ConfigParser import SafeConfigParser
-
+try:
+ from ConfigParser import SafeConfigParser
+except ImportError:
+ from configparser import SafeConfigParser
+
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import Date
@@ -184,7 +188,7 @@ class PolicyRequest(object):
http://www.postfix.org/SMTPD_POLICY_README.html
"""
- for key in policy_request.keys():
+ for key in policy_request:
# Normalize email addresses (they may contain recipient delimiters)
if key in self.email_address_keys:
@@ -263,7 +267,7 @@ class PolicyRequest(object):
for search_attr in search_attrs:
if search_attr in rule_subject:
- if isinstance(rule_subject[search_attr], basestring):
+ if isinstance(rule_subject[search_attr], string_types):
values.append(rule_subject[search_attr])
else:
values.extend(rule_subject[search_attr])
@@ -325,7 +329,7 @@ class PolicyRequest(object):
rules = {'allow': [], 'deny': []}
- if isinstance(policy, basestring):
+ if isinstance(policy, string_types):
policy = [policy]
for rule in policy:
@@ -333,7 +337,7 @@ class PolicyRequest(object):
# mapping the rule onto a key in "special_rule_values", a
# dictionary with the corresponding value set to a function to
# execute.
- if rule in special_rule_values.keys():
+ if rule in special_rule_values:
special_rules = special_rule_values[rule]()
if rule.startswith("-"):
rules['deny'].extend(special_rules)
@@ -510,7 +514,7 @@ class PolicyRequest(object):
return False
else:
self.sasl_user = {'dn': sasl_users[0]}
- elif isinstance(sasl_users, basestring):
+ elif isinstance(sasl_users, string_types):
self.sasl_user = {'dn': sasl_users}
if not self.sasl_user['dn']:
@@ -613,7 +617,7 @@ class PolicyRequest(object):
else:
self.sender_user = {'dn': False}
- elif isinstance(sender_users, basestring):
+ elif isinstance(sender_users, string_types):
self.sender_user = {'dn': sender_users}
if not self.sender_user['dn']:
@@ -708,7 +712,7 @@ class PolicyRequest(object):
return False
else:
self.sasl_user = {'dn': sasl_users[0]}
- elif isinstance(sasl_users, basestring):
+ elif isinstance(sasl_users, string_types):
self.sasl_user = {'dn': sasl_users}
# Possible values for the kolabDelegate attribute are:
@@ -889,7 +893,7 @@ class PolicyRequest(object):
return True
- elif isinstance(recipients, basestring):
+ elif isinstance(recipients, string_types):
_recipient = {'dn': recipients}
# We have gotten an invalid recipient. We need to catch this case,
@@ -1599,7 +1603,7 @@ def verify_domain(domain):
global auth, mydomains
if mydomains is not None:
- return domain in mydomains.keys()
+ return domain in mydomains
auth.connect()
diff --git a/conf.py b/conf.py
index 8e5ef43..6b5d71f 100755
--- a/conf.py
+++ b/conf.py
@@ -22,6 +22,8 @@
Kolab configuration utility.
"""
+from __future__ import print_function
+
import logging
import os
import sys
@@ -32,9 +34,9 @@ from pykolab.translate import _
try:
import pykolab.logger
-except ImportError, e:
- print >> sys.stderr, _("Cannot load pykolab/logger.py:")
- print >> sys.stderr, "%s" % e
+except ImportError as e:
+ print(_("Cannot load pykolab/logger.py:"), file=sys.stderr)
+ print("%s" % e, file=sys.stderr)
sys.exit(1)
import pykolab
diff --git a/configure.ac b/configure.ac
index 471763d..8d10eb8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([pykolab], 0.8.19)
+AC_INIT([pykolab], 0.8.23)
AC_SUBST([RELEASE], 1)
AC_CONFIG_SRCDIR(pykolab/constants.py.in)
diff --git a/cyruslib.py b/cyruslib.py
index 9e42f39..169d5f9 100644
--- a/cyruslib.py
+++ b/cyruslib.py
@@ -18,9 +18,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-# Requires python >= 2.3
+# Requires python >= 2.6
#
+from __future__ import print_function
+
__version__ = '0.8.5'
__all__ = [ 'CYRUS' ]
__doc__ = """Cyrus admin wrapper
@@ -35,8 +37,8 @@ try:
import imaplib
import re
from binascii import b2a_base64
-except ImportError, e:
- print e
+except ImportError as e:
+ print(e)
exit(1)
Commands = {
@@ -342,7 +344,7 @@ class CYRUS:
def __verbose(self, msg):
if self.VERBOSE:
- print >> self.LOGFD, msg
+ print(msg, file=self.LOGFD)
def __doexception(self, function, msg=None, *args):
if msg is None:
@@ -382,7 +384,7 @@ class CYRUS:
res, msg = wrapped(*args)
if ok(res):
return res, msg
- except Exception, info:
+ except Exception as info:
error = str(info).split(':').pop().strip()
if error.upper().startswith('BAD'):
error = error.split('BAD', 1).pop().strip()
@@ -413,7 +415,7 @@ class CYRUS:
self.AUTH = True
self.id()
admin = self.m.isadmin()
- except Exception, info:
+ except Exception as info:
self.AUTH = False
error = str(info).split(':').pop().strip()
self.__doexception("LOGIN", error)
@@ -446,7 +448,7 @@ class CYRUS:
def logout(self):
try:
res, msg = self.m.logout()
- except Exception, info:
+ except Exception as info:
error = str(info).split(':').pop().strip()
self.__doexception("LOGOUT", error)
self.AUTH = False
@@ -575,7 +577,7 @@ class CYRUS:
try:
userid = self.encode(aclList[i])
rights = aclList[i + 1]
- except Exception, info:
+ except Exception as info:
self.__verbose( '[GETACL %s] BAD: %s' % (mailbox, info.args[0]) )
raise self.__doraise("GETACL")
self.__verbose( '[GETACL %s] %s %s' % (mailbox, userid, rights) )
@@ -635,7 +637,7 @@ class CYRUS:
self.__prepare('SETQUOTA', mailbox)
try:
limit = int(limit)
- except ValueError, e:
+ except ValueError:
self.__verbose( '[SETQUOTA %s] BAD: %s %s' % (mailbox, self.ERROR.get("SETQUOTA")[1], limit) )
raise self.__doraise("SETQUOTA")
res, msg = self.__docommand("setquota", self.decode(mailbox), limit)
@@ -687,21 +689,21 @@ class CYRUS:
key = annotation.split('"')[3].replace('"','').replace("'","").strip()
_annot = annotation.split('(')[1].split(')')[0].strip()
- if not ann.has_key(folder):
+ if folder not in ann:
ann[folder] = {}
try:
value_priv = _annot[(_annot.index('"value.priv"')+len('"value.priv"')):_annot.index('"size.priv"')].strip()
- except ValueError, errmsg:
+ except ValueError:
value_priv = None
try:
size_priv = _annot[(_annot.index('"size.priv"')+len('"size.priv"')):].strip().split('"')[1].strip()
try:
value_priv = value_priv[value_priv.index('{%s}' % (size_priv))+len('{%s}' % (size_priv)):].strip()
- except Exception, errmsg:
+ except Exception:
pass
- except Exception, errmsg:
+ except Exception:
pass
if value_priv in empty_values:
@@ -728,16 +730,16 @@ class CYRUS:
try:
value_shared = _annot[(_annot.index('"value.shared"')+len('"value.shared"')):_annot.index('"size.shared"')].strip()
- except ValueError, errmsg:
+ except ValueError:
value_shared = None
try:
size_shared = _annot[(_annot.index('"size.shared"')+len('"size.shared"')):].strip().split('"')[1].strip()
try:
value_shared = value_shared[value_shared.index('{%s}' % (size_shared))+len('{%s}' % (size_shared)):].strip()
- except Exception, errmsg:
+ except Exception:
pass
- except Exception, errmsg:
+ except Exception:
pass
if value_shared in empty_values:
diff --git a/ext/python/Tools/freeze/checkextensions.py b/ext/python/Tools/freeze/checkextensions.py
index 334521f..abffe18 100644
--- a/ext/python/Tools/freeze/checkextensions.py
+++ b/ext/python/Tools/freeze/checkextensions.py
@@ -18,7 +18,7 @@ def checkextensions(unknown, extensions):
for mod in unknown:
for e in extensions:
(mods, vars), liba = edict[e]
- if not mods.has_key(mod):
+ if mod not in mods:
continue
modules.append(mod)
if liba:
@@ -28,7 +28,7 @@ def checkextensions(unknown, extensions):
if liba in files:
break
files.append(liba)
- for m in mods.keys():
+ for m in mods:
files = files + select(e, mods, vars,
m, 1)
break
@@ -84,7 +84,7 @@ def expandvars(str, vars):
break
var = str[i:j]
i = j+1
- if vars.has_key(var):
+ if var in vars:
str = str[:k] + vars[var] + str[i:]
i = k
return str
diff --git a/ext/python/Tools/freeze/checkextensions_win32.py b/ext/python/Tools/freeze/checkextensions_win32.py
index a198ecf..ba3853c 100644
--- a/ext/python/Tools/freeze/checkextensions_win32.py
+++ b/ext/python/Tools/freeze/checkextensions_win32.py
@@ -131,7 +131,7 @@ def parse_dsp(dsp):
dsp_path, dsp_name = os.path.split(dsp)
try:
lines = open(dsp, "r").readlines()
- except IOError, msg:
+ except IOError as msg:
sys.stderr.write("%s: %s\n" % (dsp, msg))
return None
for line in lines:
diff --git a/ext/python/Tools/freeze/freeze.py b/ext/python/Tools/freeze/freeze.py
index 46bfd90..e584de6 100755
--- a/ext/python/Tools/freeze/freeze.py
+++ b/ext/python/Tools/freeze/freeze.py
@@ -145,7 +145,7 @@ def main():
if sys.argv[pos] == '-i':
try:
options = open(sys.argv[pos+1]).read().split()
- except IOError, why:
+ except IOError as why:
usage("File name '%s' specified with the -i option "
"can not be read - %s" % (sys.argv[pos+1], why) )
# Replace the '-i' and the filename with the read params.
@@ -156,13 +156,13 @@ def main():
# Now parse the command line with the extras inserted.
try:
opts, args = getopt.getopt(sys.argv[1:], 'r:a:dEe:hmo:p:P:b:qs:wX:x:l:')
- except getopt.error, msg:
+ except getopt.error as msg:
usage('getopt error: ' + str(msg))
# process option arguments
for o, a in opts:
if o == '-h':
- print __doc__
+ print(__doc__)
return
if o == '-b':
binlib = a
@@ -224,7 +224,7 @@ def main():
if win:
extensions_c = 'frozen_extensions.c'
if ishome:
- print "(Using Python source directory)"
+ print("(Using Python source directory)")
binlib = exec_prefix
incldir = os.path.join(prefix, 'Include')
config_h_dir = exec_prefix
@@ -316,8 +316,8 @@ def main():
if odir and not os.path.isdir(odir):
try:
os.mkdir(odir)
- print "Created output directory", odir
- except os.error, msg:
+ print("Created output directory", odir)
+ except os.error as msg:
usage('%s: mkdir failed (%s)' % (odir, str(msg)))
base = ''
if odir:
@@ -339,7 +339,7 @@ def main():
try:
custom_entry_point, python_entry_is_main = \
winmakemakefile.get_custom_entry_point(subsystem)
- except ValueError, why:
+ except ValueError as why:
usage(why)
@@ -377,7 +377,7 @@ def main():
if debug > 0:
mf.report()
- print
+ print()
dict = mf.modules
if error_if_any_missing:
@@ -467,7 +467,7 @@ def main():
somevars = {}
if os.path.exists(makefile_in):
makevars = parsesetup.getmakevars(makefile_in)
- for key in makevars.keys():
+ for key in makevars:
somevars[key] = makevars[key]
somevars['CFLAGS'] = ' '.join(cflags) # override
@@ -485,18 +485,18 @@ def main():
# Done!
if odir:
- print 'Now run "make" in', odir,
- print 'to build the target:', base_target
+ print('Now run "make" in', odir, end=' ')
+ print('to build the target:', base_target)
else:
- print 'Now run "make" to build the target:', base_target
+ print('Now run "make" to build the target:', base_target)
# Print usage message and exit
def usage(msg):
sys.stdout = sys.stderr
- print "Error:", msg
- print "Use ``%s -h'' for help" % sys.argv[0]
+ print("Error:", msg)
+ print("Use ``%s -h'' for help" % sys.argv[0])
sys.exit(2)
diff --git a/ext/python/Tools/freeze/hello.py b/ext/python/Tools/freeze/hello.py
index f978acc..d7a3729 100644
--- a/ext/python/Tools/freeze/hello.py
+++ b/ext/python/Tools/freeze/hello.py
@@ -1 +1 @@
-print 'Hello world...'
+print('Hello world...')
diff --git a/ext/python/Tools/freeze/makeconfig.py b/ext/python/Tools/freeze/makeconfig.py
index b9bfd08..8aba55e 100644
--- a/ext/python/Tools/freeze/makeconfig.py
+++ b/ext/python/Tools/freeze/makeconfig.py
@@ -40,8 +40,8 @@ def makeconfig(infp, outfp, modules, with_ifdef=0):
def test():
import sys
if not sys.argv[3:]:
- print 'usage: python makeconfig.py config.c.in outputfile',
- print 'modulename ...'
+ print('usage: python makeconfig.py config.c.in outputfile', end=' ')
+ print('modulename ...')
sys.exit(2)
if sys.argv[1] == '-':
infp = sys.stdin
diff --git a/ext/python/Tools/freeze/makefreeze.py b/ext/python/Tools/freeze/makefreeze.py
index 1208b67..e359db9 100644
--- a/ext/python/Tools/freeze/makefreeze.py
+++ b/ext/python/Tools/freeze/makefreeze.py
@@ -43,7 +43,7 @@ def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
outfp = bkfile.open(base + file, 'w')
files.append(file)
if debug:
- print "freezing", mod, "..."
+ print("freezing", mod, "...")
str = marshal.dumps(m.__code__)
size = len(str)
if m.__path__:
@@ -53,7 +53,7 @@ def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
writecode(outfp, mangled, str)
outfp.close()
if debug:
- print "generating table of frozen modules"
+ print("generating table of frozen modules")
outfp = bkfile.open(base + 'frozen.c', 'w')
for mod, mangled, size in done:
outfp.write('extern unsigned char M_%s[];\n' % mangled)
diff --git a/ext/python/Tools/freeze/parsesetup.py b/ext/python/Tools/freeze/parsesetup.py
index 856234d..ae0bc43 100644
--- a/ext/python/Tools/freeze/parsesetup.py
+++ b/ext/python/Tools/freeze/parsesetup.py
@@ -84,29 +84,29 @@ def test():
import sys
import os
if not sys.argv[1:]:
- print 'usage: python parsesetup.py Makefile*|Setup* ...'
+ print('usage: python parsesetup.py Makefile*|Setup* ...')
sys.exit(2)
for arg in sys.argv[1:]:
base = os.path.basename(arg)
if base[:8] == 'Makefile':
- print 'Make style parsing:', arg
+ print('Make style parsing:', arg)
v = getmakevars(arg)
prdict(v)
elif base[:5] == 'Setup':
- print 'Setup style parsing:', arg
+ print('Setup style parsing:', arg)
m, v = getsetupinfo(arg)
prdict(m)
prdict(v)
else:
- print arg, 'is neither a Makefile nor a Setup file'
- print '(name must begin with "Makefile" or "Setup")'
+ print(arg, 'is neither a Makefile nor a Setup file')
+ print('(name must begin with "Makefile" or "Setup")')
def prdict(d):
keys = d.keys()
keys.sort()
for key in keys:
value = d[key]
- print "%-15s" % key, str(value)
+ print("%-15s" % key, str(value))
if __name__ == '__main__':
test()
diff --git a/ext/python/Tools/freeze/winmakemakefile.py b/ext/python/Tools/freeze/winmakemakefile.py
index 8570f3d..7d198c1 100644
--- a/ext/python/Tools/freeze/winmakemakefile.py
+++ b/ext/python/Tools/freeze/winmakemakefile.py
@@ -39,7 +39,7 @@ def get_custom_entry_point(subsystem):
try:
return subsystem_details[subsystem][:2]
except KeyError:
- raise ValueError, "The subsystem %s is not known" % subsystem
+ raise ValueError("The subsystem %s is not known" % subsystem)
def makemakefile(outfp, vars, files, target):
@@ -52,29 +52,29 @@ def makemakefile(outfp, vars, files, target):
def realwork(vars, moddefns, target):
version_suffix = "%r%r" % sys.version_info[:2]
- print "# Makefile for Microsoft Visual C++ generated by freeze.py script"
- print
- print 'target = %s' % target
- print 'pythonhome = %s' % vars['prefix']
- print
- print 'DEBUG=0 # Set to 1 to use the _d versions of Python.'
- print '!IF $(DEBUG)'
- print 'debug_suffix=_d'
- print 'c_debug=/Zi /Od /DDEBUG /D_DEBUG'
- print 'l_debug=/DEBUG'
- print 'temp_dir=Build\\Debug'
- print '!ELSE'
- print 'debug_suffix='
- print 'c_debug=/Ox'
- print 'l_debug='
- print 'temp_dir=Build\\Release'
- print '!ENDIF'
- print
-
- print '# The following line assumes you have built Python using the standard instructions'
- print '# Otherwise fix the following line to point to the library.'
- print 'pythonlib = "$(pythonhome)/pcbuild/python%s$(debug_suffix).lib"' % version_suffix
- print
+ print("# Makefile for Microsoft Visual C++ generated by freeze.py script")
+ print()
+ print('target = %s' % target)
+ print('pythonhome = %s' % vars['prefix'])
+ print()
+ print('DEBUG=0 # Set to 1 to use the _d versions of Python.')
+ print('!IF $(DEBUG)')
+ print('debug_suffix=_d')
+ print('c_debug=/Zi /Od /DDEBUG /D_DEBUG')
+ print('l_debug=/DEBUG')
+ print('temp_dir=Build\\Debug')
+ print('!ELSE')
+ print('debug_suffix=')
+ print('c_debug=/Ox')
+ print('l_debug=')
+ print('temp_dir=Build\\Release')
+ print('!ENDIF')
+ print()
+
+ print('# The following line assumes you have built Python using the standard instructions')
+ print('# Otherwise fix the following line to point to the library.')
+ print('pythonlib = "$(pythonhome)/pcbuild/python%s$(debug_suffix).lib"' % version_suffix)
+ print()
# We only ever write one "entry point" symbol - either
# "main" or "WinMain". Therefore, there is no need to
@@ -88,59 +88,59 @@ def realwork(vars, moddefns, target):
target_ext = ".dll"
- print "# As the target uses Python%s.dll, we must use this compiler option!" % version_suffix
- print "cdl = /MD"
- print
- print "all: $(target)$(debug_suffix)%s" % (target_ext)
- print
+ print("# As the target uses Python%s.dll, we must use this compiler option!" % version_suffix)
+ print("cdl = /MD")
+ print()
+ print("all: $(target)$(debug_suffix)%s" % (target_ext))
+ print()
- print '$(temp_dir):'
- print ' if not exist $(temp_dir)\. mkdir $(temp_dir)'
- print
+ print('$(temp_dir):')
+ print(' if not exist $(temp_dir)\. mkdir $(temp_dir)')
+ print()
objects = []
libs = ["shell32.lib", "comdlg32.lib", "wsock32.lib", "user32.lib", "oleaut32.lib"]
for moddefn in moddefns:
- print "# Module", moddefn.name
+ print("# Module", moddefn.name)
for file in moddefn.sourceFiles:
base = os.path.basename(file)
base, ext = os.path.splitext(base)
objects.append(base + ".obj")
- print '$(temp_dir)\%s.obj: "%s"' % (base, file)
- print "\t@$(CC) -c -nologo /Fo$* $(cdl) $(c_debug) /D BUILD_FREEZE",
- print '"-I$(pythonhome)/Include" "-I$(pythonhome)/PC" \\'
- print "\t\t$(cflags) $(cdebug) $(cinclude) \\"
+ print('$(temp_dir)\%s.obj: "%s"' % (base, file))
+ print("\t@$(CC) -c -nologo /Fo$* $(cdl) $(c_debug) /D BUILD_FREEZE", end=' ')
+ print('"-I$(pythonhome)/Include" "-I$(pythonhome)/PC" \\')
+ print("\t\t$(cflags) $(cdebug) $(cinclude) \\")
extra = moddefn.GetCompilerOptions()
if extra:
- print "\t\t%s \\" % (' '.join(extra),)
- print '\t\t"%s"' % file
- print
+ print("\t\t%s \\" % (' '.join(extra),))
+ print('\t\t"%s"' % file)
+ print()
# Add .lib files this module needs
for modlib in moddefn.GetLinkerLibs():
if modlib not in libs:
libs.append(modlib)
- print "ADDN_LINK_FILES=",
- for addn in vars['addn_link']: print '"%s"' % (addn),
- print ; print
-
- print "OBJS=",
- for obj in objects: print '"$(temp_dir)\%s"' % (obj),
- print ; print
-
- print "LIBS=",
- for lib in libs: print '"%s"' % (lib),
- print ; print
-
- print "$(target)$(debug_suffix)%s: $(temp_dir) $(OBJS)" % (target_ext)
- print "\tlink -out:$(target)$(debug_suffix)%s %s" % (target_ext, target_link_flags),
- print "\t$(OBJS) \\"
- print "\t$(LIBS) \\"
- print "\t$(ADDN_LINK_FILES) \\"
- print "\t$(pythonlib) $(lcustom) $(l_debug)\\"
- print "\t$(resources)"
- print
- print "clean:"
- print "\t-rm -f *.obj"
- print "\t-rm -f $(target).exe"
+ print("ADDN_LINK_FILES=", end=' ')
+ for addn in vars['addn_link']: print('"%s"' % (addn), end=' ')
+ print() ; print()
+
+ print("OBJS=", end=' ')
+ for obj in objects: print('"$(temp_dir)\%s"' % (obj), end=' ')
+ print() ; print()
+
+ print("LIBS=", end=' ')
+ for lib in libs: print('"%s"' % (lib), end=' ')
+ print() ; print()
+
+ print("$(target)$(debug_suffix)%s: $(temp_dir) $(OBJS)" % (target_ext))
+ print("\tlink -out:$(target)$(debug_suffix)%s %s" % (target_ext, target_link_flags), end=' ')
+ print("\t$(OBJS) \\")
+ print("\t$(LIBS) \\")
+ print("\t$(ADDN_LINK_FILES) \\")
+ print("\t$(pythonlib) $(lcustom) $(l_debug)\\")
+ print("\t$(resources)")
+ print()
+ print("clean:")
+ print("\t-rm -f *.obj")
+ print("\t-rm -f $(target).exe")
diff --git a/kolab-cli.py b/kolab-cli.py
index fbcfac5..37ea08e 100755
--- a/kolab-cli.py
+++ b/kolab-cli.py
@@ -18,6 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import logging
import os
import sys
@@ -30,9 +32,9 @@ from pykolab.cli import Cli
try:
import pykolab.logger
-except ImportError, e:
- print >> sys.stderr, _("Cannot load pykolab/logger.py:")
- print >> sys.stderr, "%s" % e
+except ImportError as e:
+ print(_("Cannot load pykolab/logger.py:"), file=sys.stderr)
+ print("%s" % e, file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
diff --git a/kolabd/__init__.py b/kolabd/__init__.py
index 491eaef..b15fccd 100644
--- a/kolabd/__init__.py
+++ b/kolabd/__init__.py
@@ -316,7 +316,7 @@ class KolabDaemon:
for domain in all_domains:
log.debug(_l("Checking for domain %s") % (domain), level=8)
- if domain in domain_auth.keys() and domain in primary_domains:
+ if domain in domain_auth and domain in primary_domains:
if not domain_auth[domain].is_alive():
log.debug(_l("Domain %s isn't alive anymore.") % (domain), level=8)
domain_auth[domain].terminate()
@@ -325,7 +325,7 @@ class KolabDaemon:
log.debug(_l("Domain %s already there and alive.") % (domain), level=8)
continue
- elif domain in domain_auth.keys():
+ elif domain in domain_auth:
log.debug(_l("Domain %s should not exist any longer.") % (domain), level=8)
removed_domains.append(domain)
else:
diff --git a/pykolab/__init__.py b/pykolab/__init__.py
index 09e3267..fdbc3a6 100644
--- a/pykolab/__init__.py
+++ b/pykolab/__init__.py
@@ -52,4 +52,5 @@ def getConf():
return conf
-import base
+from . import base
+
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 046c30c..2b3e56a 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -48,8 +48,8 @@ from pykolab.constants import SUPPORTED_LDAP_CONTROLS
from pykolab.errors import *
from pykolab.translate import _ as _l
-import auth_cache
-import cache
+from . import auth_cache
+from . import cache
# pylint: disable=invalid-name
log = pykolab.getLogger('pykolab.auth')
@@ -820,7 +820,7 @@ class LDAP(Base):
List alias domain name spaces for the current domain name space.
"""
if self.domains is not None:
- return [s for s in self.domains.keys() if s not in self.domains.values()]
+ return [s for s in self.domains if s not in self.domains.values()]
return []
@@ -923,7 +923,7 @@ class LDAP(Base):
attributes = self.get_entry_attributes(entry_dn, want_attrs)
- for attribute in attributes.keys():
+ for attribute in attributes:
entry[attribute] = attributes[attribute]
if 'preferredlanguage' not in entry:
@@ -1259,7 +1259,7 @@ class LDAP(Base):
attrs = {}
- for attribute in attributes.keys():
+ for attribute in attributes:
attrs[attribute.lower()] = attributes[attribute]
modlist = []
@@ -1723,13 +1723,18 @@ class LDAP(Base):
self.get_entry_attribute(entry, mailserver_attribute)
rcpt_addrs = self.recipient_policy(entry)
+
for key in rcpt_addrs:
entry[key] = rcpt_addrs[key]
if result_attribute not in entry:
+ entry[result_attribute] = self.get_entry_attribute(entry, result_attribute)
return
- if entry[result_attribute] is None:
+ if result_attribute not in entry:
+ return
+
+ if not entry[result_attribute]:
return
if entry[result_attribute] == '':
@@ -2283,7 +2288,7 @@ class LDAP(Base):
entry_changes[result_attribute]
)
- for key in entry_changes.keys():
+ for key in entry_changes:
entry[key] = entry_changes[key]
self.set_entry_attribute(entry, key, entry[key])
@@ -2780,7 +2785,7 @@ class LDAP(Base):
entry = {'dn': entry_dn}
entry_attrs = utils.normalize(entry_attrs)
- for attr in entry_attrs.keys():
+ for attr in entry_attrs:
entry[attr.lower()] = entry_attrs[attr]
# Ignore nstombstone objects
@@ -2806,7 +2811,7 @@ class LDAP(Base):
#
# log.debug(_l("Recipient Addresses: %r") % (rcpt_addrs), level=8)
#
-# for key in rcpt_addrs.keys():
+# for key in rcpt_addrs:
# entry[key] = rcpt_addrs[key]
#
# cache.get_entry(self.domain, entry)
@@ -3033,7 +3038,7 @@ class LDAP(Base):
):
import ldapurl
- import syncrepl
+ from . import syncrepl
ldap_url = ldapurl.LDAPUrl(self.config_get('ldap_uri'))
@@ -3135,7 +3140,7 @@ class LDAP(Base):
)
if len(self.ldap.supported_controls) < 1:
- for control_num in SUPPORTED_LDAP_CONTROLS.keys():
+ for control_num in SUPPORTED_LDAP_CONTROLS:
log.debug(
_l("Checking for support for %s on %s") % (
SUPPORTED_LDAP_CONTROLS[control_num]['desc'],
@@ -3152,7 +3157,7 @@ class LDAP(Base):
for (_result, _supported_controls) in _search:
supported_controls = _supported_controls.values()[0]
- for control_num in SUPPORTED_LDAP_CONTROLS.keys():
+ for control_num in SUPPORTED_LDAP_CONTROLS:
if SUPPORTED_LDAP_CONTROLS[control_num]['oid'] in \
supported_controls:
diff --git a/pykolab/auth/ldap/auth_cache.py b/pykolab/auth/ldap/auth_cache.py
index f32779c..41ef438 100644
--- a/pykolab/auth/ldap/auth_cache.py
+++ b/pykolab/auth/ldap/auth_cache.py
@@ -17,6 +17,7 @@
#
import datetime
+import os
import sqlalchemy
@@ -84,6 +85,11 @@ def del_entry(key):
db = init_db()
+ if db is None:
+ return
+
+ purge_entries()
+
try:
db.query(Entry).filter_by(key=key).delete()
except sqlalchemy.exc.OperationalError:
@@ -102,6 +108,9 @@ def get_entry(key):
db = init_db()
+ if db is None:
+ return None
+
try:
_entries = db.query(Entry).filter_by(key=key).all()
except sqlalchemy.exc.OperationalError:
@@ -111,18 +120,32 @@ def get_entry(key):
finally:
_entries = db.query(Entry).filter_by(key=key).all()
- if len(_entries) != 1:
+ __entries = []
+
+ for __entry in _entries:
+ if __entry.last_change <= datetime.datetime.now() - datetime.timedelta(0, 7200):
+ continue
+
+ __entries.append(__entry)
+
+ if len(__entries) != 1:
return None
- log.debug("Entry found: %r" % (_entries[0].__dict__))
- log.debug("Returning: %r" % (_entries[0].value))
+ log.debug("Entry found: %r" % (__entries[0].__dict__))
+ log.debug("Returning: %r" % (__entries[0].value))
- return _entries[0].value.encode('utf-8', 'latin1')
+ return __entries[0].value.encode('utf-8', 'latin1')
def set_entry(key, value):
+ # pylint: disable=global-statement
+ global db
+
db = init_db()
+ if db is None:
+ return
+
try:
_entries = db.query(Entry).filter_by(key=key).all()
except sqlalchemy.exc.OperationalError:
@@ -147,12 +170,18 @@ def set_entry(key, value):
db.commit()
-def purge_entries(db):
- db.query(Entry).filter(
- Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(1))
- ).delete()
+def purge_entries():
+ # pylint: disable=global-statement
+ global db
- db.commit()
+ try:
+ db.query(Entry).filter(
+ Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(0, 7200))
+ ).delete()
+
+ db.commit()
+ except Exception:
+ return
def init_db(reinit=False):
@@ -167,11 +196,13 @@ def init_db(reinit=False):
db_uri = conf.get('ldap', 'auth_cache_uri')
+ if db_uri == "null":
+ return None
+
if db_uri is None:
db_uri = 'sqlite:///%s/auth_cache.db' % (KOLAB_LIB_PATH)
if reinit:
- import os
if os.path.isfile('%s/auth_cache.db' % (KOLAB_LIB_PATH)):
os.unlink('%s/auth_cache.db' % (KOLAB_LIB_PATH))
@@ -181,6 +212,5 @@ def init_db(reinit=False):
Session = sessionmaker(bind=engine)
db = Session()
- purge_entries(db)
return db
diff --git a/pykolab/auth/ldap/syncrepl.py b/pykolab/auth/ldap/syncrepl.py
index 03ab5ae..98c2e11 100644
--- a/pykolab/auth/ldap/syncrepl.py
+++ b/pykolab/auth/ldap/syncrepl.py
@@ -1,6 +1,9 @@
#!/usr/bin/python
-import anydbm
+try:
+ import anydbm
+except:
+ import dbm.ndbm as anydbm
import ldap
import ldap.syncrepl
import ldapurl
@@ -17,12 +20,12 @@ class DNSync(ldap.ldapobject.LDAPObject,ldap.syncrepl.SyncreplConsumer):
callback = None
def __init__(self, filename, *args, **kwargs):
- if kwargs.has_key('callback'):
+ if 'callback' in kwargs:
self.callback = kwargs['callback']
del kwargs['callback']
ldap.ldapobject.LDAPObject.__init__(self, *args, **kwargs)
- self.__db = anydbm.open(filename, 'c', 0640)
+ self.__db = anydbm.open(filename, 'c', 0o640)
self.__presentUUIDs = {}
def syncrepl_set_cookie(self,cookie):
@@ -71,7 +74,7 @@ class DNSync(ldap.ldapobject.LDAPObject,ldap.syncrepl.SyncreplConsumer):
if uuids is None:
if refreshDeletes is False:
nonpresent = []
- for uuid in self.__db.keys():
+ for uuid in self.__db:
if uuid == 'cookie': continue
if uuid in self.__presentUUIDs: continue
nonpresent.append(uuid)
diff --git a/pykolab/cli/__init__.py b/pykolab/cli/__init__.py
index 4843aba..2b3c511 100644
--- a/pykolab/cli/__init__.py
+++ b/pykolab/cli/__init__.py
@@ -16,7 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
+try:
+ # Python 2: "reload" is built-in
+ reload
+except NameError:
+ from importlib import reload
import ldap
import ldif
import logging
@@ -42,7 +46,7 @@ conf = pykolab.getConf()
class Cli(object):
def __init__(self):
- import commands
+ from . import commands
commands.__init__()
to_execute = []
@@ -51,12 +55,12 @@ class Cli(object):
for arg in sys.argv[1:]:
arg_num += 1
if not arg.startswith('-') and len(sys.argv) >= arg_num:
- if commands.commands.has_key(sys.argv[arg_num].replace('-','_')):
+ if sys.argv[arg_num].replace('-','_') in commands.commands:
to_execute.append(sys.argv[arg_num].replace('-','_'))
- if commands.commands.has_key("%s_%s" % (
+ if "%s_%s" % (
'_'.join(to_execute),sys.argv[arg_num].replace('-','_')
- )):
+ ) in commands.commands:
to_execute.append(sys.argv[arg_num].replace('-','_'))
diff --git a/pykolab/cli/cmd_acl_cleanup.py b/pykolab/cli/cmd_acl_cleanup.py
index d2f8210..54cfd38 100644
--- a/pykolab/cli/cmd_acl_cleanup.py
+++ b/pykolab/cli/cmd_acl_cleanup.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -52,7 +52,7 @@ def execute(*args, **kw):
acls = imap.list_acls(folder)
if not aci_subject == None:
- if aci_subject in acls.keys():
+ if aci_subject in acls:
log.debug(_("Deleting ACL %s for subject %s on folder %s") % (
acls[aci_subject],
aci_subject,
@@ -62,7 +62,7 @@ def execute(*args, **kw):
imap.set_acl(folder, aci_subject, '')
#else:
- #for _aci_subject in acls.keys():
+ #for _aci_subject in acls:
# connect to auth(!)
# find recipient result_attr=aci_subject
- # if no entry, expire acl \ No newline at end of file
+ # if no entry, expire acl
diff --git a/pykolab/cli/cmd_add_alias.py b/pykolab/cli/cmd_add_alias.py
index 9f7a2c6..8f90032 100644
--- a/pykolab/cli/cmd_add_alias.py
+++ b/pykolab/cli/cmd_add_alias.py
@@ -17,9 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+from six import string_types
+
import sys
-import commands
+from . import commands
import pykolab
@@ -39,10 +42,10 @@ def execute(*args, **kw):
try:
secondary_rcpt_address = conf.cli_args.pop(0)
except:
- print >> sys.stderr, _("Specify the (new) alias address")
+ print(_("Specify the (new) alias address"), file=sys.stderr)
sys.exit(1)
except:
- print >> sys.stderr, _("Specify the existing recipient address")
+ print(_("Specify the existing recipient address"), file=sys.stderr)
sys.exit(1)
if len(primary_rcpt_address.split('@')) > 1:
@@ -62,29 +65,29 @@ def execute(*args, **kw):
secondary_rcpt_domain = conf.get('kolab', 'primary_domain')
# Check if either is in fact a domain
- if not primary_rcpt_domain.lower() in domains.keys():
- print >> sys.stderr, _("Domain %r is not a local domain") % (primary_rcpt_domain)
+ if not primary_rcpt_domain.lower() in domains:
+ print(_("Domain %r is not a local domain") % (primary_rcpt_domain), file=sys.stderr)
sys.exit(1)
- if not secondary_rcpt_domain.lower() in domains.keys():
- print >> sys.stderr, _("Domain %r is not a local domain") % (secondary_rcpt_domain)
+ if not secondary_rcpt_domain.lower() in domains:
+ print(_("Domain %r is not a local domain") % (secondary_rcpt_domain), file=sys.stderr)
sys.exit(1)
if not primary_rcpt_domain == secondary_rcpt_domain:
if not domains[primary_rcpt_domain] == domains[secondary_rcpt_domain]:
- print >> sys.stderr, _("Primary and secondary domain do not have the same parent domain")
+ print(_("Primary and secondary domain do not have the same parent domain"), file=sys.stderr)
sys.exit(1)
primary_recipient_dn = auth.find_recipient(primary_rcpt_address)
if primary_recipient_dn == [] or len(primary_recipient_dn) == 0:
- print >> sys.stderr, _("No such recipient %r") % (primary_rcpt_address)
+ print(_("No such recipient %r") % (primary_rcpt_address), file=sys.stderr)
sys.exit(1)
secondary_recipient_dn = auth.find_recipient(secondary_rcpt_address)
if not secondary_recipient_dn == [] and not len(secondary_recipient_dn) == 0:
- print >> sys.stderr, _("Recipient for alias %r already exists") % (secondary_rcpt_address)
+ print(_("Recipient for alias %r already exists") % (secondary_rcpt_address), file=sys.stderr)
sys.exit(1)
rcpt_attrs = conf.get_list('ldap', 'mail_attributes')
@@ -94,21 +97,21 @@ def execute(*args, **kw):
if len(rcpt_attrs) >= 2:
secondary_rcpt_attr = rcpt_attrs[1]
else:
- print >> sys.stderr, _("Environment is not configured for " + \
- "users to hold secondary mail attributes")
+ print(_("Environment is not configured for " + \
+ "users to hold secondary mail attributes"), file=sys.stderr)
sys.exit(1)
primary_recipient = auth.get_entry_attributes(primary_rcpt_domain, primary_recipient_dn, rcpt_attrs)
- if not primary_recipient.has_key(primary_rcpt_attr):
- print >> sys.stderr, _("Recipient %r is not the primary recipient for address %r") % (primary_recipient, primary_rcpt_address)
+ if primary_rcpt_attr not in primary_recipient:
+ print(_("Recipient %r is not the primary recipient for address %r") % (primary_recipient, primary_rcpt_address), file=sys.stderr)
sys.exit(1)
- if not primary_recipient.has_key(secondary_rcpt_attr):
+ if secondary_rcpt_attr not in primary_recipient:
auth.set_entry_attributes(primary_rcpt_domain, primary_recipient_dn, {secondary_rcpt_attr: [ secondary_rcpt_address ] })
else:
- if isinstance(primary_recipient[secondary_rcpt_attr], basestring):
+ if isinstance(primary_recipient[secondary_rcpt_attr], string_types):
new_secondary_rcpt_attrs = [
primary_recipient[secondary_rcpt_attr],
secondary_rcpt_address
diff --git a/pykolab/cli/cmd_add_domain.py b/pykolab/cli/cmd_add_domain.py
index a95373e..8034281 100644
--- a/pykolab/cli/cmd_add_domain.py
+++ b/pykolab/cli/cmd_add_domain.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
@@ -63,7 +63,7 @@ def execute(*args, **kw):
try:
domain = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
domain = utils.ask_question(_("Domain name"))
wap_client.domain_add(domain, conf.domains)
diff --git a/pykolab/cli/cmd_add_user.py b/pykolab/cli/cmd_add_user.py
index 09cc08c..b01b9ad 100644
--- a/pykolab/cli/cmd_add_user.py
+++ b/pykolab/cli/cmd_add_user.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_add_user_subscription.py b/pykolab/cli/cmd_add_user_subscription.py
index d8a8901..50ba9af 100644
--- a/pykolab/cli/cmd_add_user_subscription.py
+++ b/pykolab/cli/cmd_add_user_subscription.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -48,10 +50,10 @@ def execute(*args, **kw):
user = conf.cli_args.pop(0)
try:
folder_pattern = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
folder_pattern = utils.ask_question(_("Folder pattern"))
- except IndexError, errmsg:
+ except IndexError:
user = utils.ask_question(_("User ID"))
folder_pattern = utils.ask_question(_("Folder pattern"))
@@ -73,9 +75,9 @@ def execute(*args, **kw):
imap.login_plain(admin_login, admin_password, user)
if not imap.has_folder(folder_pattern):
- print >> sys.stderr, \
- _("Cannot subscribe user to folder %r:") % (folder_pattern), \
- _("No such folder")
+ print(_("Cannot subscribe user to folder %r:") % (folder_pattern), \
+ _("No such folder"), \
+ file=sys.stderr)
sys.exit(1)
_folders = imap.lm(folder_pattern)
diff --git a/pykolab/cli/cmd_check_quota.py b/pykolab/cli/cmd_check_quota.py
index ecbd66d..c102735 100644
--- a/pykolab/cli/cmd_check_quota.py
+++ b/pykolab/cli/cmd_check_quota.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -70,7 +72,7 @@ def execute(*args, **kw):
domains = auth.list_domains()
folders = []
- for domain in domains.keys():
+ for domain in domains:
folders = imap.lm("user/%%@%s" % (domain))
domain_auth = Auth(domain=domain)
@@ -81,7 +83,7 @@ def execute(*args, **kw):
user_dn = domain_auth.find_recipient(login)
if user_dn == None:
- print >> sys.stderr, _("No such user %s") % (login)
+ print(_("No such user %s") % (login), file=sys.stderr)
continue
if len(login.split('@')) > 1:
@@ -95,14 +97,14 @@ def execute(*args, **kw):
user_quota = None
if user_quota == None:
- print >> sys.stderr, _("No quota for user %s") % (login)
+ print(_("No quota for user %s") % (login), file=sys.stderr)
continue
try:
(used, quota) = imap.get_quota(folder)
if not (int)(quota) == (int)(user_quota):
- print >> sys.stderr, _("user quota does not match for %s (IMAP: %d, LDAP: %d)") % (login, (int)(quota), (int)(user_quota))
+ print(_("user quota does not match for %s (IMAP: %d, LDAP: %d)") % (login, (int)(quota), (int)(user_quota)), file=sys.stderr)
except:
pass
diff --git a/pykolab/cli/cmd_count_domain_mailboxes.py b/pykolab/cli/cmd_count_domain_mailboxes.py
index 958bccd..0559bcc 100644
--- a/pykolab/cli/cmd_count_domain_mailboxes.py
+++ b/pykolab/cli/cmd_count_domain_mailboxes.py
@@ -19,7 +19,7 @@
import datetime
-import commands
+from . import commands
import pykolab
@@ -56,11 +56,11 @@ def execute(*args, **kw):
domains = auth.list_domains()
folders = []
- for domain in domains.keys():
- print "%s: %d" % (domain,len(imap.lm("user/%%@%s" % (domain))))
+ for domain in domains:
+ print("%s: %d" % (domain,len(imap.lm("user/%%@%s" % (domain)))))
null_realm = len(imap.lm("user/%%"))
if null_realm > 0:
- print "null: %d" % (null_realm)
+ print("null: %d" % (null_realm))
diff --git a/pykolab/cli/cmd_create_mailbox.py b/pykolab/cli/cmd_create_mailbox.py
index 385cbd1..4da5c47 100644
--- a/pykolab/cli/cmd_create_mailbox.py
+++ b/pykolab/cli/cmd_create_mailbox.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
@@ -56,7 +56,7 @@ def description():
def execute(*args, **kw):
try:
mailbox = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
log.error(_("Invalid argument"))
sys.exit(1)
diff --git a/pykolab/cli/cmd_delete_domain.py b/pykolab/cli/cmd_delete_domain.py
index 94418c1..28bbcaf 100644
--- a/pykolab/cli/cmd_delete_domain.py
+++ b/pykolab/cli/cmd_delete_domain.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
@@ -63,7 +63,7 @@ def execute(*args, **kw):
try:
domain = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
domain = utils.ask_question(_("Domain name"))
if wap_client.domain_delete(domain, conf.force):
diff --git a/pykolab/cli/cmd_delete_mailbox.py b/pykolab/cli/cmd_delete_mailbox.py
index 9a7e1b1..66ec534 100644
--- a/pykolab/cli/cmd_delete_mailbox.py
+++ b/pykolab/cli/cmd_delete_mailbox.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -41,7 +43,7 @@ def execute(*args, **kw):
"""
if len(conf.cli_args) < 1:
- print >> sys.stderr, _("No mailbox specified")
+ print(_("No mailbox specified"), file=sys.stderr)
sys.exit(1)
imap = IMAP()
@@ -54,17 +56,17 @@ def execute(*args, **kw):
folders = imap.list_folders(folder)
if len(folders) < 1:
- print >> sys.stderr, _("No such folder(s): %s") % (folder)
+ print(_("No such folder(s): %s") % (folder), file=sys.stderr)
delete_folders.extend(folders)
if len(delete_folders) == 0:
- print >> sys.stderr, _("No folders to delete.")
+ print(_("No folders to delete."), file=sys.stderr)
sys.exit(1)
for delete_folder in delete_folders:
try:
imap.delete_mailfolder(delete_folder)
- except Exception, errmsg:
+ except Exception:
log.error(_("Could not delete mailbox '%s'") % (delete_folder))
diff --git a/pykolab/cli/cmd_delete_mailbox_acl.py b/pykolab/cli/cmd_delete_mailbox_acl.py
index b7a7ede..c15f85b 100644
--- a/pykolab/cli/cmd_delete_mailbox_acl.py
+++ b/pykolab/cli/cmd_delete_mailbox_acl.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -41,10 +43,10 @@ def execute(*args, **kw):
folder = conf.cli_args.pop(0)
try:
identifier = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
identifier = utils.ask_question(_("ACI Subject"))
- except IndexError, errmsg:
+ except IndexError:
folder = utils.ask_question(_("Folder name"))
quota = utils.ask_question(_("ACI Subject"))
@@ -57,7 +59,7 @@ def execute(*args, **kw):
imap.connect(domain=domain)
if not imap.has_folder(folder):
- print >> sys.stderr, _("No such folder %r") % (folder)
+ print(_("No such folder %r") % (folder), file=sys.stderr)
else:
folders = imap.list_folders(folder)
diff --git a/pykolab/cli/cmd_delete_message.py b/pykolab/cli/cmd_delete_message.py
index 5c7c242..5f68ee8 100644
--- a/pykolab/cli/cmd_delete_message.py
+++ b/pykolab/cli/cmd_delete_message.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_export_mailbox.py b/pykolab/cli/cmd_export_mailbox.py
index 37a862c..f37c7b2 100644
--- a/pykolab/cli/cmd_export_mailbox.py
+++ b/pykolab/cli/cmd_export_mailbox.py
@@ -17,7 +17,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from __future__ import print_function
+
+from . import commands
import pykolab
@@ -115,8 +117,8 @@ def execute(*args, **kw):
stdout=subprocess.PIPE
).communicate()[0]
- print >> sys.stderr, _("ZIP file at %s.zip") % (user)
+ print(_("ZIP file at %s.zip") % (user), file=sys.stderr)
else:
- print >> sys.stderr, _("No directories found for user %s") % (user)
+ print(_("No directories found for user %s") % (user), file=sys.stderr)
sys.exit(1)
diff --git a/pykolab/cli/cmd_find_domain.py b/pykolab/cli/cmd_find_domain.py
index a573634..64dc2de 100644
--- a/pykolab/cli/cmd_find_domain.py
+++ b/pykolab/cli/cmd_find_domain.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
@@ -52,7 +52,7 @@ def execute(*args, **kw):
try:
domain = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
domain = utils.ask_question(_("Domain name"))
wap_client.domain_find(domain)
diff --git a/pykolab/cli/cmd_list_deleted_mailboxes.py b/pykolab/cli/cmd_list_deleted_mailboxes.py
index 6d07816..6596142 100644
--- a/pykolab/cli/cmd_list_deleted_mailboxes.py
+++ b/pykolab/cli/cmd_list_deleted_mailboxes.py
@@ -19,7 +19,7 @@
import datetime
-import commands
+from . import commands
import pykolab
@@ -101,7 +101,7 @@ def execute(*args, **kw):
log.debug(_("Appending folder search for %r") % (search), level=8)
folders.extend(imap.lm(imap_utf7.encode(search)))
- print "Deleted folders:"
+ print("Deleted folders:")
for folder in folders:
utf8_folder = imap_utf7.decode(folder).encode('utf-8')
@@ -109,6 +109,6 @@ def execute(*args, **kw):
ts = datetime.datetime.fromtimestamp(int(mbox_parts['hex_timestamp'], 16))
if not conf.raw:
- print "%s (Deleted at %s)" % (utf8_folder, ts)
+ print("%s (Deleted at %s)" % (utf8_folder, ts))
else:
- print "%s (Deleted at %s)" % (folder, ts)
+ print("%s (Deleted at %s)" % (folder, ts))
diff --git a/pykolab/cli/cmd_list_domain_mailboxes.py b/pykolab/cli/cmd_list_domain_mailboxes.py
index d4c8bfe..602fc5d 100644
--- a/pykolab/cli/cmd_list_domain_mailboxes.py
+++ b/pykolab/cli/cmd_list_domain_mailboxes.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -75,10 +75,10 @@ def execute(*args, **kw):
for secondary in secondaries:
folders.extend(imap.lm("user/%%@%s" % (secondary)))
- print "Deleted folders:"
+ print("Deleted folders:")
for folder in folders:
if not conf.raw:
- print imap_utf7.decode(folder)
+ print(imap_utf7.decode(folder))
else:
- print folder
+ print(folder)
diff --git a/pykolab/cli/cmd_list_domains.py b/pykolab/cli/cmd_list_domains.py
index 3ee4d20..d72ed71 100644
--- a/pykolab/cli/cmd_list_domains.py
+++ b/pykolab/cli/cmd_list_domains.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -38,15 +38,15 @@ def execute(*args, **kw):
dna = conf.get('ldap', 'domain_name_attribute')
- print "%-39s %-40s" % ("Primary Domain Name Space","Secondary Domain Name Space(s)")
+ print("%-39s %-40s" % ("Primary Domain Name Space","Secondary Domain Name Space(s)"))
# TODO: Take a hint in --quiet, and otherwise print out a nice table
# with headers and such.
if isinstance(domains['list'], dict):
- for domain_dn in domains['list'].keys():
+ for domain_dn in domains['list']:
if isinstance(domains['list'][domain_dn][dna], list):
- print domains['list'][domain_dn][dna][0]
+ print(domains['list'][domain_dn][dna][0])
for domain_alias in domains['list'][domain_dn][dna][1:]:
- print "%-39s %-40s" % ('', domain_alias)
+ print("%-39s %-40s" % ('', domain_alias))
else:
- print domains['list'][domain_dn][dna]
+ print(domains['list'][domain_dn][dna])
diff --git a/pykolab/cli/cmd_list_mailbox_acls.py b/pykolab/cli/cmd_list_mailbox_acls.py
index c9e47ac..d4f76d5 100644
--- a/pykolab/cli/cmd_list_mailbox_acls.py
+++ b/pykolab/cli/cmd_list_mailbox_acls.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -39,7 +41,7 @@ def description():
def execute(*args, **kw):
try:
folder = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
folder = utils.ask_question(_("Folder name"))
if len(folder.split('@')) > 1:
@@ -51,15 +53,15 @@ def execute(*args, **kw):
imap.connect(domain=domain)
if not imap.has_folder(folder):
- print >> sys.stderr, _("No such folder %r") % (folder)
+ print(_("No such folder %r") % (folder), file=sys.stderr)
else:
acls = []
folders = imap.list_folders(folder)
for folder in folders:
- print "Folder", folder
+ print("Folder", folder)
acls = imap.list_acls(folder)
- for acl in acls.keys():
- print " %-13s %s" %(acls[acl], acl)
+ for acl in acls:
+ print(" %-13s %s" %(acls[acl], acl))
diff --git a/pykolab/cli/cmd_list_mailbox_metadata.py b/pykolab/cli/cmd_list_mailbox_metadata.py
index 223482b..7734770 100644
--- a/pykolab/cli/cmd_list_mailbox_metadata.py
+++ b/pykolab/cli/cmd_list_mailbox_metadata.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -50,7 +52,7 @@ def description():
def execute(*args, **kw):
try:
folder = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
folder = utils.ask_question(_("Folder name"))
if len(folder.split('@')) > 1:
@@ -77,19 +79,19 @@ def execute(*args, **kw):
imap.connect(domain=domain)
if not imap.has_folder(folder):
- print >> sys.stderr, _("No such folder %r") % (folder)
+ print(_("No such folder %r") % (folder), file=sys.stderr)
else:
metadata = []
folders = imap.list_folders(folder)
for folder in folders:
- print "Folder", folder
+ print("Folder", folder)
metadata = imap.get_metadata(folder)
- if metadata.has_key(folder):
- for annotation in metadata[folder].keys():
- print " %-49s %s" % (
+ if folder in metadata:
+ for annotation in metadata[folder]:
+ print(" %-49s %s" % (
annotation,
metadata[folder][annotation]
- )
+ ))
diff --git a/pykolab/cli/cmd_list_mailboxes.py b/pykolab/cli/cmd_list_mailboxes.py
index 3b3bbd8..3cb7f03 100644
--- a/pykolab/cli/cmd_list_mailboxes.py
+++ b/pykolab/cli/cmd_list_mailboxes.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -98,6 +98,6 @@ def execute(*args, **kw):
for folder in folders:
if not conf.raw:
- print imap_utf7.decode(folder)
+ print(imap_utf7.decode(folder))
else:
- print folder
+ print(folder)
diff --git a/pykolab/cli/cmd_list_messages.py b/pykolab/cli/cmd_list_messages.py
index db59a48..af2c447 100644
--- a/pykolab/cli/cmd_list_messages.py
+++ b/pykolab/cli/cmd_list_messages.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
@@ -118,17 +118,17 @@ def execute(*args, **kw):
if len(flags) >= 3:
# Any flags are set
if flags[2] == '(\\Deleted))':
- print num, '\Deleted'
+ print(num, '\Deleted')
elif flags[2] == '(\\Deleted':
- print num, '\Deleted'
+ print(num, '\Deleted')
elif '\\Deleted' in flags[3:]:
- print num, '\Deleted'
+ print(num, '\Deleted')
elif '\\Deleted))' in flags[3:]:
- print num, '\Deleted'
+ print(num, '\Deleted')
else:
- print num
+ print(num)
else:
- print num
+ print(num)
if conf.user == None:
imap.set_acl(folder, 'cyrus-admin', '')
diff --git a/pykolab/cli/cmd_list_ous.py b/pykolab/cli/cmd_list_ous.py
index 670b609..46b991f 100644
--- a/pykolab/cli/cmd_list_ous.py
+++ b/pykolab/cli/cmd_list_ous.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -36,4 +36,4 @@ def execute(*args, **kw):
wap_client.authenticate(username=conf.get("ldap", "bind_dn"), password=conf.get("ldap", "bind_pw"))
ous = wap_client.ous_list()
- print '\n'.join(ous['list'].keys())
+ print('\n'.join(ous['list'].keys()))
diff --git a/pykolab/cli/cmd_list_quota.py b/pykolab/cli/cmd_list_quota.py
index f66f580..7dd6b9d 100644
--- a/pykolab/cli/cmd_list_quota.py
+++ b/pykolab/cli/cmd_list_quota.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -51,7 +53,7 @@ def execute(*args, **kw):
try:
quota_folder = conf.cli_args.pop(0)
- except IndexError, e:
+ except IndexError:
quota_folder = '*'
imap = IMAP()
@@ -67,36 +69,36 @@ def execute(*args, **kw):
for quota_folder in quota_folders:
try:
(used, quota) = imap.get_quota(quota_folder)
- print "Folder: %s" % (quota_folder)
+ print("Folder: %s" % (quota_folder))
if not used == None and not quota == None:
if quota == 0:
- print >> sys.stderr, _("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder)
- print "%d (Used: %d, Percentage: %s)" % (quota, used, u'\u221E')
+ print(_("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder), file=sys.stderr)
+ print("%d (Used: %d, Percentage: %s)" % (quota, used, u'\u221E'))
else:
percentage = round(((float)(used)/(float)(quota)) * 100.0, 1)
- print "%d (Used: %d, Percentage: %d)" % (quota, used, percentage)
+ print("%d (Used: %d, Percentage: %d)" % (quota, used, percentage))
else:
if used == None:
- print "%d (Used: %d, Percentage: %d)" % (quota, 0, 0)
+ print("%d (Used: %d, Percentage: %d)" % (quota, 0, 0))
else:
- print "No quota"
+ print("No quota")
except:
try:
(quota_root, used, quota) = imap.get_quota_root(quota_folder)
- print "Folder: %s" % (quota_folder)
+ print("Folder: %s" % (quota_folder))
if not quota_root == None and not used == None and not quota == None:
if quota == 0:
- print >> sys.stderr, _("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder)
- print "%d (Used: %d, Percentage: %d)" % (quota, used, u'\u221E')
+ print(_("The quota for folder %s is set to literally allow 0KB of storage.") % (quota_folder), file=sys.stderr)
+ print("%d (Used: %d, Percentage: %d)" % (quota, used, u'\u221E'))
else:
percentage = round(((float)(used)/(float)(quota)) * 100.0, 1)
- print "%d (Root: %s, Used: %d, Percentage: %d)" % (quota, quota_root, used, percentage)
+ print("%d (Root: %s, Used: %d, Percentage: %d)" % (quota, quota_root, used, percentage))
else:
if used == None and not quota_root == None:
- print "%d (Root: %s, Used: %d, Percentage: %d)" % (quota, quota_root, 0, 0)
+ print("%d (Root: %s, Used: %d, Percentage: %d)" % (quota, quota_root, 0, 0))
else:
- print "No quota"
+ print("No quota")
except:
- print "Folder: %s" % (quota_folder)
- print "No quota root"
+ print("Folder: %s" % (quota_folder))
+ print("No quota root")
diff --git a/pykolab/cli/cmd_list_user_subscriptions.py b/pykolab/cli/cmd_list_user_subscriptions.py
index 9095604..3d90812 100644
--- a/pykolab/cli/cmd_list_user_subscriptions.py
+++ b/pykolab/cli/cmd_list_user_subscriptions.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -56,10 +56,10 @@ def execute(*args, **kw):
user = conf.cli_args.pop(0)
try:
folder_pattern = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
pass
- except IndexError, errmsg:
+ except IndexError:
user = utils.ask_question(_("User ID"))
if len(user.split('@')) > 1:
@@ -91,14 +91,14 @@ def execute(*args, **kw):
if len(unsubscribed_folders) > 0:
if not conf.raw:
- print "\n".join([imap_utf7.decode(x) for x in unsubscribed_folders])
+ print("\n".join([imap_utf7.decode(x) for x in unsubscribed_folders]))
else:
- print "\n".join(unsubscribed_folders)
+ print("\n".join(unsubscribed_folders))
else:
- print _("No unsubscribed folders for user %s") % (user)
+ print(_("No unsubscribed folders for user %s") % (user))
else:
if not conf.raw:
- print "\n".join([imap_utf7.decode(x) for x in subscribed_folders])
+ print("\n".join([imap_utf7.decode(x) for x in subscribed_folders]))
else:
- print "\n".join(subscribed_folders)
+ print("\n".join(subscribed_folders))
diff --git a/pykolab/cli/cmd_list_users.py b/pykolab/cli/cmd_list_users.py
index ff1ddef..bb5506e 100644
--- a/pykolab/cli/cmd_list_users.py
+++ b/pykolab/cli/cmd_list_users.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -36,4 +36,4 @@ def execute(*args, **kw):
wap_client.authenticate(username=conf.get("ldap", "bind_dn"), password=conf.get("ldap", "bind_pw"))
users = wap_client.users_list()
- print '\n'.join(users['list'].keys())
+ print('\n'.join(users['list'].keys()))
diff --git a/pykolab/cli/cmd_mailbox_cleanup.py b/pykolab/cli/cmd_mailbox_cleanup.py
index ee12c1e..ccc964d 100644
--- a/pykolab/cli/cmd_mailbox_cleanup.py
+++ b/pykolab/cli/cmd_mailbox_cleanup.py
@@ -17,10 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import ldap
-import sys
-
-import commands
+from . import commands
import pykolab
@@ -32,33 +29,46 @@ from pykolab.translate import _
log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
+
def __init__():
commands.register('mailbox_cleanup', execute, description=description())
+
def cli_options():
my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
my_option_group.add_option(
'--dry-run',
- dest = "dryrun",
- action = "store_true",
- default = False,
- help = _(
+ dest="dryrun",
+ action="store_true",
+ default=False,
+ help=_(
"Do not actually delete mailboxes, but report what mailboxes would have been deleted."
)
)
my_option_group.add_option(
'--server',
- dest = "connect_server",
- action = "store",
- default = None,
- metavar = "SERVER",
- help = _("Evaluate mailboxes on server SERVER only.")
+ dest="connect_server",
+ action="store",
+ default=None,
+ metavar="SERVER",
+ help=_("Evaluate mailboxes on server SERVER only.")
+ )
+
+ my_option_group.add_option(
+ '--with-acls',
+ dest="with_acls",
+ action="store",
+ default=False,
+ help=_("Evaluate ACLs on mailboxes as well.")
)
+
def description():
return _("Clean up mailboxes that do no longer have an owner.")
+
+# pylint: disable=too-many-branches,too-many-locals,too-many-statements
def execute(*args, **kw):
"""
List mailboxes
@@ -69,7 +79,7 @@ def execute(*args, **kw):
imap = IMAP()
- if not conf.connect_server == None:
+ if conf.connect_server is not None:
imap.connect(server=conf.connect_server)
else:
imap.connect()
@@ -80,20 +90,21 @@ def execute(*args, **kw):
# Placeholder for subjects that would have already been deleted
subjects_deleted = []
- for domain in domains.keys():
+ for domain in domains:
domain_folders[domain] = imap.lm("user/%%@%s" % (domain))
- for domain in domain_folders.keys():
+ for domain in domain_folders:
auth = Auth(domain=domain)
auth.connect(domain)
for folder in domain_folders[domain]:
- user = folder.replace('user/','')
+ user = folder.replace('user/', '')
try:
recipient = auth.find_recipient(user)
- except ldap.NO_SUCH_OBJECT, errmsg:
- if not user in subjects_deleted and conf.dryrun:
+ # pylint: disable=bare-except
+ except:
+ if user not in subjects_deleted and conf.dryrun:
subjects_deleted.append(user)
if conf.dryrun:
@@ -103,7 +114,7 @@ def execute(*args, **kw):
continue
if len(recipient) == 0 or recipient == []:
- if not user in subjects_deleted and conf.dryrun:
+ if user not in subjects_deleted and conf.dryrun:
subjects_deleted.append(user)
if conf.dryrun:
@@ -112,23 +123,30 @@ def execute(*args, **kw):
log.info(_("Deleting folder 'user/%s'") % (user))
try:
imap.dm(folder)
+ # pylint: disable=bare-except
except:
log.error(_("Error deleting folder 'user/%s'") % (user))
else:
log.debug(_("Valid recipient found for 'user/%s'") % (user), level=6)
- if not user in subjects:
+ if user not in subjects:
subjects.append(user)
imap_domains = []
folders = imap.lm()
+
for folder in folders:
- namespace = folder.split('/')[0]
+ components = folder.split('/')
+
+ if len(components) < 2:
+ log.error("Not enough components for folder %s" % (folder))
+ continue
+
mailbox = folder.split('/')[1]
if len(mailbox.split('@')) > 1:
domain = mailbox.split('@')[1]
- if not domain in domains.keys() and not domain in imap_domains:
+ if domain not in domains and domain not in imap_domains:
imap_domains.append(domain)
for domain in imap_domains:
@@ -136,7 +154,7 @@ def execute(*args, **kw):
user = folder.replace('user/', '')
- if not user in subjects_deleted and conf.dryrun:
+ if user not in subjects_deleted and conf.dryrun:
subjects_deleted.append(user)
if conf.dryrun:
@@ -145,6 +163,7 @@ def execute(*args, **kw):
log.info(_("Deleting folder '%s'") % (folder))
try:
imap.dm(folder)
+ # pylint: disable=bare-except
except:
log.error(_("Error deleting folder '%s'") % (folder))
@@ -155,51 +174,55 @@ def execute(*args, **kw):
log.info(_("Deleting folder '%s'") % (folder))
try:
imap.dm(folder)
+ # pylint: disable=bare-except
except:
log.error(_("Error deleting folder '%s'") % (folder))
+ if not conf.with_acls:
+ return
+
for folder in [x for x in imap.lm() if not x.startswith('DELETED/')]:
folder = imap_utf7.decode(folder)
acls = imap.list_acls(folder)
- for subject in acls.keys():
+ for subject in acls:
if subject == 'anyone':
log.info(
- _("Skipping removal of ACL %s for subject %s on folder %s") % (
- acls[subject],
- subject,
- folder
- )
+ _("Skipping removal of ACL %s for subject %s on folder %s") % (
+ acls[subject],
+ subject,
+ folder
)
+ )
continue
- if not subject in subjects and not subject in subjects_deleted:
+ if subject not in subjects and subject not in subjects_deleted:
if conf.dryrun:
log.info(
- _("Would have deleted ACL %s for subject %s on folder %s") % (
- acls[subject],
- subject,
- folder
- )
+ _("Would have deleted ACL %s for subject %s on folder %s") % (
+ acls[subject],
+ subject,
+ folder
)
+ )
else:
log.info(
- _("Deleting ACL %s for subject %s on folder %s") % (
- acls[subject],
- subject,
- folder
- )
+ _("Deleting ACL %s for subject %s on folder %s") % (
+ acls[subject],
+ subject,
+ folder
)
+ )
try:
- imap.set_acl(folder, aci_subject, '')
+ imap.set_acl(folder, subject, '')
+ # pylint: disable=bare-except
except:
log.error(
- _("Error removing ACL %s for subject %s from folder %s") % (
- acls[subject],
- subject,
- folder
- )
+ _("Error removing ACL %s for subject %s from folder %s") % (
+ acls[subject],
+ subject,
+ folder
)
-
+ )
diff --git a/pykolab/cli/cmd_remove_mailaddress.py b/pykolab/cli/cmd_remove_mailaddress.py
index af64609..cfc4f89 100644
--- a/pykolab/cli/cmd_remove_mailaddress.py
+++ b/pykolab/cli/cmd_remove_mailaddress.py
@@ -17,9 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+from six import string_types
+
import sys
-import commands
+from . import commands
import pykolab
@@ -39,7 +42,7 @@ def description():
def execute(*args, **kw):
try:
email_address = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
email_address = utils.ask_question("Email address to remove")
# Get the domain from the email address
@@ -65,14 +68,14 @@ def execute(*args, **kw):
log.debug(_("Using the following mail attributes: %r") % (mail_attributes), level=8)
- if isinstance(recipients, basestring):
+ if isinstance(recipients, string_types):
recipient = recipients
# Only a single recipient found, remove the address
attributes = auth.get_entry_attributes(domain, recipient, mail_attributes)
# See which attribute holds the value we're trying to remove
- for attribute in attributes.keys():
+ for attribute in attributes:
if isinstance(attributes[attribute], list):
if email_address in attributes[attribute]:
attributes[attribute].pop(attributes[attribute].index(email_address))
@@ -87,7 +90,7 @@ def execute(*args, **kw):
pass
else:
- print >> sys.stderr, _("Found the following recipients:")
+ print(_("Found the following recipients:"), file=sys.stderr)
for recipient in recipients:
- print recipient
+ print(recipient)
diff --git a/pykolab/cli/cmd_remove_user_subscription.py b/pykolab/cli/cmd_remove_user_subscription.py
index 59975c8..208ff4a 100644
--- a/pykolab/cli/cmd_remove_user_subscription.py
+++ b/pykolab/cli/cmd_remove_user_subscription.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -48,10 +50,10 @@ def execute(*args, **kw):
user = conf.cli_args.pop(0)
try:
folder_pattern = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
folder_pattern = utils.ask_question(_("Folder pattern"))
- except IndexError, errmsg:
+ except IndexError:
user = utils.ask_question(_("User ID"))
folder_pattern = utils.ask_question(_("Folder pattern"))
@@ -73,9 +75,9 @@ def execute(*args, **kw):
imap.login_plain(admin_login, admin_password, user)
if not imap.has_folder(folder_pattern):
- print >> sys.stderr, \
- _("Cannot subscribe user to folder %r:") % (folder_pattern), \
- _("No such folder")
+ print(_("Cannot subscribe user to folder %r:") % (folder_pattern), \
+ _("No such folder"), \
+ file=sys.stderr)
sys.exit(1)
_folders = imap.lm(folder_pattern)
@@ -88,14 +90,14 @@ def execute(*args, **kw):
unsubscribed_folders.append(_folder)
if len(unsubscribed_folders) > 0:
- print _("Successfully unsubscribed user %s from the following folders:") % (
+ print(_("Successfully unsubscribed user %s from the following folders:") % (
user
- )
+ ))
- print "\n".join(unsubscribed_folders)
+ print("\n".join(unsubscribed_folders))
else:
- print >> sys.stderr, _("User %s was not unsubscribed from any folders.") % (
+ print(_("User %s was not unsubscribed from any folders.") % (
user
- )
+ ), file=sys.stderr)
sys.exit(1)
diff --git a/pykolab/cli/cmd_rename_mailbox.py b/pykolab/cli/cmd_rename_mailbox.py
index 7432e08..b46c79d 100644
--- a/pykolab/cli/cmd_rename_mailbox.py
+++ b/pykolab/cli/cmd_rename_mailbox.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -46,12 +48,12 @@ def execute(*args, **kw):
target_folder = conf.cli_args.pop(0)
try:
partition = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
partition = None
- except IndexError, errmsg:
- print >> sys.stderr, _("No target mailbox name specified")
- except IndexError, errmsg:
- print >> sys.stderr, _("No source mailbox name specified")
+ except IndexError:
+ print(_("No target mailbox name specified"), file=sys.stderr)
+ except IndexError:
+ print(_("No source mailbox name specified"), file=sys.stderr)
sys.exit(1)
if len(source_folder.split('@')) > 1:
@@ -63,11 +65,11 @@ def execute(*args, **kw):
imap.connect(domain=domain)
if not imap.has_folder(source_folder):
- print >> sys.stderr, _("Source folder %r does not exist") % (source_folder)
+ print(_("Source folder %r does not exist") % (source_folder), file=sys.stderr)
sys.exit(1)
if imap.has_folder(target_folder) and partition == None:
- print >> sys.stderr, _("Target folder %r already exists") % (target_folder)
+ print(_("Target folder %r already exists") % (target_folder), file=sys.stderr)
sys.exit(1)
imap.imap.rename(imap.folder_utf7(source_folder), imap.folder_utf7(target_folder), partition)
diff --git a/pykolab/cli/cmd_server_info.py b/pykolab/cli/cmd_server_info.py
index e512fcc..f0f867a 100644
--- a/pykolab/cli/cmd_server_info.py
+++ b/pykolab/cli/cmd_server_info.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -55,4 +55,4 @@ def execute(*args, **kw):
else:
imap.connect()
- print imap.get_metadata("")
+ print(imap.get_metadata(""))
diff --git a/pykolab/cli/cmd_set_language.py b/pykolab/cli/cmd_set_language.py
index 83b5d95..df575c5 100644
--- a/pykolab/cli/cmd_set_language.py
+++ b/pykolab/cli/cmd_set_language.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_set_mail.py b/pykolab/cli/cmd_set_mail.py
index 0b457cb..97512fd 100644
--- a/pykolab/cli/cmd_set_mail.py
+++ b/pykolab/cli/cmd_set_mail.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_set_mailbox_acl.py b/pykolab/cli/cmd_set_mailbox_acl.py
index 379a8c3..a18c48b 100644
--- a/pykolab/cli/cmd_set_mailbox_acl.py
+++ b/pykolab/cli/cmd_set_mailbox_acl.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -43,14 +45,14 @@ def execute(*args, **kw):
identifier = conf.cli_args.pop(0)
try:
acl = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
acl = utils.ask_question(_("ACI Permissions"))
- except IndexError, errmsg:
+ except IndexError:
identifier = utils.ask_question(_("ACI Subject"))
acl = utils.ask_question(_("ACI Permissions"))
- except IndexError, errmsg:
+ except IndexError:
folder = utils.ask_question(_("Folder name"))
identifier = utils.ask_question(_("ACI Subject"))
acl = utils.ask_question(_("ACI Permissions"))
@@ -64,7 +66,7 @@ def execute(*args, **kw):
imap.connect(domain=domain)
if not imap.has_folder(folder):
- print >> sys.stderr, _("No such folder %r") % (folder)
+ print(_("No such folder %r") % (folder), file=sys.stderr)
else:
folders = imap.list_folders(folder)
diff --git a/pykolab/cli/cmd_set_mailbox_metadata.py b/pykolab/cli/cmd_set_mailbox_metadata.py
index 0b7b1fe..339b664 100644
--- a/pykolab/cli/cmd_set_mailbox_metadata.py
+++ b/pykolab/cli/cmd_set_mailbox_metadata.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -55,14 +57,14 @@ def execute(*args, **kw):
metadata_path = conf.cli_args.pop(0)
try:
metadata_value = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
metadata_value = utils.ask_question(_("Metadata value"))
- except IndexError, errmsg:
+ except IndexError:
metadata_path = utils.ask_question(_("Metadata path"))
metadata_value = utils.ask_question(_("Metadata value"))
- except IndexError, errmsg:
+ except IndexError:
folder = utils.ask_question(_("Folder name"))
metadata_path = utils.ask_question(_("Metadata path"))
metadata_value = utils.ask_question(_("Metadata value"))
@@ -91,7 +93,7 @@ def execute(*args, **kw):
imap.connect(domain=domain)
if not imap.has_folder(folder):
- print >> sys.stderr, _("No such folder %r") % (folder)
+ print(_("No such folder %r") % (folder), file=sys.stderr)
else:
folders = imap.lm(imap_utf7.encode(folder))
diff --git a/pykolab/cli/cmd_set_quota.py b/pykolab/cli/cmd_set_quota.py
index 2fa9ba3..3692f10 100644
--- a/pykolab/cli/cmd_set_quota.py
+++ b/pykolab/cli/cmd_set_quota.py
@@ -17,9 +17,11 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -41,10 +43,10 @@ def execute(*args, **kw):
folder = conf.cli_args.pop(0)
try:
quota = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
quota = utils.ask_question(_("New quota"))
- except IndexError, errmsg:
+ except IndexError:
folder = utils.ask_question(_("Folder name"))
quota = utils.ask_question(_("New quota"))
@@ -57,10 +59,10 @@ def execute(*args, **kw):
imap.connect(domain=domain)
if not imap.has_folder(folder):
- print >> sys.stderr, _("No such folder %r") % (folder)
+ print(_("No such folder %r") % (folder), file=sys.stderr)
sys.exit(1)
for _folder in imap.lm(imap.folder_utf7(folder)):
imap.set_quota(_folder, quota)
- print >> sys.stdout, "Quota for folder '%s' set to %d" % (_folder, int(quota))
+ print("Quota for folder '%s' set to %d" % (_folder, int(quota)), file=sys.stdout)
diff --git a/pykolab/cli/cmd_sync.py b/pykolab/cli/cmd_sync.py
index 7d44d02..85952cb 100644
--- a/pykolab/cli/cmd_sync.py
+++ b/pykolab/cli/cmd_sync.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
from distutils import version
import multiprocessing
@@ -139,7 +139,7 @@ def _synchronize(*args, **kw):
imap.connect()
if not imap.user_mailbox_exists(entry[mailbox_attribute]):
- if entry.has_key('mailhost'):
+ if 'mailhost' in entry:
server = entry['mailhost']
else:
server = None
diff --git a/pykolab/cli/cmd_sync_mailhost_attrs.py b/pykolab/cli/cmd_sync_mailhost_attrs.py
index 3f5a731..a3e200f 100644
--- a/pykolab/cli/cmd_sync_mailhost_attrs.py
+++ b/pykolab/cli/cmd_sync_mailhost_attrs.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
@@ -113,7 +113,7 @@ def execute(*args, **kw):
log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
try:
imap.dm(folder)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("An error occurred removing mailbox %r: %r") % (folder, errmsg))
else:
log.info(_("Not automatically deleting shared folder '%s'") % (folder))
@@ -121,7 +121,7 @@ def execute(*args, **kw):
log.warning(_("No recipients for '%s' (use --delete to delete)!") % (r_folder))
for primary in list(set(domains.values())):
- secondaries = [x for x in domains.keys() if domains[x] == primary]
+ secondaries = [x for x in domains if domains[x] == primary]
folders = []
@@ -161,7 +161,7 @@ def execute(*args, **kw):
log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
try:
imap.dm(folder)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("An error occurred removing mailbox %r: %r") % (folder, errmsg))
else:
log.info(_("Not automatically deleting shared folder '%s'") % (folder))
@@ -174,7 +174,7 @@ def execute(*args, **kw):
if not server == mailhost:
if conf.dry_run:
- print folder, server, mailhost
+ print(folder, server, mailhost)
else:
auth.set_entry_attribute(primary, recipient, 'mailhost', server)
@@ -193,4 +193,4 @@ def execute(*args, **kw):
else:
recipient = auth.find_recipient('/'.join(folder.split('/')[1:]), search_attrs=[result_attribute])
- print folder, server, recipient
+ print(folder, server, recipient)
diff --git a/pykolab/cli/cmd_transfer_mailbox.py b/pykolab/cli/cmd_transfer_mailbox.py
index 1593eea..071eda4 100644
--- a/pykolab/cli/cmd_transfer_mailbox.py
+++ b/pykolab/cli/cmd_transfer_mailbox.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_undelete_mailbox.py b/pykolab/cli/cmd_undelete_mailbox.py
index 5b74a64..35b7a2f 100644
--- a/pykolab/cli/cmd_undelete_mailbox.py
+++ b/pykolab/cli/cmd_undelete_mailbox.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_user_info.py b/pykolab/cli/cmd_user_info.py
index d7b83a6..eb7dfcb 100644
--- a/pykolab/cli/cmd_user_info.py
+++ b/pykolab/cli/cmd_user_info.py
@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
-import commands
+from . import commands
import pykolab
@@ -37,7 +39,7 @@ def execute(*args, **kw):
try:
user = conf.cli_args.pop(0)
- except IndexError, errmsg:
+ except IndexError:
user = utils.ask_question(_("Email address"))
result = wap_client.authenticate(username=conf.get("ldap", "bind_dn"), password=conf.get("ldap", "bind_pw"))
@@ -48,13 +50,13 @@ def execute(*args, **kw):
user_info = wap_client.user_find({'mail':user})
if user_info == None or not user_info:
- print >> sys.stderr, _("No such user %s") % (user)
+ print(_("No such user %s") % (user), file=sys.stderr)
sys.exit(0)
unic_attrs = ['displayname', 'givenname', 'cn', 'sn', 'ou', 'entrydn']
- for (k,v) in user_info.iteritems():
+ for (k,v) in user_info.items():
if k in unic_attrs:
- print "%s: %s" % (k,v)
+ print("%s: %s" % (k,v))
else:
- print "%s: %r" % (k,v)
+ print("%s: %r" % (k,v))
diff --git a/pykolab/cli/commands.py b/pykolab/cli/commands.py
index 515d40c..072c346 100644
--- a/pykolab/cli/commands.py
+++ b/pykolab/cli/commands.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import os
import sys
@@ -44,8 +45,8 @@ def __init__():
cmd_name = module_name.replace('cmd_', '')
#print "exec(\"from %s import __init__ as %s_register\"" % (module_name,cmd_name)
try:
- exec("from %s import __init__ as %s_register" % (module_name,cmd_name))
- except ImportError, errmsg:
+ exec("from .%s import __init__ as %s_register" % (module_name,cmd_name))
+ except ImportError:
pass
exec("%s_register()" % (cmd_name))
@@ -68,7 +69,7 @@ def list_commands(*args, **kw):
__commands = {}
- for command in commands.keys():
+ for command in commands:
if isinstance(command, tuple):
command_group, command = command
__commands[command_group] = {
@@ -81,57 +82,57 @@ def list_commands(*args, **kw):
_commands.sort()
for _command in _commands:
- if __commands[_command].has_key('group'):
+ if 'group' in __commands[_command]:
continue
- if __commands[_command].has_key('function'):
+ if 'function' in __commands[_command]:
# This is a top-level command
if not __commands[_command]['description'] == None:
- print "%-25s - %s" % (_command.replace('_','-'),__commands[_command]['description'])
+ print("%-25s - %s" % (_command.replace('_','-'),__commands[_command]['description']))
else:
- print "%-25s" % (_command.replace('_','-'))
+ print("%-25s" % (_command.replace('_','-')))
for _command in _commands:
- if not __commands[_command].has_key('function'):
+ if 'function' not in __commands[_command]:
# This is a nested command
- print "\n" + _("Command Group: %s") % (_command) + "\n"
+ print("\n" + _("Command Group: %s") % (_command) + "\n")
___commands = __commands[_command].keys()
___commands.sort()
for __command in ___commands:
if not __commands[_command][__command]['description'] == None:
- print "%-4s%-21s - %s" % ('',__command.replace('_','-'),__commands[_command][__command]['description'])
+ print("%-4s%-21s - %s" % ('',__command.replace('_','-'),__commands[_command][__command]['description']))
else:
- print "%-4s%-21s" % ('',__command.replace('_','-'))
+ print("%-4s%-21s" % ('',__command.replace('_','-')))
def execute(cmd_name, *args, **kw):
if cmd_name == "":
execute("help")
sys.exit(0)
- if not commands.has_key(cmd_name):
+ if cmd_name not in commands:
log.error(_("No such command."))
sys.exit(1)
- if not commands[cmd_name].has_key('function') and \
- not commands[cmd_name].has_key('group'):
+ if 'function' not in commands[cmd_name] and \
+ 'group' not in commands[cmd_name]:
log.error(_("No such command."))
sys.exit(1)
- if commands[cmd_name].has_key('group'):
+ if 'group' in commands[cmd_name]:
group = commands[cmd_name]['group']
command_name = commands[cmd_name]['cmd_name']
try:
- exec("from %s.cmd_%s import cli_options as %s_%s_cli_options" % (group,command_name,group,command_name))
+ exec("from .%s.cmd_%s import cli_options as %s_%s_cli_options" % (group,command_name,group,command_name))
exec("%s_%s_cli_options()" % (group,command_name))
- except ImportError, e:
+ except ImportError:
pass
else:
command_name = commands[cmd_name]['cmd_name']
try:
- exec("from cmd_%s import cli_options as %s_cli_options" % (command_name,command_name))
+ exec("from .cmd_%s import cli_options as %s_cli_options" % (command_name,command_name))
exec("%s_cli_options()" % (command_name))
- except ImportError, errmsg:
+ except ImportError:
pass
conf.finalize_conf()
@@ -151,7 +152,7 @@ def register_group(dirname, module):
module_name = filename.replace('.py','')
cmd_name = module_name.replace('cmd_', '')
#print "exec(\"from %s.%s import __init__ as %s_%s_register\"" % (module,module_name,module,cmd_name)
- exec("from %s.%s import __init__ as %s_%s_register" % (module,module_name,module,cmd_name))
+ exec("from .%s.%s import __init__ as %s_%s_register" % (module,module_name,module,cmd_name))
exec("%s_%s_register()" % (module,cmd_name))
def register(cmd_name, func, group=None, description=None, aliases=[]):
@@ -160,10 +161,10 @@ def register(cmd_name, func, group=None, description=None, aliases=[]):
else:
command = cmd_name
- if isinstance(aliases, basestring):
+ if isinstance(aliases, string_types):
aliases = [aliases]
- if commands.has_key(command):
+ if command in commands:
log.fatal(_("Command '%s' already registered") % (command))
sys.exit(1)
@@ -197,5 +198,5 @@ def register(cmd_name, func, group=None, description=None, aliases=[]):
##
def not_yet_implemented(*args, **kw):
- print _("Not yet implemented")
+ print(_("Not yet implemented"))
sys.exit(1)
diff --git a/pykolab/cli/sieve/cmd_list.py b/pykolab/cli/sieve/cmd_list.py
index d10517c..0ed7434 100644
--- a/pykolab/cli/sieve/cmd_list.py
+++ b/pykolab/cli/sieve/cmd_list.py
@@ -19,7 +19,10 @@
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
@@ -103,19 +106,19 @@ def execute(*args, **kw):
)
if not result:
- print "LOGIN FAILED??"
+ print("LOGIN FAILED??")
sieveclient.authenticated = True
result = sieveclient.listscripts()
if result == None:
- print "No scripts"
+ print("No scripts")
sys.exit(0)
(active, scripts) = result
- print "%s (active)" % (active)
+ print("%s (active)" % (active))
for script in scripts:
- print script
+ print(script)
diff --git a/pykolab/cli/sieve/cmd_put.py b/pykolab/cli/sieve/cmd_put.py
index 7286370..5ab937f 100644
--- a/pykolab/cli/sieve/cmd_put.py
+++ b/pykolab/cli/sieve/cmd_put.py
@@ -27,7 +27,10 @@ log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
def __init__():
commands.register('put', execute, group='sieve', description=description())
diff --git a/pykolab/cli/sieve/cmd_refresh.py b/pykolab/cli/sieve/cmd_refresh.py
index b784eac..abb93ae 100644
--- a/pykolab/cli/sieve/cmd_refresh.py
+++ b/pykolab/cli/sieve/cmd_refresh.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import pykolab
@@ -29,7 +30,10 @@ conf = pykolab.getConf()
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
def __init__():
commands.register('refresh', execute, group='sieve', description=description())
@@ -125,28 +129,28 @@ def execute(*args, **kw):
if not vacation_text_attr == None:
- if user.has_key(vacation_active_attr):
+ if vacation_active_attr in user:
vacation_active = utils.true_or_false(user[vacation_active_attr])
else:
vacation_active = False
- if user.has_key(vacation_text_attr):
+ if vacation_text_attr in user:
vacation_text = user[vacation_text_attr]
else:
vacation_active = False
- if user.has_key(vacation_uce_attr):
+ if vacation_uce_attr in user:
vacation_uce = utils.true_or_false(user[vacation_uce_attr])
else:
vacation_uce = False
- if user.has_key(vacation_react_domains_attr):
+ if vacation_react_domains_attr in user:
if isinstance(user[vacation_react_domains_attr], list):
vacation_react_domains = user[vacation_react_domains_attr]
else:
vacation_react_domains = [ user[vacation_react_domains_attr] ]
else:
- if user.has_key(vacation_noreact_domains_attr):
+ if vacation_noreact_domains_attr in user:
if isinstance(user[vacation_noreact_domains_attr], list):
vacation_noreact_domains = user[vacation_noreact_domains_attr]
else:
@@ -159,7 +163,7 @@ def execute(*args, **kw):
#
dtf_active_attr = conf.get('sieve', 'deliver_to_folder_active')
if not dtf_active_attr == None:
- if user.has_key(dtf_active_attr):
+ if dtf_active_attr in user:
dtf_active = utils.true_or_false(user[dtf_active_attr])
else:
dtf_active = False
@@ -172,7 +176,7 @@ def execute(*args, **kw):
if dtf_active:
dtf_folder_name_attr = conf.get('sieve', 'deliver_to_folder_attr')
if not dtf_folder_name_attr == None:
- if user.has_key(dtf_folder_name_attr):
+ if dtf_folder_name_attr in user:
dtf_folder = user[dtf_folder_name_attr]
else:
log.warning(_("Delivery to folder active, but no folder name attribute available for user %r") % (user))
@@ -204,15 +208,15 @@ def execute(*args, **kw):
forward_active_attr = conf.get('sieve', 'forward_address_active')
if not forward_active_attr == None:
- if user.has_key(forward_active_attr):
+ if forward_active_attr in user:
forward_active = utils.true_or_false(user[forward_active_attr])
else:
forward_active = False
if not forward_active == False:
forward_address_attr = conf.get('sieve', 'forward_address_attr')
- if user.has_key(forward_address_attr):
- if isinstance(user[forward_address_attr], basestring):
+ if forward_address_attr in user:
+ if isinstance(user[forward_address_attr], string_types):
forward_addresses = [ user[forward_address_attr] ]
elif isinstance(user[forward_address_attr], str):
forward_addresses = [ user[forward_address_attr] ]
@@ -224,14 +228,14 @@ def execute(*args, **kw):
forward_keepcopy_attr = conf.get('sieve', 'forward_keepcopy_active')
if not forward_keepcopy_attr == None:
- if user.has_key(forward_keepcopy_attr):
+ if forward_keepcopy_attr in user:
forward_keepcopy = utils.true_or_false(user[forward_keepcopy_attr])
else:
forward_keepcopy = False
forward_uce_attr = conf.get('sieve', 'forward_uce_active')
if not forward_uce_attr == None:
- if user.has_key(forward_uce_attr):
+ if forward_uce_attr in user:
forward_uce = utils.true_or_false(user[forward_uce_attr])
else:
forward_uce = False
diff --git a/pykolab/cli/sieve/cmd_test.py b/pykolab/cli/sieve/cmd_test.py
index 0c9421e..0b7bdeb 100644
--- a/pykolab/cli/sieve/cmd_test.py
+++ b/pykolab/cli/sieve/cmd_test.py
@@ -27,7 +27,10 @@ log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
def __init__():
@@ -89,7 +92,7 @@ def execute(*args, **kw):
active, scripts = sieveclient.listscripts()
- print "%s (active)" % (active)
+ print("%s (active)" % (active))
_all_scripts = [ active ] + scripts
_used_scripts = [ active ]
@@ -97,7 +100,7 @@ def execute(*args, **kw):
_a_script = sieveclient.getscript(active)
- print _a_script
+ print(_a_script)
import sievelib.parser
@@ -107,23 +110,23 @@ def execute(*args, **kw):
#print "%r" % (_a_parsed)
if not _a_parsed:
- print _a_parser.error
+ print(_a_parser.error)
- print "%r" % (_a_parser.result)
+ print("%r" % (_a_parser.result))
for _a_command in _a_parser.result:
- print _a_command.name, _a_command.arguments
+ print(_a_command.name, _a_command.arguments)
if len(_a_command.children) > 0:
for _a_child in _a_command.children:
- print " ", _a_child.name, _a_child.arguments
+ print(" ", _a_child.name, _a_child.arguments)
if _a_command.name == "include":
if _a_command.arguments["script"].strip('"') in scripts:
- print "OK"
+ print("OK")
_used_scripts.append(_a_command.arguments["script"].strip('"'))
else:
- print "Not OK"
+ print("Not OK")
for script in scripts:
- print script
+ print(script)
diff --git a/pykolab/cli/telemetry/cmd_examine_command_issue.py b/pykolab/cli/telemetry/cmd_examine_command_issue.py
index 9563dbc..15d8673 100644
--- a/pykolab/cli/telemetry/cmd_examine_command_issue.py
+++ b/pykolab/cli/telemetry/cmd_examine_command_issue.py
@@ -72,7 +72,7 @@ def execute(*args, **kw):
id=session.server_id
).first()
- print _("Session by %s on server %s") % (user.sasl_username,server.fqdn)
+ print(_("Session by %s on server %s") % (user.sasl_username,server.fqdn))
command_issues = db.query(
telemetry.TelemetryCommandIssue
@@ -94,14 +94,14 @@ def execute(*args, **kw):
).first()
if command_issue.id == _command_issue.id:
- print "========="
+ print("=========")
- print "Client(%d): %s %s %s" % (
+ print("Client(%d): %s %s %s" % (
_command_issue.id,
_command_issue.command_tag,
command.command,
command_arg.command_arg
- )
+ ))
server_responses = db.query(
telemetry.TelemetryServerResponse
@@ -113,11 +113,11 @@ def execute(*args, **kw):
server_response_lines = server_response.response.split('\n');
for server_response_line in server_response_lines:
- print "Server(%d): %s" % (
+ print("Server(%d): %s" % (
server_response.id,
server_response_line
- )
+ ))
if command_issue.id == _command_issue.id:
- print "========="
+ print("=========")
diff --git a/pykolab/cli/telemetry/cmd_examine_session.py b/pykolab/cli/telemetry/cmd_examine_session.py
index cf09b74..d6851d5 100644
--- a/pykolab/cli/telemetry/cmd_examine_session.py
+++ b/pykolab/cli/telemetry/cmd_examine_session.py
@@ -97,7 +97,7 @@ def execute(*args, **kw):
return
- print _("Session by %s on server %s") % (user.sasl_username,server.fqdn)
+ print(_("Session by %s on server %s") % (user.sasl_username,server.fqdn))
command_issues = db.query(
telemetry.TelemetryCommandIssue
@@ -118,12 +118,12 @@ def execute(*args, **kw):
id=command_issue.command_arg_id
).first()
- print "Client(%d): %s %s %s" % (
+ print("Client(%d): %s %s %s" % (
command_issue.id,
command_issue.command_tag,
command.command,
command_arg.command_arg
- )
+ ))
server_responses = db.query(
telemetry.TelemetryServerResponse
@@ -134,8 +134,8 @@ def execute(*args, **kw):
for server_response in server_responses:
server_response_lines = server_response.response.split('\n');
for server_response_line in server_response_lines:
- print "Server(%d): %s" % (
+ print("Server(%d): %s" % (
server_response.id,
server_response_line
- )
+ ))
diff --git a/pykolab/cli/telemetry/cmd_list_sessions.py b/pykolab/cli/telemetry/cmd_list_sessions.py
index 6ed0ab7..773856f 100644
--- a/pykolab/cli/telemetry/cmd_list_sessions.py
+++ b/pykolab/cli/telemetry/cmd_list_sessions.py
@@ -55,9 +55,9 @@ def execute(*args, **kw):
id=session.user_id
).first()
- print _("Session for user %s started at %s with ID %s") % (
+ print(_("Session for user %s started at %s with ID %s") % (
user.sasl_username,
session.start,
session.id
- )
+ ))
diff --git a/pykolab/cli/wap/cmd_system_capabilities.py b/pykolab/cli/wap/cmd_system_capabilities.py
index 3cabdd7..7b27e40 100644
--- a/pykolab/cli/wap/cmd_system_capabilities.py
+++ b/pykolab/cli/wap/cmd_system_capabilities.py
@@ -38,13 +38,13 @@ def execute(*args, **kw):
system_capabilities = wap_client.system_capabilities()
if system_capabilities['count'] < 1:
- print "No system capabilities"
+ print("No system capabilities")
sys.exit(1)
- for domain in system_capabilities['list'].keys():
- print "Domain capabilities for %s" % (domain)
+ for domain in system_capabilities['list']:
+ print("Domain capabilities for %s" % (domain))
domain_capabilities = system_capabilities['list'][domain]
- for service in domain_capabilities['actions'].keys():
- print " %-15s - %r" % (service, domain_capabilities['actions'][service]['type'])
+ for service in domain_capabilities['actions']:
+ print(" %-15s - %r" % (service, domain_capabilities['actions'][service]['type']))
diff --git a/pykolab/cli/wap/cmd_user_types_list.py b/pykolab/cli/wap/cmd_user_types_list.py
index ee1e7f9..0136781 100644
--- a/pykolab/cli/wap/cmd_user_types_list.py
+++ b/pykolab/cli/wap/cmd_user_types_list.py
@@ -37,4 +37,4 @@ def execute(*args, **kw):
for user_type in user_types['list']:
type = user_types['list'][user_type]
- print "%-15s - %s" % (type['key'], type['description'])
+ print("%-15s - %s" % (type['key'], type['description']))
diff --git a/pykolab/conf/__init__.py b/pykolab/conf/__init__.py
index 16f38d8..5628488 100644
--- a/pykolab/conf/__init__.py
+++ b/pykolab/conf/__init__.py
@@ -23,7 +23,10 @@ import os
import sys
from optparse import OptionParser
-from ConfigParser import SafeConfigParser
+try:
+ from ConfigParser import SafeConfigParser
+except ImportError:
+ from configparser import SafeConfigParser
import pykolab
@@ -85,7 +88,7 @@ class Conf(object):
self.defaults = Defaults(self.plugins)
# But, they should be available in our class as well
- for option in self.defaults.__dict__.keys():
+ for option in self.defaults.__dict__:
log.debug(
_("Setting %s to %r (from defaults)") % (
option,
@@ -103,7 +106,7 @@ class Conf(object):
# Also set the cli options
if hasattr(self, 'cli_keywords') and self.cli_keywords is not None:
- for option in self.cli_keywords.__dict__.keys():
+ for option in self.cli_keywords.__dict__:
retval = False
if hasattr(self, "check_setting_%s" % (option)):
exec(
@@ -144,14 +147,14 @@ class Conf(object):
file and checks, then sets everything it can find.
"""
- for section in self.defaults.__dict__.keys():
+ for section in self.defaults.__dict__:
if section == 'testing':
continue
if not config.has_section(section):
continue
- for key in self.defaults.__dict__[section].keys():
+ for key in self.defaults.__dict__[section]:
retval = False
if not config.has_option(section, key):
continue
@@ -530,7 +533,7 @@ class Conf(object):
)
def set_defaults_from_cli_options(self):
- for long_opt in self.cli_parser.__dict__['_long_opt'].keys():
+ for long_opt in self.cli_parser.__dict__['_long_opt']:
if long_opt == "--help":
continue
@@ -541,7 +544,7 @@ class Conf(object):
)
# But, they should be available in our class as well
- for option in self.cli_parser.defaults.keys():
+ for option in self.cli_parser.defaults:
log.debug(
_("Setting %s to %r (from the default values for CLI options)") % (
option,
@@ -596,7 +599,7 @@ class Conf(object):
self.read_config()
if self.cfg_parser.has_option(section, key):
- return self.cfg_parser.get(section, key, 1)
+ return self.cfg_parser.get(section, key, raw=1)
return default
@@ -642,12 +645,13 @@ class Conf(object):
if quiet:
return ""
else:
- log.warning(
+ log.debug(
_("Option %s/%s does not exist in config file %s, pulling from defaults") % (
section,
key,
self.config_file
- )
+ ),
+ level=8
)
if hasattr(self.defaults, "%s_%s" % (section, key)):
diff --git a/pykolab/conf/entitlement.py b/pykolab/conf/entitlement.py
index 5dda82c..ac2b169 100644
--- a/pykolab/conf/entitlement.py
+++ b/pykolab/conf/entitlement.py
@@ -17,7 +17,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-from ConfigParser import ConfigParser
+try:
+ from ConfigParser import ConfigParser
+except ImportError:
+ from configparser import ConfigParser
import hashlib
import OpenSSL
import os
@@ -54,8 +57,8 @@ class Entitlement(object):
)
if (bool)(ca_cert.has_expired()):
- raise Exception, _("Invalid entitlement verification " + \
- "certificate at %s" % (ca_cert_file))
+ raise Exception(_("Invalid entitlement verification " + \
+ "certificate at %s" % (ca_cert_file)))
# TODO: Check validity and warn ~1-2 months in advance.
@@ -77,8 +80,8 @@ class Entitlement(object):
ca_cert_issuer_hash_digest = hashlib.sha224(ca_cert_issuer_hash).hexdigest()
if not ca_cert_issuer_hash_digest in self.entitlement_verification:
- raise Exception, _("Invalid entitlement verification " + \
- "certificate at %s") % (ca_cert_file)
+ raise Exception(_("Invalid entitlement verification " + \
+ "certificate at %s") % (ca_cert_file))
ca_cert_subject_hash = subprocess.Popen(
[
@@ -95,8 +98,8 @@ class Entitlement(object):
ca_cert_subject_hash_digest = hashlib.sha224(ca_cert_subject_hash).hexdigest()
if not ca_cert_subject_hash_digest in self.entitlement_verification:
- raise Exception, _("Invalid entitlement verification " + \
- "certificate at %s") % (ca_cert_file)
+ raise Exception(_("Invalid entitlement verification " + \
+ "certificate at %s") % (ca_cert_file))
customer_cert_issuer_hash = subprocess.Popen(
[
@@ -113,14 +116,14 @@ class Entitlement(object):
customer_cert_issuer_hash_digest = hashlib.sha224(customer_cert_issuer_hash).hexdigest()
if not customer_cert_issuer_hash_digest in self.entitlement_verification:
- raise Exception, _("Invalid entitlement verification " + \
- "certificate at %s") % (customer_cert_file)
+ raise Exception(_("Invalid entitlement verification " + \
+ "certificate at %s") % (customer_cert_file))
if not ca_cert_issuer.countryName == ca_cert_subject.countryName:
- raise Exception, _("Invalid entitlement certificate")
+ raise Exception(_("Invalid entitlement certificate"))
if not ca_cert_issuer.organizationName == ca_cert_subject.organizationName:
- raise Exception, _("Invalid entitlement certificate")
+ raise Exception(_("Invalid entitlement certificate"))
if os.path.isdir('/etc/kolab/entitlement.d/') and \
os.access('/etc/kolab/entitlement.d/', os.R_OK):
@@ -192,7 +195,7 @@ class Entitlement(object):
# log.error(_("Error reading entitlement certificate authority file"))
def get(self):
- if len(self.entitlement.keys()) == 0:
+ if len(self.entitlement) == 0:
return None
else:
return self.entitlement
@@ -227,8 +230,8 @@ class License(object):
).communicate()[0].strip().split('=')[1]
if not customer_cert_serial == cert_serial:
- raise Exception, _("Invalid entitlement verification " + \
- "certificate at %s") % (customer_cert_file)
+ raise Exception(_("Invalid entitlement verification " + \
+ "certificate at %s") % (customer_cert_file))
customer_cert_issuer_hash = subprocess.Popen(
[
@@ -243,8 +246,8 @@ class License(object):
).communicate()[0].strip()
if not customer_cert_issuer_hash == cert_issuer_hash:
- raise Exception, _("Invalid entitlement verification " + \
- "certificate at %s") % (customer_cert_file)
+ raise Exception(_("Invalid entitlement verification " + \
+ "certificate at %s") % (customer_cert_file))
customer_cert_subject_hash = subprocess.Popen(
[
@@ -259,8 +262,8 @@ class License(object):
).communicate()[0].strip()
if not customer_cert_subject_hash == cert_subject_hash:
- raise Exception, _("Invalid entitlement verification " + \
- "certificate at %s") % (customer_cert_file)
+ raise Exception(_("Invalid entitlement verification " + \
+ "certificate at %s") % (customer_cert_file))
def get(self):
return self.entitlement
diff --git a/pykolab/constants.py.in b/pykolab/constants.py.in
index 9b06666..b99c433 100644
--- a/pykolab/constants.py.in
+++ b/pykolab/constants.py.in
@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import math
import socket
import sys
@@ -50,7 +52,7 @@ fqdn = socket.getfqdn()
try:
domain_parts = fqdn.split('.')
if len(domain_parts) < 3:
- print >> sys.stderr, _("WARNING") + ": " + _("The Fully Qualified Domain Name or FQDN for this system is incorrect. Falling back to 'localdomain'.")
+ print(_("WARNING") + ": " + _("The Fully Qualified Domain Name or FQDN for this system is incorrect. Falling back to 'localdomain'."), file=sys.stderr)
domainname = "localdomain"
else:
domainname = '.'.join(domain_parts[1:])
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 8ea23e7..171e4e5 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
+from six import string_types
import logging
import re
@@ -24,7 +24,10 @@ import time
import socket
import sys
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
from pykolab import utils
@@ -70,7 +73,7 @@ class IMAP(object):
# For each ACL entry, see if we think it is a current, valid
# entry
- for acl_entry in acls.keys():
+ for acl_entry in acls:
# If the key 'acl_entry' does not exist in the dictionary
# of valid ACL entries, this ACL entry has got to go.
if acl_entry == aci_subject:
@@ -89,7 +92,7 @@ class IMAP(object):
self.set_acl(folder, acl_entry, '')
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(
_("Failed to read/set ACL on folder %s: %r") % (
folder,
@@ -175,7 +178,7 @@ class IMAP(object):
if hostname not in self._imap:
if backend == 'cyrus-imap':
- import cyrus
+ from . import cyrus
self._imap[hostname] = cyrus.Cyrus(uri)
# Actually connect
if login:
@@ -184,7 +187,7 @@ class IMAP(object):
self._imap[hostname].logged_in = True
elif backend == 'dovecot':
- import dovecot
+ from . import dovecot
self._imap[hostname] = dovecot.Dovecot(uri)
# Actually connect
if login:
@@ -243,7 +246,7 @@ class IMAP(object):
del self.imap
# Empty out self._imap as well
- for key in self._imap.keys():
+ for key in list(self._imap):
del self._imap[key]
else:
@@ -263,27 +266,31 @@ class IMAP(object):
try:
self._imap[server].cm(folder_path, partition=partition)
return True
- except Exception:
- log.error(_("Could not create folder %r on server %r") % (folder_path, server))
+ except Exception as excpt:
+ log.error(
+ _("Could not create folder %r on server %r: %r") % (folder_path, server, excpt)
+ )
else:
try:
self.imap.cm(folder_path, partition=partition)
return True
- except Exception:
- log.error(_("Could not create folder %r") % (folder_path))
+ except Exception as excpt:
+ log.error(_("Could not create folder %r: %r") % (folder_path, excpt))
return False
def __getattr__(self, name):
if hasattr(self.imap, name):
return getattr(self.imap, name)
- elif hasattr(self.imap, 'm'):
+
+ if hasattr(self.imap, 'm'):
if hasattr(self.imap.m, name):
return getattr(self.imap.m, name)
- else:
- raise AttributeError(_("%r has no attribute %s") % (self, name))
- else:
- raise AttributeError(_("%r has no attribute %s") % (self, name))
+
+ raise AttributeError(_("%r has no attribute %s") % (self, name))
+
+ def append(self, folder, message):
+ return self.imap.m.append(self.folder_utf7(folder), None, None, message)
def folder_utf7(self, folder):
from pykolab import imap_utf7
@@ -407,7 +414,7 @@ class IMAP(object):
acl_map[mode] += char
current_acls = self.imap.lam(self.folder_utf7(folder))
- for current_acl in current_acls.keys():
+ for current_acl in current_acls:
if current_acl == identifier:
_acl = current_acls[current_acl]
break
@@ -565,7 +572,7 @@ class IMAP(object):
auth.disconnect()
- if len(domains.keys()) > 0:
+ if len(domains) > 0:
if self.domain in domains:
primary = domains[self.domain]
@@ -647,7 +654,7 @@ class IMAP(object):
time.sleep(0.5)
- for additional_folder in additional_folders.keys():
+ for additional_folder in additional_folders:
_add_folder = {}
folder_name = additional_folder
@@ -664,7 +671,7 @@ class IMAP(object):
continue
if "annotations" in additional_folders[additional_folder]:
- for annotation in additional_folders[additional_folder]["annotations"].keys():
+ for annotation in additional_folders[additional_folder]["annotations"]:
self.set_metadata(
folder_name,
"%s" % (annotation),
@@ -672,7 +679,7 @@ class IMAP(object):
)
if "acls" in additional_folders[additional_folder]:
- for acl in additional_folders[additional_folder]["acls"].keys():
+ for acl in additional_folders[additional_folder]["acls"]:
self.set_acl(
folder_name,
"%s" % (acl),
@@ -737,7 +744,7 @@ class IMAP(object):
self.logout()
self.connect(domain=self.domain)
- for additional_folder in additional_folders.keys():
+ for additional_folder in additional_folders:
if additional_folder.startswith(personal) and not personal == '':
folder_name = additional_folder.replace(personal, '')
else:
@@ -899,7 +906,7 @@ class IMAP(object):
return
- if isinstance(acls, basestring):
+ if isinstance(acls, string_types):
acls = [ acls ]
old_acls = None
diff --git a/pykolab/imap/cyrus.py b/pykolab/imap/cyrus.py
index 15a7d00..91df698 100644
--- a/pykolab/imap/cyrus.py
+++ b/pykolab/imap/cyrus.py
@@ -17,11 +17,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import cyruslib
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
@@ -146,15 +151,15 @@ class Cyrus(cyruslib.CYRUS):
"""
try:
cyruslib.CYRUS.login(self, *args, **kw)
- except cyruslib.CYRUSError, errmsg:
+ except cyruslib.CYRUSError as errmsg:
log.error("Login to Cyrus IMAP server failed: %r", errmsg)
- except Exception, errmsg:
+ except Exception as errmsg:
log.exception(errmsg)
self.separator = self.SEP
try:
self._id()
- except Exception, errmsg:
+ except Exception:
pass
log.debug(
@@ -217,7 +222,7 @@ class Cyrus(cyruslib.CYRUS):
level=8
)
- if self.mbox.has_key(mailfolder):
+ if mailfolder in self.mbox:
log.debug(
_(
"Possibly reproducing the find " +
@@ -246,8 +251,8 @@ class Cyrus(cyruslib.CYRUS):
ann_path
)
- if annotations.has_key(mailfolder):
- if annotations[mailfolder].has_key(s_ann_path):
+ if mailfolder in annotations:
+ if s_ann_path in annotations[mailfolder]:
break
if max_tries <= num_try:
@@ -380,7 +385,7 @@ class Cyrus(cyruslib.CYRUS):
try:
self.setannotation(mailfolder, annotation, value, shared)
- except cyruslib.CYRUSError, errmsg:
+ except cyruslib.CYRUSError as errmsg:
log.error(
_("Could not set annotation %r on mail folder %r: %r") % (
annotation,
@@ -499,18 +504,16 @@ class Cyrus(cyruslib.CYRUS):
self.rename(undelete_folder, target_folder)
else:
if not target_server == source_server:
- print >> sys.stdout, \
- _("Would have transferred %s from %s to %s") % (
+ print(_("Would have transferred %s from %s to %s") % (
undelete_folder,
source_server,
target_server
- )
+ ), file=sys.stdout)
- print >> sys.stdout, \
- _("Would have renamed %s to %s") % (
+ print(_("Would have renamed %s to %s") % (
undelete_folder,
target_folder
- )
+ ), file=sys.stdout)
def parse_mailfolder(self, mailfolder):
"""
diff --git a/pykolab/imap/dovecot.py b/pykolab/imap/dovecot.py
index 8d5c0a5..869ab5b 100644
--- a/pykolab/imap/dovecot.py
+++ b/pykolab/imap/dovecot.py
@@ -37,12 +37,17 @@
# are using need.
# -----
+from __future__ import print_function
+
import cyruslib
import imaplib
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
@@ -240,7 +245,7 @@ class Dovecot(cyruslib.CYRUS):
def __verbose(self, msg):
if self.VERBOSE:
- print >> self.LOGFD, msg
+ print(msg, file=self.LOGFD)
def connect(self, uri):
"""
@@ -521,9 +526,9 @@ class Dovecot(cyruslib.CYRUS):
self.rename(undelete_folder,target_folder)
else:
if not target_server == self.server:
- print >> sys.stdout, _("Would have transfered %s from %s to %s") % (undelete_folder, self.server, target_server)
+ print(_("Would have transfered %s from %s to %s") % (undelete_folder, self.server, target_server), file=sys.stdout)
- print >> sys.stdout, _("Would have renamed %s to %s") % (undelete_folder, target_folder)
+ print(_("Would have renamed %s to %s") % (undelete_folder, target_folder), file=sys.stdout)
def parse_mailfolder(self, mailfolder):
"""
diff --git a/pykolab/imap_utf7.py b/pykolab/imap_utf7.py
index 038623b..152609c 100644
--- a/pykolab/imap_utf7.py
+++ b/pykolab/imap_utf7.py
@@ -22,58 +22,70 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+# https://twistedmatrix.com/trac/attachment/ticket/6289/imap4.patch
+# #6289 enhancement closed fixed (fixed)
+# Port imap4-utf-7 codec implementation to Python 3
class FolderNameError(ValueError):
pass
+try:
+ unicode()
+except:
+ unicode = str
+
+memory_cast = getattr(memoryview, "cast", lambda *x: x[0])
+
def encode(s):
if isinstance(s, str) and sum(n for n in (ord(c) for c in s) if n > 127):
try:
- s = unicode(s, "UTF-8")
- except Exception, errmsg:
+ s = bytes(s, "UTF-8")
+ except Exception:
raise FolderNameError("%r contains characters not valid in a str folder name. "
- "Convert to unicode first?" % s)
+ "Convert to unicode first?" % s)
- r = []
+ r = bytearray()
_in = []
+ valid_chars = set(map(chr, range(0x20, 0x7f))) - {u"&"}
for c in s:
- if ord(c) in (range(0x20, 0x26) + range(0x27, 0x7f)):
+ if c in valid_chars:
if _in:
- r.extend(['&', modified_base64(''.join(_in)), '-'])
+ r += b'&' + modified_base64(''.join(_in)) + b'-'
del _in[:]
- r.append(str(c))
- elif c == '&':
+ r.append(ord(c))
+ elif c == u'&':
if _in:
- r.extend(['&', modified_base64(''.join(_in)), '-'])
+ r += b'&' + modified_base64(''.join(_in)) + b'-'
del _in[:]
- r.append('&-')
+ r += b'&-'
else:
_in.append(c)
if _in:
- r.extend(['&', modified_base64(''.join(_in)), '-'])
+ r.extend(b'&' + modified_base64(''.join(_in)) + b'-')
- return ''.join(r)
+ return bytes(r)
def decode(s):
r = []
decode = []
+ s = memory_cast(memoryview(s), 'c')
for c in s:
- if c == '&' and not decode:
- decode.append('&')
- elif c == '-' and decode:
+ if c == b'&' and not decode:
+ decode.append(u'&')
+ elif c == b'-' and decode:
if len(decode) == 1:
- r.append('&')
+ r.append(u'&')
else:
- r.append(modified_unbase64(''.join(decode[1:])))
+ r.append(modified_unbase64(b''.join(decode[1:])))
decode = []
elif decode:
decode.append(c)
else:
- r.append(c)
+ r.append(c.decode())
if decode:
- r.append(modified_unbase64(''.join(decode[1:])))
+ r.append(modified_unbase64(b''.join(decode[1:])))
out = ''.join(r)
if not isinstance(out, unicode):
@@ -83,9 +95,9 @@ def decode(s):
def modified_base64(s):
s_utf7 = s.encode('utf-7')
- return s_utf7[1:-1].replace('/', ',')
+ return s_utf7[1:-1].replace(b'/', b',')
def modified_unbase64(s):
- s_utf7 = '+' + s.replace(',', '/') + '-'
+ s_utf7 = b'+' + s.replace(b',', b'/') + b'-'
return s_utf7.decode('utf-7')
diff --git a/pykolab/logger.py b/pykolab/logger.py
index 2b857e2..ab41c94 100644
--- a/pykolab/logger.py
+++ b/pykolab/logger.py
@@ -213,10 +213,10 @@ class Logger(logging.Logger):
group_gid
)
- os.chmod(self.logfile, 0660)
+ os.chmod(self.logfile, 0o660)
except Exception as errmsg:
- self.error(
+ print(
_("Could not change permissions on %s: %r") % (self.logfile, errmsg)
)
@@ -226,7 +226,7 @@ class Logger(logging.Logger):
except Exception as errmsg:
if os.path.isfile(self.logfile):
- self.error(_("Could not change permissions on %s: %r") % (self.logfile, errmsg))
+ print(_("Could not change permissions on %s: %r") % (self.logfile, errmsg))
if self.debuglevel > 8:
import traceback
traceback.print_exc()
diff --git a/pykolab/plugins/__init__.py b/pykolab/plugins/__init__.py
index 82bf525..96e0044 100644
--- a/pykolab/plugins/__init__.py
+++ b/pykolab/plugins/__init__.py
@@ -67,15 +67,15 @@ class KolabPlugins(object):
exec("from pykolab.plugins import %s" % (plugin))
self.plugins[plugin] = True
self.load_plugins(plugins=[plugin])
- except ImportError, e:
+ except ImportError as e:
log.error(_("ImportError for plugin %s: %s") % (plugin, e))
traceback.print_exc()
self.plugins[plugin] = False
- except RuntimeError, e:
+ except RuntimeError as e:
log.error( _("RuntimeError for plugin %s: %s") % (plugin, e))
traceback.print_exc()
self.plugins[plugin] = False
- except Exception, e:
+ except Exception as e:
log.error(_("Plugin %s failed to load (%s: %s)") % (plugin, e.__class__, e))
traceback.print_exc()
except:
@@ -113,9 +113,9 @@ class KolabPlugins(object):
if hasattr(getattr(self, plugin), "set_defaults"):
try:
getattr(self, plugin).set_defaults(defaults)
- except TypeError, e:
+ except TypeError as e:
log.error(_("Cannot set defaults for plugin %s: %s") % (plugin, e))
- except RuntimeError, e:
+ except RuntimeError as e:
log.error(_("Cannot set defaults for plugin %s: %s") % (plugin, e))
except:
log.error(_("Cannot set defaults for plugin %s: Unknown Error") % (plugin))
@@ -139,7 +139,7 @@ class KolabPlugins(object):
if hasattr(getattr(self, plugin), "set_runtime"):
try:
getattr(self, plugin).set_runtime(runtime)
- except RuntimeError, e:
+ except RuntimeError as e:
log.error(_("Cannot set runtime for plugin %s: %s") % (plugin, e))
else:
log.debug(_("Not setting runtime for plugin %s: No function 'set_runtime()'") % (plugin), level=5)
@@ -160,9 +160,9 @@ class KolabPlugins(object):
if hasattr(getattr(self, plugin), "add_options"):
try:
exec("self.%s.add_options(parser)" % plugin)
- except RuntimeError, e:
+ except RuntimeError as e:
log.error(_("Cannot add options for plugin %s: %s") % (plugin, e))
- except TypeError, e:
+ except TypeError as e:
log.error(_("Cannot add options for plugin %s: %s") % (plugin, e))
else:
log.debug(_("Not adding options for plugin %s: No function 'add_options()'") % plugin, level=5)
@@ -184,7 +184,7 @@ class KolabPlugins(object):
if hasattr(getattr(self, plugin), "check_options"):
try:
exec("self.%s.check_options()" % plugin)
- except AttributeError, e:
+ except AttributeError as e:
log.error(_("Cannot check options for plugin %s: %s") % (plugin, e))
else:
log.debug(_("Not checking options for plugin %s: No function 'check_options()'") % (plugin), level=5)
@@ -262,7 +262,7 @@ class KolabPlugins(object):
if hasattr(getattr(self, plugin), bool):
try:
exec("boolval = self.%s.%s" % (plugin, bool))
- except AttributeError, e:
+ except AttributeError:
pass
else:
boolval = None
diff --git a/pykolab/plugins/defaultfolders/__init__.py b/pykolab/plugins/defaultfolders/__init__.py
index e098ec2..a4a59b0 100644
--- a/pykolab/plugins/defaultfolders/__init__.py
+++ b/pykolab/plugins/defaultfolders/__init__.py
@@ -43,13 +43,13 @@ class KolabDefaultfolders(object):
user_folder - user folder
"""
- if not kw.has_key('additional_folders'):
+ if 'additional_folders' not in kw:
log.error(_("Plugin %s called without required keyword %s.") % ("defaultfolders", "additional_folders"))
return {}
try:
exec("additional_folders = %s" % (kw['additional_folders']))
- except Exception, e:
+ except Exception:
log.error(_("Could not parse additional_folders"))
return {}
diff --git a/pykolab/plugins/dynamicquota/__init__.py b/pykolab/plugins/dynamicquota/__init__.py
index c9b9b7f..51cb547 100644
--- a/pykolab/plugins/dynamicquota/__init__.py
+++ b/pykolab/plugins/dynamicquota/__init__.py
@@ -53,7 +53,7 @@ class KolabDynamicquota(object):
"""
for keyword in [ 'used', 'imap_quota', 'ldap_quota', 'default_quota' ]:
- if not kw.has_key(keyword):
+ if keyword not in kw:
log.warning(
_("No keyword %s passed to set_user_folder_quota") % (
keyword
diff --git a/pykolab/plugins/recipientpolicy/__init__.py b/pykolab/plugins/recipientpolicy/__init__.py
index 23ba863..330ddfa 100644
--- a/pykolab/plugins/recipientpolicy/__init__.py
+++ b/pykolab/plugins/recipientpolicy/__init__.py
@@ -56,12 +56,12 @@ class KolabRecipientpolicy(object):
user_attrs = utils.normalize(kw['entry'])
- if not user_attrs.has_key('domain'):
+ if 'domain' not in user_attrs:
user_attrs['domain'] = kw['primary_domain']
elif not user_attrs['domain'] == kw['primary_domain']:
user_attrs['domain'] = kw['primary_domain']
- if not user_attrs.has_key('preferredlanguage'):
+ if 'preferredlanguage' not in user_attrs:
default_locale = conf.get(user_attrs['domain'], 'default_locale')
if default_locale == None:
default_locale = conf.get('kolab', 'default_locale')
@@ -75,9 +75,9 @@ class KolabRecipientpolicy(object):
mail = utils.translate(mail, user_attrs['preferredlanguage'])
mail = mail.lower()
return mail
- except KeyError, e:
+ except KeyError:
log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy"))
- if user_attrs.has_key('mail'):
+ if 'mail' in user_attrs:
return user_attrs['mail']
else:
return None
@@ -96,12 +96,12 @@ class KolabRecipientpolicy(object):
user_attrs = utils.normalize(kw['entry'])
- if not user_attrs.has_key('domain'):
+ if 'domain' not in user_attrs:
user_attrs['domain'] = kw['primary_domain']
elif not user_attrs['domain'] == kw['primary_domain']:
user_attrs['domain'] = kw['primary_domain']
- if not user_attrs.has_key('preferredlanguage'):
+ if 'preferredlanguage' not in user_attrs:
default_locale = conf.get(user_attrs['domain'], 'default_locale')
if default_locale == None:
default_locale = conf.get(user_attrs['domain'], 'default_locale')
@@ -112,7 +112,7 @@ class KolabRecipientpolicy(object):
try:
exec("alternative_mail_routines = %s" % kw['secondary_mail'])
- except Exception, e:
+ except Exception:
log.error(_("Could not parse the alternative mail routines"))
alternative_mail = []
@@ -123,22 +123,22 @@ class KolabRecipientpolicy(object):
for attr in [ 'givenname', 'sn', 'surname' ]:
try:
user_attrs[attr] = utils.translate(user_attrs[attr], user_attrs['preferredlanguage'])
- except Exception, errmsg:
+ except Exception:
log.error(_("An error occurred in composing the secondary mail attribute for entry %r") % (user_attrs['id']))
if conf.debuglevel > 8:
import traceback
traceback.print_exc()
return []
- for number in alternative_mail_routines.keys():
- for routine in alternative_mail_routines[number].keys():
+ for number in alternative_mail_routines:
+ for routine in alternative_mail_routines[number]:
try:
exec("retval = '%s'.%s" % (routine,alternative_mail_routines[number][routine] % user_attrs))
log.debug(_("Appending additional mail address: %s") % (retval), level=8)
alternative_mail.append(retval)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Policy for secondary email address failed: %r") % (errmsg))
if conf.debuglevel > 8:
import traceback
@@ -153,7 +153,7 @@ class KolabRecipientpolicy(object):
log.debug(_("Appending additional mail address: %s") % (retval), level=8)
alternative_mail.append(retval)
- except KeyError, e:
+ except KeyError:
log.warning(_("Attribute substitution for 'alternative_mail' failed in Recipient Policy"))
alternative_mail = utils.normalize(alternative_mail)
diff --git a/pykolab/plugins/roundcubedb/__init__.py b/pykolab/plugins/roundcubedb/__init__.py
index 40271c3..9fe7642 100644
--- a/pykolab/plugins/roundcubedb/__init__.py
+++ b/pykolab/plugins/roundcubedb/__init__.py
@@ -58,7 +58,7 @@ class KolabRoundcubedb(object):
result_attribute = conf.get('cyrus-sasl', 'result_attribute')
# execute Roundcube's bin/deluser.sh script to do the work
- if kw.has_key('user') and kw['user'].has_key(result_attribute) and os.path.exists(rcpath + 'bin/deluser.sh'):
+ if 'user' in kw and result_attribute in kw['user'] and os.path.exists(rcpath + 'bin/deluser.sh'):
proc = subprocess.Popen([ 'sudo -u apache', rcpath + 'bin/deluser.sh', kw['user'][result_attribute] ], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
procout, procerr = proc.communicate()
if proc.returncode != 0:
diff --git a/pykolab/plugins/sievemgmt/__init__.py b/pykolab/plugins/sievemgmt/__init__.py
index 75e247b..772165d 100644
--- a/pykolab/plugins/sievemgmt/__init__.py
+++ b/pykolab/plugins/sievemgmt/__init__.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import pykolab
@@ -28,7 +29,10 @@ log = pykolab.getLogger('pykolab.plugin_sievemgmt')
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
class KolabSievemgmt(object):
"""
@@ -47,7 +51,7 @@ class KolabSievemgmt(object):
user - the user identifier
"""
- if not len(kw.keys()) == 1 or not kw.has_key('user'):
+ if not len(kw) == 1 or 'user' not in kw:
log.error(_("Wrong number of arguments for sieve management plugin"))
return
else:
@@ -137,28 +141,28 @@ class KolabSievemgmt(object):
if not vacation_text_attr == None:
- if user.has_key(vacation_active_attr):
+ if vacation_active_attr in user:
vacation_active = utils.true_or_false(user[vacation_active_attr])
else:
vacation_active = False
- if user.has_key(vacation_text_attr):
+ if vacation_text_attr in user:
vacation_text = user[vacation_text_attr]
else:
vacation_active = False
- if user.has_key(vacation_uce_attr):
+ if vacation_uce_attr in user:
vacation_uce = utils.true_or_false(user[vacation_uce_attr])
else:
vacation_uce = False
- if user.has_key(vacation_react_domains_attr):
+ if vacation_react_domains_attr in user:
if isinstance(user[vacation_react_domains_attr], list):
vacation_react_domains = user[vacation_react_domains_attr]
else:
vacation_react_domains = [ user[vacation_react_domains_attr] ]
else:
- if user.has_key(vacation_noreact_domains_attr):
+ if vacation_noreact_domains_attr in user:
if isinstance(user[vacation_noreact_domains_attr], list):
vacation_noreact_domains = user[vacation_noreact_domains_attr]
else:
@@ -171,7 +175,7 @@ class KolabSievemgmt(object):
#
dtf_active_attr = conf.get('sieve', 'deliver_to_folder_active')
if not dtf_active_attr == None:
- if user.has_key(dtf_active_attr):
+ if dtf_active_attr in user:
dtf_active = utils.true_or_false(user[dtf_active_attr])
else:
dtf_active = False
@@ -184,7 +188,7 @@ class KolabSievemgmt(object):
if dtf_active:
dtf_folder_name_attr = conf.get('sieve', 'deliver_to_folder_attr')
if not dtf_folder_name_attr == None:
- if user.has_key(dtf_folder_name_attr):
+ if dtf_folder_name_attr in user:
dtf_folder = user[dtf_folder_name_attr]
else:
log.warning(_("Delivery to folder active, but no folder name attribute available for user %r") % (user))
@@ -216,15 +220,15 @@ class KolabSievemgmt(object):
forward_active_attr = conf.get('sieve', 'forward_address_active')
if not forward_active_attr == None:
- if user.has_key(forward_active_attr):
+ if forward_active_attr in user:
forward_active = utils.true_or_false(user[forward_active_attr])
else:
forward_active = False
if not forward_active == False:
forward_address_attr = conf.get('sieve', 'forward_address_attr')
- if user.has_key(forward_address_attr):
- if isinstance(user[forward_address_attr], basestring):
+ if forward_address_attr in user:
+ if isinstance(user[forward_address_attr], string_types):
forward_addresses = [ user[forward_address_attr] ]
elif isinstance(user[forward_address_attr], str):
forward_addresses = [ user[forward_address_attr] ]
@@ -236,14 +240,14 @@ class KolabSievemgmt(object):
forward_keepcopy_attr = conf.get('sieve', 'forward_keepcopy_active')
if not forward_keepcopy_attr == None:
- if user.has_key(forward_keepcopy_attr):
+ if forward_keepcopy_attr in user:
forward_keepcopy = utils.true_or_false(user[forward_keepcopy_attr])
else:
forward_keepcopy = False
forward_uce_attr = conf.get('sieve', 'forward_uce_active')
if not forward_uce_attr == None:
- if user.has_key(forward_uce_attr):
+ if forward_uce_attr in user:
forward_uce = utils.true_or_false(user[forward_uce_attr])
else:
forward_uce = False
diff --git a/pykolab/setup/__init__.py b/pykolab/setup/__init__.py
index 52bee91..f23d358 100644
--- a/pykolab/setup/__init__.py
+++ b/pykolab/setup/__init__.py
@@ -30,14 +30,14 @@ to_execute = []
class Setup(object):
def __init__(self):
- import components
+ from . import components
components.__init__()
arg_num = 0
for arg in sys.argv[1:]:
arg_num += 1
if not arg.startswith('-') and len(sys.argv) >= arg_num:
- if components.components.has_key(sys.argv[arg_num].replace('-','_')):
+ if sys.argv[arg_num].replace('-','_') in components.components:
to_execute.append(sys.argv[arg_num].replace('-','_'))
def run(self):
diff --git a/pykolab/setup/components.py b/pykolab/setup/components.py
index a9adbfa..bb01f9c 100644
--- a/pykolab/setup/components.py
+++ b/pykolab/setup/components.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import os
@@ -49,7 +50,7 @@ def __init__():
module_name = filename.replace('.py','')
component_name = module_name.replace('setup_', '')
#print "exec(\"from %s import __init__ as %s_register\"" % (module_name,component_name)
- exec("from %s import __init__ as %s_register" % (module_name,component_name))
+ exec("from .%s import __init__ as %s_register" % (module_name,component_name))
exec("%s_register()" % (component_name))
for dirname in dirnames:
@@ -64,7 +65,7 @@ def list_components(*args, **kw):
__components = {}
- for component in components.keys():
+ for component in components:
if isinstance(component, tuple):
component_group, component = component
__components[component_group] = {
@@ -77,24 +78,24 @@ def list_components(*args, **kw):
_components.sort()
for _component in _components:
- if __components[_component].has_key('function'):
+ if 'function' in __components[_component]:
# This is a top-level component
if not __components[_component]['description'] == None:
- print "%-25s - %s" % (_component.replace('_','-'),__components[_component]['description'])
+ print("%-25s - %s" % (_component.replace('_','-'),__components[_component]['description']))
else:
- print "%-25s" % (_component.replace('_','-'))
+ print("%-25s" % (_component.replace('_','-')))
for _component in _components:
- if not __components[_component].has_key('function'):
+ if 'function' not in __components[_component]:
# This is a nested component
- print "\n" + _("Command Group: %s") % (_component) + "\n"
+ print("\n" + _("Command Group: %s") % (_component) + "\n")
___components = __components[_component].keys()
___components.sort()
for __component in ___components:
if not __components[_component][__component]['description'] == None:
- print "%-4s%-21s - %s" % ('',__component.replace('_','-'),__components[_component][__component]['description'])
+ print("%-4s%-21s - %s" % ('',__component.replace('_','-'),__components[_component][__component]['description']))
else:
- print "%-4s%-21s" % ('',__component.replace('_','-'))
+ print("%-4s%-21s" % ('',__component.replace('_','-')))
def _list_components(*args, **kw):
"""
@@ -104,7 +105,7 @@ def _list_components(*args, **kw):
__components = {}
- for component in components.keys():
+ for component in components:
if isinstance(component, tuple):
component_group, component = component
__components[component_group] = {
@@ -124,20 +125,20 @@ def cli_options_from_component(component_name, *args, **kw):
if component_name in components_included_in_cli:
return
- if components[component_name].has_key('group'):
+ if 'group' in components[component_name]:
group = components[component_name]['group']
component_name = components[component_name]['component_name']
try:
- exec("from %s.setup_%s import cli_options as %s_%s_cli_options" % (group,component_name,group,component_name))
+ exec("from .%s.setup_%s import cli_options as %s_%s_cli_options" % (group,component_name,group,component_name))
exec("%s_%s_cli_options()" % (group,component_name))
- except ImportError, e:
+ except ImportError:
pass
else:
try:
- exec("from setup_%s import cli_options as %s_cli_options" % (component_name,component_name))
+ exec("from .setup_%s import cli_options as %s_cli_options" % (component_name,component_name))
exec("%s_cli_options()" % (component_name))
- except ImportError, e:
+ except ImportError:
pass
components_included_in_cli.append(component_name)
@@ -161,7 +162,7 @@ def execute(component_name, *args, **kw):
execute_this = False
if execute_this:
- if components[component].has_key('after'):
+ if 'after' in components[component]:
for _component in components[component]['after']:
if not _component in executed_components:
execute_this = False
@@ -183,12 +184,12 @@ def execute(component_name, *args, **kw):
for component in _list_components():
cli_options_from_component(component)
- if not components.has_key(component_name):
+ if component_name not in components:
log.error(_("No such component."))
sys.exit(1)
- if not components[component_name].has_key('function') and \
- not components[component_name].has_key('group'):
+ if 'function' not in components[component_name] and \
+ 'group' not in components[component_name]:
log.error(_("No such component."))
sys.exit(1)
@@ -215,7 +216,7 @@ def register_group(dirname, module):
module_name = filename.replace('.py','')
component_name = module_name.replace('setup_', '')
#print "exec(\"from %s.%s import __init__ as %s_%s_register\"" % (module,module_name,module,component_name)
- exec("from %s.%s import __init__ as %s_%s_register" % (module,module_name,module,component_name))
+ exec("from .%s.%s import __init__ as %s_%s_register" % (module,module_name,module,component_name))
exec("%s_%s_register()" % (module,component_name))
def register(component_name, func, group=None, description=None, aliases=[], after=[], before=[]):
@@ -224,10 +225,10 @@ def register(component_name, func, group=None, description=None, aliases=[], aft
else:
component = component_name
- if isinstance(aliases, basestring):
+ if isinstance(aliases, string_types):
aliases = [aliases]
- if components.has_key(component):
+ if component in components:
log.fatal(_("Command '%s' already registered") % (component))
sys.exit(1)
@@ -262,5 +263,5 @@ def register(component_name, func, group=None, description=None, aliases=[], aft
##
def not_yet_implemented(*args, **kw):
- print _("Not yet implemented")
+ print(_("Not yet implemented"))
sys.exit(1)
diff --git a/pykolab/setup/setup_freebusy.py b/pykolab/setup/setup_freebusy.py
index 947e1fb..f492f73 100644
--- a/pykolab/setup/setup_freebusy.py
+++ b/pykolab/setup/setup_freebusy.py
@@ -17,14 +17,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-from ConfigParser import RawConfigParser
+try:
+ from ConfigParser import RawConfigParser
+except ImportError:
+ from configparser import RawConfigParser
import os
import sys
import time
import socket
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
-import components
+from . import components
import pykolab
@@ -164,12 +170,12 @@ def execute(*args, **kw):
cfg_parser = RawConfigParser()
cfg_parser.read('/etc/kolab-freebusy/config.ini')
- for section in freebusy_settings.keys():
- if len(freebusy_settings[section].keys()) < 1:
+ for section in freebusy_settings:
+ if len(freebusy_settings[section]) < 1:
cfg_parser.remove_section(section)
continue
- for key in freebusy_settings[section].keys():
+ for key in freebusy_settings[section]:
if not cfg_parser.has_section(section):
cfg_parser.add_section(section)
diff --git a/pykolab/setup/setup_guam.py b/pykolab/setup/setup_guam.py
index 6a23527..16b407f 100644
--- a/pykolab/setup/setup_guam.py
+++ b/pykolab/setup/setup_guam.py
@@ -23,7 +23,7 @@ import subprocess
import sys
import time
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_imap.py b/pykolab/setup/setup_imap.py
index c55582e..e145c0f 100644
--- a/pykolab/setup/setup_imap.py
+++ b/pykolab/setup/setup_imap.py
@@ -22,7 +22,7 @@ from Cheetah.Template import Template
import os
import subprocess
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_kolabd.py b/pykolab/setup/setup_kolabd.py
index 54892ce..2c4a78e 100644
--- a/pykolab/setup/setup_kolabd.py
+++ b/pykolab/setup/setup_kolabd.py
@@ -20,7 +20,7 @@
import os
import subprocess
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_ldap.py b/pykolab/setup/setup_ldap.py
index 8dc6327..9765545 100644
--- a/pykolab/setup/setup_ldap.py
+++ b/pykolab/setup/setup_ldap.py
@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import ldap
import ldap.modlist
import os
@@ -26,7 +28,7 @@ import subprocess
import tempfile
import time
-import components
+from . import components
import pykolab
@@ -102,7 +104,7 @@ def execute(*args, **kw):
ask_questions = False
if conf.without_ldap:
- print >> sys.stderr, _("Skipping setup of LDAP, as specified")
+ print(_("Skipping setup of LDAP, as specified"), file=sys.stderr)
return
_input = {}
@@ -130,12 +132,12 @@ def execute(*args, **kw):
return
elif conf.with_ad and conf.with_openldap:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
You can not configure Kolab to run against OpenLDAP
and Active Directory simultaneously.
""")
- )
+ ), file=sys.stderr)
sys.exit(1)
@@ -143,7 +145,7 @@ def execute(*args, **kw):
for path, directories, files in os.walk('/etc/dirsrv/'):
for direct in directories:
if direct.startswith('slapd-'):
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
It seems 389 Directory Server has an existing
instance configured. This setup script does not
@@ -151,20 +153,20 @@ def execute(*args, **kw):
make sure /etc/dirsrv/ and /var/lib/dirsrv/ are
clean so that this setup does not have to worry.
""")
- )
+ ), file=sys.stderr)
sys.exit(1)
_input = {}
if ask_questions:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please supply a password for the LDAP administrator user
'admin', used to login to the graphical console of 389
Directory server.
""")
- )
+ ), file=sys.stderr)
_input['admin_pass'] = utils.ask_question(
_("Administrator password"),
@@ -176,14 +178,14 @@ def execute(*args, **kw):
if conf.directory_manager_pwd is not None:
_input['dirmgr_pass'] = conf.directory_manager_pwd
else:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please supply a password for the LDAP Directory Manager
user, which is the administrator user you will be using
to at least initially log in to the Web Admin, and that
Kolab uses to perform administrative tasks.
""")
- )
+ ), file=sys.stderr)
_input['dirmgr_pass'] = utils.ask_question(
_("Directory Manager password"),
@@ -192,13 +194,13 @@ def execute(*args, **kw):
confirm=True
)
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please choose the system user and group the service
should use to run under. These should be existing,
unprivileged, local system POSIX accounts with no shell.
""")
- )
+ ), file=sys.stderr)
try:
pw = pwd.getpwnam("dirsrv")
@@ -241,7 +243,7 @@ def execute(*args, **kw):
_input['rootdn'] = utils.standard_root_dn(_input['domain'])
if ask_questions:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
This setup procedure plans to set up Kolab Groupware for
the following domain name space. This domain name is
@@ -249,7 +251,7 @@ def execute(*args, **kw):
interface. Please confirm this is the appropriate domain
name space.
""")
- )
+ ), file=sys.stderr)
answer = utils.ask_confirmation("%s" % (_input['domain']))
@@ -260,21 +262,21 @@ def execute(*args, **kw):
if not _input['domain'] == None and not _input['domain'] == "":
positive_answer = True
else:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Invalid input. Please try again.
""")
- )
+ ), file=sys.stderr)
_input['nodotdomain'] = _input['domain'].replace('.','_')
_input['rootdn'] = utils.standard_root_dn(_input['domain'])
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
The standard root dn we composed for you follows. Please
confirm this is the root dn you wish to use.
""")
- )
+ ), file=sys.stderr)
answer = utils.ask_confirmation("%s" % (_input['rootdn']))
@@ -285,11 +287,11 @@ def execute(*args, **kw):
if not _input['rootdn'] == None and not _input['rootdn'] == "":
positive_answer = True
else:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Invalid input. Please try again.
""")
- )
+ ), file=sys.stderr)
# TODO: Loudly complain if the fqdn does not resolve back to this system.
@@ -344,13 +346,13 @@ ServerAdminPwd = %(admin_pass)s
'--file=%s' % (filename)
]
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Setup is now going to set up the 389 Directory Server. This
may take a little while (during which period there is no
output and no progress indication).
""")
- )
+ ), file=sys.stderr)
log.info(_("Setting up 389 Directory Server"))
@@ -363,7 +365,7 @@ ServerAdminPwd = %(admin_pass)s
(stdoutdata, stderrdata) = setup_389.communicate()
if not setup_389.returncode == 0:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
An error was detected in the setup procedure for 389
Directory Server. This setup will write out stderr and
@@ -371,7 +373,7 @@ ServerAdminPwd = %(admin_pass)s
/var/log/kolab/setup.out.log respectively, before it
exits.
""")
- )
+ ), file=sys.stderr)
fp = open('/var/log/kolab/setup.error.log', 'w')
fp.write(stderrdata)
@@ -441,7 +443,7 @@ ServerAdminPwd = %(admin_pass)s
"directory server service."))
if ask_questions:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please supply a Cyrus Administrator password. This
password is used by Kolab to execute administrative
@@ -449,7 +451,7 @@ ServerAdminPwd = %(admin_pass)s
yourself to troubleshoot Cyrus IMAP and/or perform
other administrative tasks against Cyrus IMAP directly.
""")
- )
+ ), file=sys.stderr)
_input['cyrus_admin_pass'] = utils.ask_question(
_("Cyrus Administrator password"),
@@ -458,14 +460,14 @@ ServerAdminPwd = %(admin_pass)s
confirm=True
)
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please supply a Kolab Service account password. This
account is used by various services such as Postfix,
and Roundcube, as anonymous binds to the LDAP server
will not be allowed.
""")
- )
+ ), file=sys.stderr)
_input['kolab_service_pass'] = utils.ask_question(
_("Kolab Service password"),
diff --git a/pykolab/setup/setup_manticore.py b/pykolab/setup/setup_manticore.py
index 2f17244..c199ec6 100644
--- a/pykolab/setup/setup_manticore.py
+++ b/pykolab/setup/setup_manticore.py
@@ -26,7 +26,7 @@ import subprocess
import sys
import time
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_mta.py b/pykolab/setup/setup_mta.py
index c3c4154..db8766d 100644
--- a/pykolab/setup/setup_mta.py
+++ b/pykolab/setup/setup_mta.py
@@ -23,7 +23,7 @@ import os
import shutil
import subprocess
-import components
+from . import components
import pykolab
@@ -243,9 +243,9 @@ result_format = "shared+%%s"
)
if not os.path.isdir('/etc/postfix/ldap'):
- os.mkdir('/etc/postfix/ldap/', 0770)
+ os.mkdir('/etc/postfix/ldap/', 0o770)
- for filename in files.keys():
+ for filename in files:
fp = open(filename, 'w')
fp.write(files[filename])
fp.close()
@@ -305,7 +305,7 @@ result_format = "shared+%%s"
setting_base = '/files/etc/postfix/main.cf/'
- for setting_key in postfix_main_settings.keys():
+ for setting_key in postfix_main_settings:
setting = os.path.join(setting_base,setting_key)
current_value = myaugeas.get(setting)
@@ -446,7 +446,10 @@ result_format = "shared+%%s"
myaugeas.close()
if os.path.isfile('/usr/lib/systemd/system/clamd@.service'):
- from ConfigParser import SafeConfigParser
+ try:
+ from ConfigParser import SafeConfigParser
+ except ImportError:
+ from configparser import SafeConfigParser
unitfile = SafeConfigParser()
unitfile.optionxform = str
unitfile.read('/usr/lib/systemd/system/clamd@.service')
diff --git a/pykolab/setup/setup_mysql.py b/pykolab/setup/setup_mysql.py
index 08b7b7c..96ad202 100644
--- a/pykolab/setup/setup_mysql.py
+++ b/pykolab/setup/setup_mysql.py
@@ -17,12 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import os
import subprocess
import tempfile
import time
-import components
+from . import components
import pykolab
@@ -142,12 +144,12 @@ def execute(*args, **kw): # noqa: C901
if answer == "1" or answer == 1:
if not conf.mysqlrootpw:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please supply the root password for MySQL, so we can set
up user accounts for other components that use MySQL.
""")
- )
+ ), file=sys.stderr)
mysql_root_password = utils.ask_question(
_("MySQL root password"),
@@ -161,7 +163,7 @@ def execute(*args, **kw): # noqa: C901
mysql_root_password = 'unix_socket'
else:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please supply a root password for MySQL. This password
will be the administrative user for this MySQL server,
@@ -170,7 +172,7 @@ def execute(*args, **kw): # noqa: C901
about this password, but you will need it for
administrative tasks in MySQL.
""")
- )
+ ), file=sys.stderr)
mysql_root_password = utils.ask_question(
_("MySQL root password"),
@@ -256,7 +258,7 @@ host=%s
fp = open('/tmp/kolab-setup-my.cnf', 'w')
- os.chmod('/tmp/kolab-setup-my.cnf', 0600)
+ os.chmod('/tmp/kolab-setup-my.cnf', 0o600)
fp.write(data)
fp.close()
@@ -276,13 +278,13 @@ host=%s
p1.stdout.close()
p2.communicate()
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please supply a password for the MySQL user 'kolab'.
This password will be used by Kolab services, such as
the Web Administration Panel.
""")
- )
+ ), file=sys.stderr)
mysql_kolab_password = utils.ask_question(
_("MySQL kolab password"),
diff --git a/pykolab/setup/setup_php.py b/pykolab/setup/setup_php.py
index f27dd3f..a8fa654 100644
--- a/pykolab/setup/setup_php.py
+++ b/pykolab/setup/setup_php.py
@@ -17,13 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
from augeas import Augeas
import os
import shutil
import subprocess
import tempfile
-import components
+from . import components
import pykolab
@@ -66,13 +67,13 @@ def description():
def execute(*args, **kw):
if conf.timezone is None:
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
_("""
Please supply the timezone PHP should be using.
You have to use a Continent or Country / City locality name
like 'Europe/Berlin', but not just 'CEST'.
""")
- )
+ ), file=sys.stderr)
conf.timezone = utils.ask_question(
_("Timezone ID"),
diff --git a/pykolab/setup/setup_roundcube.py b/pykolab/setup/setup_roundcube.py
index 47ac8fc..462c23a 100644
--- a/pykolab/setup/setup_roundcube.py
+++ b/pykolab/setup/setup_roundcube.py
@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import codecs
import grp
import hashlib
@@ -29,7 +31,7 @@ import time
from Cheetah.Template import Template
-import components
+from . import components
import pykolab
@@ -51,13 +53,13 @@ def description():
def execute(*args, **kw):
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
"""
Please supply a password for the MySQL user 'roundcube'.
This password will be used by the Roundcube webmail
interface.
"""
- )
+ ), file=sys.stderr)
mysql_roundcube_password = utils.ask_question(
"MySQL roundcube password",
@@ -223,9 +225,9 @@ def execute(*args, **kw):
break
if not os.path.isfile('/tmp/kolab-setup-my.cnf'):
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
"""Please supply the MySQL root password (use 'unix_socket' for socket based authentication)"""
- )
+ ), file=sys.stderr)
mysql_root_password = utils.ask_question(
_("MySQL root password"),
@@ -259,7 +261,7 @@ host=%s
""" % (mysql_root_password, conf.mysqlhost)
fp = open('/tmp/kolab-setup-my.cnf', 'w')
- os.chmod('/tmp/kolab-setup-my.cnf', 0600)
+ os.chmod('/tmp/kolab-setup-my.cnf', 0o600)
fp.write(data)
fp.close()
diff --git a/pykolab/setup/setup_syncroton.py b/pykolab/setup/setup_syncroton.py
index c7c03ce..507ebf8 100644
--- a/pykolab/setup/setup_syncroton.py
+++ b/pykolab/setup/setup_syncroton.py
@@ -17,12 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import os
import subprocess
import sys
import time
-import components
+from . import components
import pykolab
@@ -66,9 +68,9 @@ def execute(*args, **kw):
break
if not os.path.isfile('/tmp/kolab-setup-my.cnf'):
- print >> sys.stderr, utils.multiline_message(
+ print(utils.multiline_message(
"""Please supply the MySQL root password (use 'unix_socket' for socket based authentication)"""
- )
+ ), file=sys.stderr)
mysql_root_password = utils.ask_question(
_("MySQL root password"),
@@ -109,7 +111,7 @@ host=%s
""" % (mysql_root_password, conf.mysqlhost)
fp = open('/tmp/kolab-setup-my.cnf', 'w')
- os.chmod('/tmp/kolab-setup-my.cnf', 0600)
+ os.chmod('/tmp/kolab-setup-my.cnf', 0o600)
fp.write(data)
fp.close()
diff --git a/pykolab/telemetry.py b/pykolab/telemetry.py
index 28b60f9..4ddef32 100644
--- a/pykolab/telemetry.py
+++ b/pykolab/telemetry.py
@@ -19,7 +19,7 @@
#
import os
-import rfc822
+import email.utils as rfc822
import socket
import sys
import time
@@ -642,7 +642,7 @@ def init_db():
try:
metadata.create_all(engine)
- except sqlalchemy.exc.OperationalError, e:
+ except sqlalchemy.exc.OperationalError as e:
log.error(_("Operational Error in telemetry database: %s" % (e)))
Session = sessionmaker(bind=engine)
diff --git a/pykolab/translit.py b/pykolab/translit.py
index 0ff042d..d1c0459 100644
--- a/pykolab/translit.py
+++ b/pykolab/translit.py
@@ -98,7 +98,7 @@ translit_map = {
}
def transliterate(_input, lang, _output_expected=None):
- if locale_translit_map.has_key(lang):
+ if lang in locale_translit_map:
_translit_name = locale_translit_map[lang]
else:
_translit_name = lang
@@ -107,22 +107,22 @@ def transliterate(_input, lang, _output_expected=None):
if not isinstance(_input, unicode):
for char in _input.decode('utf-8'):
- if translit_map.has_key(_translit_name):
- if translit_map[_translit_name].has_key(char):
+ if _translit_name in translit_map:
+ if char in translit_map[_translit_name]:
_output += translit_map[_translit_name][char]
- elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
- _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
+ elif char in [repr(x) for x in translit_map[_translit_name]]:
+ _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name]]][0]]
else:
_output += char
else:
_output += char
else:
for char in _input:
- if translit_map.has_key(_translit_name):
- if translit_map[_translit_name].has_key(char):
+ if _translit_name in translit_map:
+ if char in translit_map[_translit_name]:
_output += translit_map[_translit_name][char]
- elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
- _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
+ elif char in [repr(x) for x in translit_map[_translit_name]]:
+ _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name]]][0]]
else:
_output += char
else:
diff --git a/pykolab/utils.py b/pykolab/utils.py
index bda7e76..e84f13b 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -198,7 +198,7 @@ def ask_menu(question, options={}, default=''):
str_format = "%%%ds" % max_key_length
- if default == '' or default not in options.keys():
+ if default == '' or default not in options:
for key in keys:
if options[key] == key:
print(" - " + key)
@@ -219,10 +219,10 @@ def ask_menu(question, options={}, default=''):
continue
- if answer == '' and default in options.keys():
+ if answer == '' and default in options:
answer = default
- if answer in [str(x) for x in options.keys()]:
+ if answer in [str(x) for x in options]:
answer_correct = True
return answer
diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index 900e280..176ac91 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -1,9 +1,15 @@
import json
-import httplib
+try:
+ import httplib
+except ImportError:
+ import http.client as httplib
import urllib
import sys
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
@@ -70,7 +76,7 @@ def authenticate(username=None, password=None, domain=None):
if not response:
return False
- if response.has_key('session_token'):
+ if 'session_token' in response:
session_id = response['session_token']
return True
@@ -188,35 +194,35 @@ def form_value_select_options(object_type, object_type_id, attribute):
def get_group_input():
group_types = group_types_list()
- if len(group_types.keys()) > 1:
- for key in group_types.keys():
+ if len(group_types) > 1:
+ for key in group_types:
if not key == "status":
- print "%s) %s" % (key,group_types[key]['name'])
+ print("%s) %s" % (key,group_types[key]['name']))
group_type_id = utils.ask_question("Please select the group type")
- elif len(group_types.keys()) > 0:
- print "Automatically selected the only group type available"
+ elif len(group_types) > 0:
+ print("Automatically selected the only group type available")
group_type_id = group_types.keys()[0]
else:
- print "No group types available"
+ print("No group types available")
sys.exit(1)
- if group_types.has_key(group_type_id):
+ if group_type_id in group_types:
group_type_info = group_types[group_type_id]['attributes']
else:
- print "No such group type"
+ print("No such group type")
sys.exit(1)
params = {
'group_type_id': group_type_id
}
- for attribute in group_type_info['form_fields'].keys():
+ for attribute in group_type_info['form_fields']:
params[attribute] = utils.ask_question(attribute)
- for attribute in group_type_info['auto_form_fields'].keys():
+ for attribute in group_type_info['auto_form_fields']:
exec("retval = group_form_value_generate_%s(params)" % (attribute))
params[attribute] = retval[attribute]
@@ -226,26 +232,26 @@ def get_user_input():
user_types = user_types_list()
if user_types['count'] > 1:
- print ""
- for key in user_types['list'].keys():
+ print("")
+ for key in user_types['list']:
if not key == "status":
- print "%s) %s" % (key,user_types['list'][key]['name'])
+ print("%s) %s" % (key,user_types['list'][key]['name']))
- print ""
+ print("")
user_type_id = utils.ask_question("Please select the user type")
elif user_types['count'] > 0:
- print "Automatically selected the only user type available"
+ print("Automatically selected the only user type available")
user_type_id = user_types['list'].keys()[0]
else:
- print "No user types available"
+ print("No user types available")
sys.exit(1)
- if user_types['list'].has_key(user_type_id):
+ if user_type_id in user_types['list']:
user_type_info = user_types['list'][user_type_id]['attributes']
else:
- print "No such user type"
+ print("No such user type")
sys.exit(1)
params = {
@@ -256,9 +262,9 @@ def get_user_input():
must_attrs = []
may_attrs = []
- for attribute in user_type_info['form_fields'].keys():
+ for attribute in user_type_info['form_fields']:
if isinstance(user_type_info['form_fields'][attribute], dict):
- if user_type_info['form_fields'][attribute].has_key('optional') and user_type_info['form_fields'][attribute]['optional']:
+ if 'optional' in user_type_info['form_fields'][attribute] and user_type_info['form_fields'][attribute]['optional']:
may_attrs.append(attribute)
else:
must_attrs.append(attribute)
@@ -267,14 +273,14 @@ def get_user_input():
for attribute in must_attrs:
if isinstance(user_type_info['form_fields'][attribute], dict) and \
- user_type_info['form_fields'][attribute].has_key('type'):
+ 'type' in user_type_info['form_fields'][attribute]:
if user_type_info['form_fields'][attribute]['type'] == 'select':
- if not user_type_info['form_fields'][attribute].has_key('values'):
+ if 'values' not in user_type_info['form_fields'][attribute]:
attribute_values = form_value_select_options('user', user_type_id, attribute)
default = ''
- if attribute_values[attribute].has_key('default'):
+ if 'default' in attribute_values[attribute]:
default = attribute_values[attribute]['default']
params[attribute] = utils.ask_menu(
@@ -285,7 +291,7 @@ def get_user_input():
else:
default = ''
- if user_type_info['form_fields'][attribute].has_key('default'):
+ if 'default' in user_type_info['form_fields'][attribute]:
default = user_type_info['form_fields'][attribute]['default']
params[attribute] = utils.ask_menu(
@@ -300,11 +306,11 @@ def get_user_input():
else:
params[attribute] = utils.ask_question(attribute)
- for attribute in user_type_info['fields'].keys():
+ for attribute in user_type_info['fields']:
params[attribute] = user_type_info['fields'][attribute]
exec("retval = user_form_value_generate(params)")
- print retval
+ print(retval)
return params
@@ -337,7 +343,7 @@ def group_form_value_generate_mail(params=None):
def group_find(params=None):
post = { 'search': { 'params': {} } }
- for (k,v) in params.iteritems():
+ for (k,v) in params.items():
post['search']['params'][k] = { 'value': v, 'type': 'exact' }
return request('POST', 'group.find', post=json.dumps(post))
@@ -371,7 +377,7 @@ def ou_edit(params={}):
def ou_find(params=None):
post = { 'search': { 'params': {} } }
- for (k,v) in params.iteritems():
+ for (k,v) in params.items():
post['search']['params'][k] = { 'value': v, 'type': 'exact' }
return request('POST', 'ou.find', post=json.dumps(post))
@@ -436,7 +442,7 @@ def request_raw(method, api_uri, get=None, post=None, headers={}, isretry=False)
try:
response_data = json.loads(data)
- except ValueError, e:
+ except ValueError:
# Some data is not JSON
log.error(_("Response data is not JSON"))
@@ -459,7 +465,7 @@ def resource_delete(params=None):
def resource_find(params=None):
post = { 'search': { 'params': {} } }
- for (k,v) in params.iteritems():
+ for (k,v) in params.items():
post['search']['params'][k] = { 'value': v, 'type': 'exact' }
return request('POST', 'resource.find', post=json.dumps(post))
@@ -497,7 +503,7 @@ def role_delete(params=None):
'role': role.keys()[0]
}
- if not params.has_key('role'):
+ if 'role' not in params:
role = role_find_by_attribute(params)
params = {
'role': role.keys()[0]
@@ -591,7 +597,7 @@ def user_edit(user = None, attributes={}):
user_info = request('GET', 'user.info', get=get)
- for attribute in attributes.keys():
+ for attribute in attributes:
user_info[attribute] = attributes[attribute]
post = json.dumps(user_info)
@@ -615,7 +621,7 @@ def user_find(attribs=None):
else:
post = { 'search': { 'params': {} } }
- for (k,v) in attribs.iteritems():
+ for (k,v) in attribs.items():
post['search']['params'][k] = { 'value': v, 'type': 'exact' }
post = json.dumps(post)
diff --git a/pykolab/xml/__init__.py b/pykolab/xml/__init__.py
index 99a269b..12ac4e6 100644
--- a/pykolab/xml/__init__.py
+++ b/pykolab/xml/__init__.py
@@ -1,37 +1,37 @@
-from attendee import Attendee
-from attendee import InvalidAttendeeParticipantStatusError
-from attendee import participant_status_label
+from .attendee import Attendee
+from .attendee import InvalidAttendeeParticipantStatusError
+from .attendee import participant_status_label
-from contact import Contact
-from contact import ContactIntegrityError
-from contact import contact_from_string
-from contact import contact_from_message
-from contact_reference import ContactReference
-from recurrence_rule import RecurrenceRule
+from .contact import Contact
+from .contact import ContactIntegrityError
+from .contact import contact_from_string
+from .contact import contact_from_message
+from .contact_reference import ContactReference
+from .recurrence_rule import RecurrenceRule
-from event import Event
-from event import EventIntegrityError
-from event import InvalidEventDateError
-from event import InvalidEventStatusError
-from event import event_from_ical
-from event import event_from_string
-from event import event_from_message
+from .event import Event
+from .event import EventIntegrityError
+from .event import InvalidEventDateError
+from .event import InvalidEventStatusError
+from .event import event_from_ical
+from .event import event_from_string
+from .event import event_from_message
-from todo import Todo
-from todo import TodoIntegrityError
-from todo import todo_from_ical
-from todo import todo_from_string
-from todo import todo_from_message
+from .todo import Todo
+from .todo import TodoIntegrityError
+from .todo import todo_from_ical
+from .todo import todo_from_string
+from .todo import todo_from_message
-from note import Note
-from note import NoteIntegrityError
-from note import note_from_string
-from note import note_from_message
+from .note import Note
+from .note import NoteIntegrityError
+from .note import note_from_string
+from .note import note_from_message
-from utils import property_label
-from utils import property_to_string
-from utils import compute_diff
-from utils import to_dt
+from .utils import property_label
+from .utils import property_to_string
+from .utils import compute_diff
+from .utils import to_dt
__all__ = [
"Attendee",
diff --git a/pykolab/xml/attendee.py b/pykolab/xml/attendee.py
index 41447db..cd8458f 100644
--- a/pykolab/xml/attendee.py
+++ b/pykolab/xml/attendee.py
@@ -3,7 +3,7 @@ import kolabformat
from pykolab.translate import _
from pykolab.translate import N_
-from contact_reference import ContactReference
+from .contact_reference import ContactReference
participant_status_labels = {
"NEEDS-ACTION": N_("Needs Action"),
@@ -25,7 +25,7 @@ participant_status_labels = {
}
def participant_status_label(status):
- return _(participant_status_labels[status]) if participant_status_labels.has_key(status) else _(status)
+ return _(participant_status_labels[status]) if status in participant_status_labels else _(status)
class Attendee(kolabformat.Attendee):
@@ -92,7 +92,7 @@ class Attendee(kolabformat.Attendee):
if isinstance(rsvp, bool):
self.setRSVP(rsvp)
else:
- if self.rsvp_map.has_key(rsvp):
+ if rsvp in self.rsvp_map:
self.setRSVP(self.rsvp_map[rsvp])
if not role == None:
@@ -101,10 +101,10 @@ class Attendee(kolabformat.Attendee):
if not cutype == None:
self.set_cutype(cutype)
- if ical_params and ical_params.has_key('DELEGATED-FROM'):
+ if ical_params and 'DELEGATED-FROM' in ical_params:
self.delegate_from(Attendee(str(ical_params['DELEGATED-FROM']), role=self.get_role(), cutype=self.get_cutype()))
- if ical_params and ical_params.has_key('DELEGATED-TO'):
+ if ical_params and 'DELEGATED-TO' in ical_params:
self.delegate_to(Attendee(str(ical_params['DELEGATED-TO'])))
if not participant_status == None:
@@ -132,14 +132,14 @@ class Attendee(kolabformat.Attendee):
for delegator in delegators:
if not isinstance(delegator, Attendee):
- raise ValueError, _("Not a valid attendee")
+ raise ValueError(_("Not a valid attendee"))
else:
self.set_role(delegator.get_role())
self.set_cutype(delegator.get_cutype())
crefs.append(delegator.contactreference)
if len(crefs) == 0:
- raise ValueError, _("No valid delegator references found")
+ raise ValueError(_("No valid delegator references found"))
else:
crefs += self.get_delegated_from()
@@ -154,12 +154,12 @@ class Attendee(kolabformat.Attendee):
for delegatee in delegatees:
if not isinstance(delegatee, Attendee):
- raise ValueError, _("Not a valid attendee")
+ raise ValueError(_("Not a valid attendee"))
else:
crefs.append(delegatee.contactreference)
if len(crefs) == 0:
- raise ValueError, _("No valid delegatee references found")
+ raise ValueError(_("No valid delegatee references found"))
else:
crefs += self.get_delegated_to()
@@ -210,36 +210,36 @@ class Attendee(kolabformat.Attendee):
return self.rsvp()
def _translate_value(self, val, map):
- name_map = dict([(v, k) for (k, v) in map.iteritems()])
- return name_map[val] if name_map.has_key(val) else 'UNKNOWN'
+ name_map = dict([(v, k) for (k, v) in map.items()])
+ return name_map[val] if val in name_map else 'UNKNOWN'
def set_cutype(self, cutype):
- if cutype in self.cutype_map.keys():
+ if cutype in self.cutype_map:
self.setCutype(self.cutype_map[cutype])
elif cutype in self.cutype_map.values():
self.setCutype(cutype)
else:
- raise InvalidAttendeeCutypeError, _("Invalid cutype %r") % (cutype)
+ raise InvalidAttendeeCutypeError(_("Invalid cutype %r") % (cutype))
def set_name(self, name):
self.contactreference.set_name(name)
self.setContact(self.contactreference)
def set_participant_status(self, participant_status):
- if participant_status in self.participant_status_map.keys():
+ if participant_status in self.participant_status_map:
self.setPartStat(self.participant_status_map[participant_status])
elif participant_status in self.participant_status_map.values():
self.setPartStat(participant_status)
else:
- raise InvalidAttendeeParticipantStatusError, _("Invalid participant status %r") % (participant_status)
+ raise InvalidAttendeeParticipantStatusError(_("Invalid participant status %r") % (participant_status))
def set_role(self, role):
- if role in self.role_map.keys():
+ if role in self.role_map:
self.setRole(self.role_map[role])
elif role in self.role_map.values():
self.setRole(role)
else:
- raise InvalidAttendeeRoleError, _("Invalid role %r") % (role)
+ raise InvalidAttendeeRoleError(_("Invalid role %r") % (role))
def set_rsvp(self, rsvp):
self.setRSVP(rsvp)
@@ -248,7 +248,7 @@ class Attendee(kolabformat.Attendee):
data = self.contactreference.to_dict()
data.pop('type', None)
- for p, getter in self.properties_map.iteritems():
+ for p, getter in self.properties_map.items():
val = None
args = {}
if hasattr(self, getter):
diff --git a/pykolab/xml/contact.py b/pykolab/xml/contact.py
index 2b08f9a..9a6fd99 100644
--- a/pykolab/xml/contact.py
+++ b/pykolab/xml/contact.py
@@ -1,3 +1,5 @@
+from six import string_types
+
import kolabformat
import datetime
import pytz
@@ -23,7 +25,7 @@ def contact_from_message(message):
contact = contact_from_string(payload)
# append attachment parts to Contact object
- elif contact and part.has_key('Content-ID'):
+ elif contact and 'Content-ID' in part:
contact._attachment_parts.append(part)
return contact
@@ -133,13 +135,13 @@ class Contact(kolabformat.Contact):
return [x for x in self.emailAddresses()]
def set_email(self, email, preferred_index=0):
- if isinstance(email, basestring):
+ if isinstance(email, string_types):
self.setEmailAddresses([email], preferred_index)
else:
self.setEmailAddresses(email, preferred_index)
def add_email(self, email):
- if isinstance(email, basestring):
+ if isinstance(email, string_types):
self.add_emails([email])
elif isinstance(email, list):
self.add_emails(email)
@@ -160,8 +162,8 @@ class Contact(kolabformat.Contact):
return _gender
def _translate_value(self, val, map):
- name_map = dict([(v, k) for (k, v) in map.iteritems()])
- return name_map[val] if name_map.has_key(val) else 'UNKNOWN'
+ name_map = dict([(v, k) for (k, v) in map.items()])
+ return name_map[val] if val in name_map else 'UNKNOWN'
def to_dict(self):
if not self.isValid():
@@ -169,7 +171,7 @@ class Contact(kolabformat.Contact):
data = self._names2dict(self.nameComponents())
- for p, getter in self.properties_map.iteritems():
+ for p, getter in self.properties_map.items():
val = None
if hasattr(self, getter):
val = getattr(self, getter)()
@@ -198,7 +200,7 @@ class Contact(kolabformat.Contact):
affiliations = self.affiliations()
if len(affiliations) > 0:
_affiliation = self._affiliation2dict(affiliations[0])
- if _affiliation.has_key('address'):
+ if 'address' in _affiliation:
data['address'].extend(_affiliation['address'])
_affiliation.pop('address', None)
data.update(_affiliation)
@@ -223,7 +225,7 @@ class Contact(kolabformat.Contact):
data = dict()
- for p, getter in names_map.iteritems():
+ for p, getter in names_map.items():
val = None
if hasattr(namecomp, getter):
val = getattr(namecomp, getter)()
@@ -243,7 +245,7 @@ class Contact(kolabformat.Contact):
data = dict()
- for p, getter in props_map.iteritems():
+ for p, getter in props_map.items():
val = None
if hasattr(affiliation, getter):
val = getattr(affiliation, getter)()
@@ -269,7 +271,7 @@ class Contact(kolabformat.Contact):
'code': 'code',
'country': 'country',
}
- addresstype_map = dict([(v, k) for (k, v) in self.addresstype_map.iteritems()])
+ addresstype_map = dict([(v, k) for (k, v) in self.addresstype_map.items()])
data = dict()
@@ -279,7 +281,7 @@ class Contact(kolabformat.Contact):
if adrtype is not None:
data['type'] = adrtype
- for p, getter in props_map.iteritems():
+ for p, getter in props_map.items():
val = None
if hasattr(adr, getter):
val = getattr(adr, getter)()
@@ -293,13 +295,13 @@ class Contact(kolabformat.Contact):
def _relateds2dict(self, relateds, aslist=True):
data = dict()
- related_map = dict([(v, k) for (k, v) in self.related_map.iteritems()])
+ related_map = dict([(v, k) for (k, v) in self.related_map.items()])
for rel in relateds:
reltype = related_map.get(rel.relationTypes(), None)
val = rel.uri() if rel.type() == kolabformat.Related.Uid else rel.text()
if reltype and val is not None:
if aslist:
- if not data.has_key(reltype):
+ if reltype not in data:
data[reltype] = []
data[reltype].append(val)
else:
@@ -308,7 +310,7 @@ class Contact(kolabformat.Contact):
return data
def _struct2dict(self, struct, propname, map):
- type_map = dict([(v, k) for (k, v) in map.iteritems()])
+ type_map = dict([(v, k) for (k, v) in map.items()])
result = dict()
if hasattr(struct, 'types'):
@@ -328,7 +330,7 @@ class Contact(kolabformat.Contact):
if error == None or not error:
return xml
else:
- raise ContactIntegrityError, kolabformat.errorMessage()
+ raise ContactIntegrityError(kolabformat.errorMessage())
class ContactIntegrityError(Exception):
diff --git a/pykolab/xml/contact_reference.py b/pykolab/xml/contact_reference.py
index 42d9919..6b40817 100644
--- a/pykolab/xml/contact_reference.py
+++ b/pykolab/xml/contact_reference.py
@@ -44,7 +44,7 @@ class ContactReference(kolabformat.ContactReference):
def to_dict(self):
data = dict()
- for p, getter in self.properties_map.iteritems():
+ for p, getter in self.properties_map.items():
val = None
if hasattr(self, getter):
val = getattr(self, getter)()
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 276bb6f..cfd9289 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -1,3 +1,5 @@
+from six import string_types
+
import datetime
import icalendar
import kolabformat
@@ -16,9 +18,9 @@ from pykolab.xml.utils import ustr
from pykolab.translate import _
from os import path
-from attendee import Attendee
-from contact_reference import ContactReference
-from recurrence_rule import RecurrenceRule
+from .attendee import Attendee
+from .contact_reference import ContactReference
+from .recurrence_rule import RecurrenceRule
from collections import OrderedDict
log = pykolab.getLogger('pykolab.xml_event')
@@ -39,7 +41,7 @@ def event_from_message(message):
event = event_from_string(payload)
# append attachment parts to Event object
- elif event and part.has_key('Content-ID'):
+ elif event and 'Content-ID' in part:
event._attachment_parts.append(part)
return event
@@ -166,7 +168,7 @@ class Event(object):
valid_datetime = True
if not valid_datetime:
- raise InvalidEventDateError, _("Rdate needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime))
+ raise InvalidEventDateError(_("Rdate needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime)))
self.event.addRecurrenceDate(xmlutils.to_cdatetime(_datetime, True))
@@ -183,14 +185,14 @@ class Event(object):
valid_datetime = True
if not valid_datetime:
- raise InvalidEventDateError, _("Exdate needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime))
+ raise InvalidEventDateError(_("Exdate needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime)))
self.event.addExceptionDate(xmlutils.to_cdatetime(_datetime, True))
def add_exception(self, exception):
recurrence_id = exception.get_recurrence_id()
if recurrence_id is None:
- raise EventIntegrityError, "Recurrence exceptions require a Recurrence-ID property"
+ raise EventIntegrityError("Recurrence exceptions require a Recurrence-ID property")
# check if an exception with the given recurrence-id already exists
append = True
@@ -218,7 +220,7 @@ class Event(object):
def del_exception(self, exception):
recurrence_id = exception.get_recurrence_id()
if recurrence_id is None:
- raise EventIntegrityError, "Recurrence exceptions require a Recurrence-ID property"
+ raise EventIntegrityError("Recurrence exceptions require a Recurrence-ID property")
updated = False
vexceptions = self.event.exceptions()
@@ -353,7 +355,7 @@ class Event(object):
break
# use the libkolab calendaring bindings to load the full iCal data
- if ical_event.has_key('RRULE') or ical_event.has_key('ATTACH') \
+ if 'RRULE' in ical_event or 'ATTACH' in ical_event \
or [part for part in ical_event.walk() if part.name == 'VALARM']:
if raw is None or raw == "":
raw = ical if isinstance(ical, str) else ical.to_ical()
@@ -364,20 +366,20 @@ class Event(object):
# TODO: Clause the timestamps for zulu suffix causing datetime.datetime
# to fail substitution.
for attr in list(set(ical_event.required)):
- if ical_event.has_key(attr):
+ if attr in ical_event:
self.set_from_ical(attr.lower(), ical_event[attr])
# NOTE: Make sure to list(set()) or duplicates may arise
# NOTE: Keep the original order e.g. to read DTSTART before RECURRENCE-ID
for attr in list(OrderedDict.fromkeys(ical_event.singletons)):
- if ical_event.has_key(attr):
+ if attr in ical_event:
if isinstance(ical_event[attr], list):
ical_event[attr] = ical_event[attr][0];
self.set_from_ical(attr.lower(), ical_event[attr])
# NOTE: Make sure to list(set()) or duplicates may arise
for attr in list(set(ical_event.multiple)):
- if ical_event.has_key(attr):
+ if attr in ical_event:
self.set_from_ical(attr.lower(), ical_event[attr])
def _xml_from_ical(self, ical):
@@ -394,7 +396,7 @@ class Event(object):
return attendee.get_participant_status()
def get_attendee(self, attendee):
- if isinstance(attendee, basestring):
+ if isinstance(attendee, string_types):
if attendee in [x.get_email() for x in self.get_attendees()]:
attendee = self.get_attendee_by_email(attendee)
@@ -402,7 +404,7 @@ class Event(object):
attendee = self.get_attendee_by_name(attendee)
else:
- raise ValueError, _("No attendee with email or name %r") %(attendee)
+ raise ValueError(_("No attendee with email or name %r") %(attendee))
return attendee
@@ -410,7 +412,7 @@ class Event(object):
return attendee
else:
- raise ValueError, _("Invalid argument value attendee %r, must be basestring or Attendee") % (attendee)
+ raise ValueError(_("Invalid argument value attendee %r, must be basestring or Attendee") % (attendee))
def find_attendee(self, attendee):
try:
@@ -422,13 +424,13 @@ class Event(object):
if email in [x.get_email() for x in self.get_attendees()]:
return [x for x in self.get_attendees() if x.get_email() == email][0]
- raise ValueError, _("No attendee with email %r") %(email)
+ raise ValueError(_("No attendee with email %r") %(email))
def get_attendee_by_name(self, name):
if name in [x.get_name() for x in self.get_attendees()]:
return [x for x in self.get_attendees() if x.get_name() == name][0]
- raise ValueError, _("No attendee with name %r") %(name)
+ raise ValueError(_("No attendee with name %r") %(name))
def get_attendees(self):
return self._attendees
@@ -551,31 +553,31 @@ class Event(object):
delegators = attendee.get_delegated_from()
delegatees = attendee.get_delegated_to()
- if rsvp in attendee.rsvp_map.keys():
+ if rsvp in attendee.rsvp_map:
_rsvp = rsvp
elif rsvp in attendee.rsvp_map.values():
- _rsvp = [k for k, v in attendee.rsvp_map.iteritems() if v == rsvp][0]
+ _rsvp = [k for k, v in attendee.rsvp_map.items() if v == rsvp][0]
else:
_rsvp = None
- if role in attendee.role_map.keys():
+ if role in attendee.role_map:
_role = role
elif role in attendee.role_map.values():
- _role = [k for k, v in attendee.role_map.iteritems() if v == role][0]
+ _role = [k for k, v in attendee.role_map.items() if v == role][0]
else:
_role = None
- if partstat in attendee.participant_status_map.keys():
+ if partstat in attendee.participant_status_map:
_partstat = partstat
elif partstat in attendee.participant_status_map.values():
- _partstat = [k for k, v in attendee.participant_status_map.iteritems() if v == partstat][0]
+ _partstat = [k for k, v in attendee.participant_status_map.items() if v == partstat][0]
else:
_partstat = None
- if cutype in attendee.cutype_map.keys():
+ if cutype in attendee.cutype_map:
_cutype = cutype
elif cutype in attendee.cutype_map.values():
- _cutype = [k for k, v in attendee.cutype_map.iteritems() if v == cutype][0]
+ _cutype = [k for k, v in attendee.cutype_map.items() if v == cutype][0]
else:
_cutype = None
@@ -608,12 +610,12 @@ class Event(object):
def get_ical_attendee_participant_status(self, attendee):
attendee = self.get_attendee(attendee)
- if attendee.get_participant_status() in attendee.participant_status_map.keys():
+ if attendee.get_participant_status() in attendee.participant_status_map:
return attendee.get_participant_status()
elif attendee.get_participant_status() in attendee.participant_status_map.values():
- return [k for k, v in attendee.participant_status_map.iteritems() if v == attendee.get_participant_status()][0]
+ return [k for k, v in attendee.participant_status_map.items() if v == attendee.get_participant_status()][0]
else:
- raise ValueError, _("Invalid participant status")
+ raise ValueError(_("Invalid participant status"))
def get_ical_created(self):
return self.get_created()
@@ -652,7 +654,7 @@ class Event(object):
def get_ical_status(self):
status = self.event.status()
- if status in self.status_map.keys():
+ if status in self.status_map:
return status
return self._translate_value(status, self.status_map) if status else None
@@ -814,12 +816,12 @@ class Event(object):
self.event.setAttendees(self._attendees)
def set_classification(self, classification):
- if classification in self.classification_map.keys():
+ if classification in self.classification_map:
self.event.setClassification(self.classification_map[classification])
elif classification in self.classification_map.values():
self.event.setClassification(classification)
else:
- raise ValueError, _("Invalid classification %r") % (classification)
+ raise ValueError(_("Invalid classification %r") % (classification))
def set_created(self, _datetime=None):
if _datetime is None or isinstance(_datetime, datetime.time):
@@ -850,7 +852,7 @@ class Event(object):
valid_datetime = True
if not valid_datetime:
- raise InvalidEventDateError, _("Event end needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime))
+ raise InvalidEventDateError(_("Event end needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime)))
self.event.setEnd(xmlutils.to_cdatetime(_datetime, True))
@@ -864,7 +866,7 @@ class Event(object):
def add_custom_property(self, name, value):
if not name.upper().startswith('X-'):
- raise ValueError, _("Invalid custom property name %r") % (name)
+ raise ValueError(_("Invalid custom property name %r") % (name))
props = self.event.customProperties()
props.append(kolabformat.CustomProperty(name.upper(), value))
@@ -892,7 +894,7 @@ class Event(object):
getattr(self, default_setter)(value)
def set_ical_attendee(self, _attendee):
- if isinstance(_attendee, basestring):
+ if isinstance(_attendee, string_types):
_attendee = [_attendee]
if isinstance(_attendee, list):
@@ -904,27 +906,27 @@ class Event(object):
else:
params = {}
- if params.has_key('CN'):
+ if 'CN' in params:
name = ustr(params['CN'])
else:
name = None
- if params.has_key('ROLE'):
+ if 'ROLE' in params:
role = params['ROLE']
else:
role = None
- if params.has_key('PARTSTAT'):
+ if 'PARTSTAT' in params:
partstat = params['PARTSTAT']
else:
partstat = None
- if params.has_key('RSVP'):
+ if 'RSVP' in params:
rsvp = params['RSVP']
else:
rsvp = None
- if params.has_key('CUTYPE'):
+ if 'CUTYPE' in params:
cutype = params['CUTYPE']
else:
cutype = kolabformat.CutypeIndividual
@@ -963,7 +965,7 @@ class Event(object):
else:
params = {}
- if params.has_key('CN'):
+ if 'CN' in params:
cn = ustr(params['CN'])
self.set_organizer(str(address), name=cn)
@@ -1001,7 +1003,7 @@ class Event(object):
try:
self.thisandfuture = params.get('RANGE', '') == 'THISANDFUTURE'
self.set_recurrence_id(value, self.thisandfuture)
- except InvalidEventDateError, e:
+ except InvalidEventDateError:
pass
def set_lastmodified(self, _datetime=None):
@@ -1017,7 +1019,7 @@ class Event(object):
_datetime = datetime.datetime.utcnow()
if not valid_datetime:
- raise InvalidEventDateError, _("Event last-modified needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime))
+ raise InvalidEventDateError(_("Event last-modified needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime)))
self.event.setLastModified(xmlutils.to_cdatetime(_datetime, False, True))
@@ -1060,17 +1062,17 @@ class Event(object):
valid_datetime = True
if not valid_datetime:
- raise InvalidEventDateError, _("Event start needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime))
+ raise InvalidEventDateError(_("Event start needs datetime.date or datetime.datetime instance, got %r") % (type(_datetime)))
self.event.setStart(xmlutils.to_cdatetime(_datetime, True))
def set_status(self, status):
- if status in self.status_map.keys():
+ if status in self.status_map:
self.event.setStatus(self.status_map[status])
elif status in self.status_map.values():
self.event.setStatus(status)
elif not status == kolabformat.StatusUndefined:
- raise InvalidEventStatusError, _("Invalid status set: %r") % (status)
+ raise InvalidEventStatusError(_("Invalid status set: %r") % (status))
def set_summary(self, summary):
self.event.setSummary(summary)
@@ -1093,7 +1095,7 @@ class Event(object):
valid_datetime = True
if not valid_datetime:
- raise InvalidEventDateError, _("Event recurrence-id needs datetime.datetime instance")
+ raise InvalidEventDateError(_("Event recurrence-id needs datetime.datetime instance"))
if _thisandfuture is None:
_thisandfuture = self.thisandfuture
@@ -1111,12 +1113,12 @@ class Event(object):
if error == None or not error:
return event_xml
else:
- raise EventIntegrityError, kolabformat.errorMessage()
+ raise EventIntegrityError(kolabformat.errorMessage())
def to_dict(self):
data = dict()
- for p, getter in self.properties_map.iteritems():
+ for p, getter in self.properties_map.items():
val = None
if hasattr(self, getter):
val = getattr(self, getter)()
@@ -1176,8 +1178,8 @@ class Event(object):
return ret
def _translate_value(self, val, map):
- name_map = dict([(v, k) for (k, v) in map.iteritems()])
- return name_map[val] if name_map.has_key(val) else 'UNKNOWN'
+ name_map = dict([(v, k) for (k, v) in map.items()])
+ return name_map[val] if val in name_map else 'UNKNOWN'
def to_message(self, creator=None):
from email.MIMEMultipart import MIMEMultipart
@@ -1273,7 +1275,7 @@ class Event(object):
from email import charset
charset.add_charset('utf-8', charset.SHORTEST, charset.QP)
- msg = MIMEMultipart()
+ msg = MIMEMultipart("alternative")
msg_from = None
attendees = None
@@ -1353,7 +1355,6 @@ class Event(object):
part.set_payload(self.as_string_itip(method=method))
- part.add_header('Content-Disposition', 'attachment; filename="event.ics"')
part.add_header('Content-Transfer-Encoding', '8bit')
msg.attach(part)
diff --git a/pykolab/xml/note.py b/pykolab/xml/note.py
index 0fc7c24..936315b 100644
--- a/pykolab/xml/note.py
+++ b/pykolab/xml/note.py
@@ -19,7 +19,7 @@ def note_from_message(message):
note = note_from_string(payload)
# append attachment parts to Note object
- elif note and part.has_key('Content-ID'):
+ elif note and 'Content-ID' in part:
note._attachment_parts.append(part)
return note
@@ -86,12 +86,12 @@ class Note(kolabformat.Note):
return _class
def set_classification(self, classification):
- if classification in self.classification_map.keys():
+ if classification in self.classification_map:
self.setClassification(self.classification_map[classification])
elif classification in self.classification_map.values():
self.setClassification(status)
else:
- raise ValueError, _("Invalid classification %r") % (classification)
+ raise ValueError(_("Invalid classification %r") % (classification))
def add_category(self, category):
_categories = self.categories()
@@ -99,8 +99,8 @@ class Note(kolabformat.Note):
self.setCategories(_categories)
def _translate_value(self, val, map):
- name_map = dict([(v, k) for (k, v) in map.iteritems()])
- return name_map[val] if name_map.has_key(val) else 'UNKNOWN'
+ name_map = dict([(v, k) for (k, v) in map.items()])
+ return name_map[val] if val in name_map else 'UNKNOWN'
def to_dict(self):
if not self.isValid():
@@ -108,7 +108,7 @@ class Note(kolabformat.Note):
data = dict()
- for p, getter in self.properties_map.iteritems():
+ for p, getter in self.properties_map.items():
val = None
if hasattr(self, getter):
val = getattr(self, getter)()
@@ -131,7 +131,7 @@ class Note(kolabformat.Note):
if error == None or not error:
return xml
else:
- raise NoteIntegrityError, kolabformat.errorMessage()
+ raise NoteIntegrityError(kolabformat.errorMessage())
class NoteIntegrityError(Exception):
def __init__(self, message):
diff --git a/pykolab/xml/recurrence_rule.py b/pykolab/xml/recurrence_rule.py
index 6f6c7d8..cbe164d 100644
--- a/pykolab/xml/recurrence_rule.py
+++ b/pykolab/xml/recurrence_rule.py
@@ -48,7 +48,7 @@ frequency_labels = {
}
def frequency_label(freq):
- return _(frequency_labels[freq]) if frequency_labels.has_key(freq) else _(freq)
+ return _(frequency_labels[freq]) if freq in frequency_labels else _(freq)
class RecurrenceRule(kolabformat.RecurrenceRule):
@@ -114,11 +114,11 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
}
for prop,setter in vectorimap.items():
- if vrecur.has_key(prop):
+ if prop in vrecur:
getattr(self, setter)([int(v) for v in vrecur[prop]])
for prop,setter in settermap.items():
- if vrecur.has_key(prop):
+ if prop in vrecur:
getattr(self, setter)(vrecur[prop])
def set_count(self, count):
@@ -150,7 +150,7 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
occurrence = int(wday.relative)
if str(wday)[0] == '-':
occurrence = occurrence * -1
- if self.weekday_map.has_key(weekday):
+ if weekday in self.weekday_map:
daypos.append(kolabformat.DayPos(occurrence, self.weekday_map[weekday]))
self.setByday(daypos)
@@ -175,14 +175,14 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
def _set_map_value(self, val, pmap, setter):
if isinstance(val, list):
val = val[0]
- if val in pmap.keys():
+ if val in pmap:
getattr(self, setter)(pmap[val])
elif val in pmap.values():
getattr(self, setter)(val)
def _translate_value(self, val, map):
- name_map = dict([(v, k) for (k, v) in map.iteritems()])
- return name_map[val] if name_map.has_key(val) else 'UNKNOWN'
+ name_map = dict([(v, k) for (k, v) in map.items()])
+ return name_map[val] if val in name_map else 'UNKNOWN'
def to_ical(self):
rrule = icalendar.vRecur(dict((k,v) for k,v in self.to_dict(True).items() if not (type(v) == str and v == '' or type(v) == list and len(v) == 0)))
@@ -194,7 +194,7 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
data = dict()
- for p, getter in self.properties_map.iteritems():
+ for p, getter in self.properties_map.items():
val = None
args = {}
if hasattr(self, getter):
diff --git a/pykolab/xml/todo.py b/pykolab/xml/todo.py
index ccd798f..effb8be 100644
--- a/pykolab/xml/todo.py
+++ b/pykolab/xml/todo.py
@@ -29,7 +29,7 @@ def todo_from_message(message):
todo = todo_from_string(payload)
# append attachment parts to Todo object
- elif todo and part.has_key('Content-ID'):
+ elif todo and 'Content-ID' in part:
todo._attachment_parts.append(part)
return todo
@@ -82,11 +82,11 @@ class Todo(Event):
ical_todo = c
break
- log.debug("Todo.from_ical(); %r, %r, %r" % (type(ical_todo), ical_todo.has_key('ATTACH'), ical_todo.has_key('ATTENDEE')), level=8)
+ log.debug("Todo.from_ical(); %r, %r, %r" % (type(ical_todo), 'ATTACH' in ical_todo, 'ATTENDEE' in ical_todo), level=8)
# DISABLED: use the libkolab calendaring bindings to load the full iCal data
# TODO: this requires support for iCal parsing in the kolab.calendaring bindings
- if False and ical_todo.has_key('ATTACH') or [part for part in ical_todo.walk() if part.name == 'VALARM']:
+ if False and 'ATTACH' in ical_todo or [part for part in ical_todo.walk() if part.name == 'VALARM']:
if raw is None or raw == "":
raw = ical if isinstance(ical, str) else ical.to_ical()
self._xml_from_ical(raw)
@@ -94,21 +94,21 @@ class Todo(Event):
self.event = kolabformat.Todo()
for attr in list(set(ical_todo.required)):
- if ical_todo.has_key(attr):
+ if attr in ical_todo:
self.set_from_ical(attr.lower(), ical_todo[attr])
for attr in list(set(ical_todo.singletons)):
- if ical_todo.has_key(attr):
+ if attr in ical_todo:
if isinstance(ical_todo[attr], list):
ical_todo[attr] = ical_todo[attr][0];
self.set_from_ical(attr.lower(), ical_todo[attr])
for attr in list(set(ical_todo.multiple)):
- if ical_todo.has_key(attr):
+ if attr in ical_todo:
self.set_from_ical(attr.lower(), ical_todo[attr])
# although specified by RFC 2445/5545, icalendar doesn't have this property listed
- if ical_todo.has_key('PERCENT-COMPLETE'):
+ if 'PERCENT-COMPLETE' in ical_todo:
self.set_from_ical('percentcomplete', ical_todo['PERCENT-COMPLETE'])
def _xml_from_ical(self, ical):
@@ -122,16 +122,16 @@ class Todo(Event):
params = {}
_attachment = kolabformat.Attachment()
- if params.has_key('FMTTYPE'):
+ if 'FMTTYPE' in params:
mimetype = str(params['FMTTYPE'])
else:
mimetype = 'application/octet-stream'
- if params.has_key('X-LABEL'):
+ if 'X-LABEL' in params:
_attachment.setLabel(str(params['X-LABEL']))
decode = False
- if params.has_key('ENCODING'):
+ if 'ENCODING' in params:
if params['ENCODING'] == "BASE64" or params['ENCODING'] == "B":
decode = True
@@ -162,7 +162,7 @@ class Todo(Event):
valid_datetime = True
if not valid_datetime:
- raise InvalidEventDateError, _("Todo due needs datetime.date or datetime.datetime instance")
+ raise InvalidEventDateError(_("Todo due needs datetime.date or datetime.datetime instance"))
self.event.setDue(xmlutils.to_cdatetime(_datetime, True))
@@ -259,7 +259,7 @@ class Todo(Event):
if error == None or not error:
return xml
else:
- raise TodoIntegrityError, kolabformat.errorMessage()
+ raise TodoIntegrityError(kolabformat.errorMessage())
class TodoIntegrityError(Exception):
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index 535e95c..821295f 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -158,7 +158,7 @@ def property_label(propname):
"""
Return a localized name for the given object property
"""
- return _(property_labels[propname]) if property_labels.has_key(propname) else _(propname)
+ return _(property_labels[propname]) if propname in property_labels else _(propname)
def property_to_string(propname, value):
@@ -186,18 +186,18 @@ def property_to_string(propname, value):
if isinstance(value, dict):
if propname == 'attendee':
from . import attendee
- name = value['name'] if value.has_key('name') and not value['name'] == '' else value['email']
+ name = value['name'] if 'name' in value and not value['name'] == '' else value['email']
return "%s, %s" % (name, attendee.participant_status_label(value['partstat']))
elif propname == 'organizer':
- return value['name'] if value.has_key('name') and not value['name'] == '' else value['email']
+ return value['name'] if 'name' in value and not value['name'] == '' else value['email']
elif propname == 'rrule':
from . import recurrence_rule
rrule = recurrence_rule.frequency_label(value['freq']) % (value['interval'])
- if value.has_key('count') and value['count'] > 0:
+ if 'count' in value and value['count'] > 0:
rrule += " " + _("for %d times") % (value['count'])
- elif value.has_key('until') and (isinstance(value['until'], datetime.datetime) or isinstance(value['until'], datetime.date)):
+ elif 'until' in value and (isinstance(value['until'], datetime.datetime) or isinstance(value['until'], datetime.date)):
rrule += " " + _("until %s") % (value['until'].strftime(date_format))
return rrule
@@ -235,7 +235,7 @@ def property_to_string(propname, value):
return alarm
elif propname == 'attach':
- return value['label'] if value.has_key('label') else value['fmttype']
+ return value['label'] if 'label' in value else value['fmttype']
return None
@@ -247,11 +247,11 @@ def compute_diff(a, b, reduced=False):
diff = []
properties = a.keys()
- properties.extend([x for x in b.keys() if x not in properties])
+ properties.extend([x for x in b if x not in properties])
for prop in properties:
- aa = a[prop] if a.has_key(prop) else None
- bb = b[prop] if b.has_key(prop) else None
+ aa = a[prop] if prop in a else None
+ bb = b[prop] if prop in b else None
# compare two lists
if isinstance(aa, list) or isinstance(bb, list):
@@ -338,8 +338,8 @@ def compare_values(aa, bb, partial=False):
# accept partial match
if partial:
- for k,v in aa.iteritems():
- if bb.has_key(k) and bb[k] == v:
+ for k,v in aa.items():
+ if k in bb and bb[k] == v:
return True
return False
@@ -355,10 +355,10 @@ def reduce_properties(aa, bb):
return (aa, bb)
properties = aa.keys()
- properties.extend([x for x in bb.keys() if x not in properties])
+ properties.extend([x for x in bb if x not in properties])
for prop in properties:
- if not aa.has_key(prop) or not bb.has_key(prop):
+ if prop not in aa or prop not in bb:
continue
if isinstance(aa[prop], dict) and isinstance(bb[prop], dict):
(aa[prop], bb[prop]) = reduce_properties(aa[prop], bb[prop])
diff --git a/saslauthd.py b/saslauthd.py
index 9d4beab..6e39ed0 100755
--- a/saslauthd.py
+++ b/saslauthd.py
@@ -18,6 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import logging
import os
import sys
@@ -29,9 +31,9 @@ from pykolab.translate import _
try:
import pykolab.logger
-except ImportError, e:
- print >> sys.stderr, _("Cannot load pykolab/logger.py:")
- print >> sys.stderr, "%s" % e
+except ImportError as e:
+ print(_("Cannot load pykolab/logger.py:"), file=sys.stderr)
+ print("%s" % e, file=sys.stderr)
sys.exit(1)
import saslauthd
diff --git a/saslauthd/__init__.py b/saslauthd/__init__.py
index 30e8189..d5c9ece 100644
--- a/saslauthd/__init__.py
+++ b/saslauthd/__init__.py
@@ -25,9 +25,12 @@
backend.
"""
+from __future__ import print_function
from optparse import OptionParser
-from ConfigParser import SafeConfigParser
-
+try:
+ from ConfigParser import SafeConfigParser
+except ImportError:
+ from configparser import SafeConfigParser
import grp
import os
import pwd
@@ -105,7 +108,7 @@ class SASLAuthDaemon(object):
conf.process_username,
conf.process_groupname
)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Could not create %r: %r") % (os.path.dirname(conf.pidfile), errmsg))
sys.exit(1)
@@ -153,6 +156,10 @@ class SASLAuthDaemon(object):
os.close(1)
os.close(2)
+ os.open(os.devnull, os.O_RDONLY)
+ os.open(os.devnull, os.O_WRONLY)
+ os.open(os.devnull, os.O_WRONLY)
+
os.umask(old_umask)
self.thread_count += 1
@@ -161,25 +168,27 @@ class SASLAuthDaemon(object):
self.write_pid()
self.do_saslauthd()
- except SystemExit, e:
+ except SystemExit as e:
exitcode = e
except KeyboardInterrupt:
exitcode = 1
log.info(_("Interrupted by user"))
- except AttributeError, e:
+ except AttributeError:
exitcode = 1
traceback.print_exc()
- print >> sys.stderr, _("Traceback occurred, please report a " +
- "bug at https://issues.kolab.org")
- except TypeError, e:
+ print(_("Traceback occurred, please report a " +
+ "bug at https://issues.kolab.org"),
+ file=sys.stderr)
+ except TypeError as e:
exitcode = 1
traceback.print_exc()
log.error(_("Type Error: %s") % e)
except:
exitcode = 2
traceback.print_exc()
- print >> sys.stderr, _("Traceback occurred, please report a " +
- "bug at https://issues.kolab.org")
+ print(_("Traceback occurred, please report a " +
+ "bug at https://issues.kolab.org"),
+ file=sys.stderr)
sys.exit(exitcode)
@@ -204,7 +213,7 @@ class SASLAuthDaemon(object):
pass
s.bind(conf.socketfile)
- os.chmod(conf.socketfile, 0777)
+ os.chmod(conf.socketfile, 0o777)
s.listen(5)
@@ -217,7 +226,7 @@ class SASLAuthDaemon(object):
try:
(clientsocket, address) = s.accept()
bound = True
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(
_("kolab-saslauthd could not accept " +
"connections on socket: %r") % (errmsg)
@@ -265,13 +274,13 @@ class SASLAuthDaemon(object):
if success:
# #1170: Catch broken pipe error (incomplete authentication request)
try:
- clientsocket.send(struct.pack("!H2s", 2, "OK"))
+ clientsocket.send(struct.pack("!H2s", 2, b"OK"))
except:
pass
else:
# #1170: Catch broken pipe error (incomplete authentication request)
try:
- clientsocket.send(struct.pack("!H2s", 2, "NO"))
+ clientsocket.send(struct.pack("!H2s", 2, b"NO"))
except:
pass
@@ -309,7 +318,7 @@ class SASLAuthDaemon(object):
try:
(ruid, euid, suid) = os.getresuid()
(rgid, egid, sgid) = os.getresgid()
- except AttributeError, errmsg:
+ except AttributeError:
ruid = os.getuid()
rgid = os.getgid()
@@ -326,9 +335,9 @@ class SASLAuthDaemon(object):
) = grp.getgrnam(conf.process_groupname)
except KeyError:
- print >> sys.stderr, _("Group %s does not exist") % (
+ print(_("Group %s does not exist") % (
conf.process_groupname
- )
+ ), file=sys.stderr)
sys.exit(1)
@@ -357,9 +366,9 @@ class SASLAuthDaemon(object):
) = pwd.getpwnam(conf.process_username)
except KeyError:
- print >> sys.stderr, _("User %s does not exist") % (
+ print(_("User %s does not exist") % (
conf.process_username
- )
+ ), file=sys.stderr)
sys.exit(1)
diff --git a/setup-kolab.py b/setup-kolab.py
index 914be99..12b5d1c 100755
--- a/setup-kolab.py
+++ b/setup-kolab.py
@@ -19,6 +19,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import logging
import os
import sys
@@ -33,9 +35,9 @@ from pykolab.translate import _
try:
from pykolab.constants import *
-except ImportError, e:
- print >> sys.stderr, _("Cannot load pykolab/constants.py:")
- print >> sys.stderr, "%s" % e
+except ImportError as e:
+ print(_("Cannot load pykolab/constants.py:"), file=sys.stderr)
+ print("%s" % e, file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
diff --git a/tests/functional/resource_func.py b/tests/functional/resource_func.py
index 36bd1bd..771d698 100644
--- a/tests/functional/resource_func.py
+++ b/tests/functional/resource_func.py
@@ -30,7 +30,7 @@ def resource_add(type, cn, members=None, owner=None, **kw):
type_id = 0
resource_types = wap_client.resource_types_list()
- for key in resource_types['list'].keys():
+ for key in resource_types['list']:
if resource_types['list'][key]['key'] == type:
type_id = key
@@ -41,7 +41,7 @@ def resource_add(type, cn, members=None, owner=None, **kw):
params = {}
- for attribute in resource_type_info['form_fields'].keys():
+ for attribute in resource_type_info['form_fields']:
attr_details = resource_type_info['form_fields'][attribute]
if isinstance(attr_details, dict):
@@ -53,7 +53,7 @@ def resource_add(type, cn, members=None, owner=None, **kw):
fvg_params = params
fvg_params['object_type'] = 'resource'
fvg_params['type_id'] = type_id
- fvg_params['attributes'] = [attr for attr in resource_type_info['auto_form_fields'].keys() if attr not in params]
+ fvg_params['attributes'] = [attr for attr in resource_type_info['auto_form_fields'] if attr not in params]
result = wap_client.resource_add(params)
result['dn'] = "cn=" + result['cn'] + ",ou=Resources,dc=example,dc=org"
diff --git a/tests/functional/test_kolabd/test_001_user_sync.py b/tests/functional/test_kolabd/test_001_user_sync.py
index e8c804d..cf8d443 100644
--- a/tests/functional/test_kolabd/test_001_user_sync.py
+++ b/tests/functional/test_kolabd/test_001_user_sync.py
@@ -89,7 +89,7 @@ class TestKolabDaemon(unittest.TestCase):
folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))
- self.assertEqual(len(folders), len(ac_folders.keys()))
+ self.assertEqual(len(folders), len(ac_folders))
def test_005_user_folders_metadata_set(self):
imap = IMAP()
@@ -104,12 +104,12 @@ class TestKolabDaemon(unittest.TestCase):
for folder in folders:
metadata = imap.get_metadata(folder)
- print metadata
+ print(metadata)
folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
if folder_name in ac_folders:
if 'annotations' in ac_folders[folder_name]:
- for _annotation in ac_folders[folder_name]['annotations'].keys():
+ for _annotation in ac_folders[folder_name]['annotations']:
if _annotation.startswith('/private'):
continue
diff --git a/tests/functional/test_kolabd/test_002_user_rename.py b/tests/functional/test_kolabd/test_002_user_rename.py
index 3ac4a02..aaea7e2 100644
--- a/tests/functional/test_kolabd/test_002_user_rename.py
+++ b/tests/functional/test_kolabd/test_002_user_rename.py
@@ -61,7 +61,7 @@ class TestKolabDaemon(unittest.TestCase):
time.sleep(2)
- print imap.lm()
+ print(imap.lm())
user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')
if not user_info['mail'] == 'joe.sixpack@example.org':
@@ -71,7 +71,7 @@ class TestKolabDaemon(unittest.TestCase):
self.assertEqual(user_info['mail'], 'joe.sixpack@example.org')
- print imap.lm()
+ print(imap.lm())
folders = imap.lm('user/john.doe@example.org')
self.assertEqual(len(folders), 0, "INBOX for john.doe still exists")
diff --git a/tests/functional/test_wallace/test_002_footer.py b/tests/functional/test_wallace/test_002_footer.py
index d6e5836..5da044a 100644
--- a/tests/functional/test_wallace/test_002_footer.py
+++ b/tests/functional/test_wallace/test_002_footer.py
@@ -276,7 +276,7 @@ class TestWallaceFooter(unittest.TestCase):
script_str = script.__str__()
- print script_str
+ print(script_str)
sieveclient.putscript("test_wallace_test_009_forward", script_str)
diff --git a/tests/functional/test_wallace/test_006_resource_performance.py b/tests/functional/test_wallace/test_006_resource_performance.py
index 814a111..39162c4 100644
--- a/tests/functional/test_wallace/test_006_resource_performance.py
+++ b/tests/functional/test_wallace/test_006_resource_performance.py
@@ -138,5 +138,5 @@ class TestWallacePerformance(unittest.TestCase):
res = module_resources.read_resource_calendar(self.room1, [itip])
self.assertEqual(res, num)
- print "\nREAD TIME:", time.time() - start
- print "CONFLICTS:", self.room1['conflicting_events']
+ print("\nREAD TIME:", time.time() - start)
+ print("CONFLICTS:", self.room1['conflicting_events'])
diff --git a/tests/functional/test_wap_client/test_002_user_add.py b/tests/functional/test_wap_client/test_002_user_add.py
index 771e700..a48b92b 100644
--- a/tests/functional/test_wap_client/test_002_user_add.py
+++ b/tests/functional/test_wap_client/test_002_user_add.py
@@ -48,10 +48,10 @@ class TestUserAdd(unittest.TestCase):
folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))
- print folders
- print ac_folders.keys()
+ print(folders)
+ print(ac_folders.keys())
- self.assertEqual(len(folders), len(ac_folders.keys()))
+ self.assertEqual(len(folders), len(ac_folders))
def test_003_folders_metadata_set(self):
imap = IMAP()
diff --git a/tests/functional/test_wap_client/test_003_user_add_fr_FR.py b/tests/functional/test_wap_client/test_003_user_add_fr_FR.py
index 72cf84b..497d26c 100644
--- a/tests/functional/test_wap_client/test_003_user_add_fr_FR.py
+++ b/tests/functional/test_wap_client/test_003_user_add_fr_FR.py
@@ -50,7 +50,7 @@ class TestUserAddFrFR(unittest.TestCase):
self.assertEqual(recipient, "uid=mehul,ou=People,dc=example,dc=org")
result = wap_client.user_info(recipient)
- print result
+ print(result)
self.assertEqual(result['mail'], 'etienne-nicolas.mehul@example.org')
self.assertEqual(sorted(result['alias']), ['e.mehul@example.org', 'mehul@example.org'])
diff --git a/tests/functional/test_wap_client/test_007_policy_uid.py b/tests/functional/test_wap_client/test_007_policy_uid.py
index a10eeb9..eac4022 100644
--- a/tests/functional/test_wap_client/test_007_policy_uid.py
+++ b/tests/functional/test_wap_client/test_007_policy_uid.py
@@ -1,4 +1,7 @@
-from ConfigParser import RawConfigParser
+try:
+ from ConfigParser import RawConfigParser
+except ImportError:
+ from configparser import RawConfigParser
import time
import unittest
diff --git a/tests/functional/user_add.py b/tests/functional/user_add.py
index 35e2b6b..e891053 100644
--- a/tests/functional/user_add.py
+++ b/tests/functional/user_add.py
@@ -32,7 +32,7 @@ def user_add(givenname, sn, preferredlanguage='en_US', **kw):
user_types = wap_client.user_types_list()
- for key in user_types['list'].keys():
+ for key in user_types['list']:
if user_types['list'][key]['key'] == 'kolab':
user_type_id = key
@@ -42,7 +42,7 @@ def user_add(givenname, sn, preferredlanguage='en_US', **kw):
'user_type_id': user_type_id,
}
- for attribute in user_type_info['form_fields'].keys():
+ for attribute in user_type_info['form_fields']:
attr_details = user_type_info['form_fields'][attribute]
if isinstance(attr_details, dict):
@@ -54,6 +54,6 @@ def user_add(givenname, sn, preferredlanguage='en_US', **kw):
fvg_params = params
fvg_params['object_type'] = 'user'
fvg_params['type_id'] = user_type_id
- fvg_params['attributes'] = [attr for attr in user_type_info['auto_form_fields'].keys() if attr not in params]
+ fvg_params['attributes'] = [attr for attr in user_type_info['auto_form_fields'] if attr not in params]
result = wap_client.user_add(params)
diff --git a/tests/unit/test-002-attendee.py b/tests/unit/test-002-attendee.py
index 65eb820..63d6686 100644
--- a/tests/unit/test-002-attendee.py
+++ b/tests/unit/test-002-attendee.py
@@ -34,7 +34,7 @@ class TestEventXML(unittest.TestCase):
self.assertEqual(self.attendee.get_participant_status(), 0)
def test_005_participant_status_map_length(self):
- self.assertEqual(len(self.attendee.participant_status_map.keys()), 7)
+ self.assertEqual(len(self.attendee.participant_status_map), 7)
def test_006_participant_status_map_forward_lookup(self):
# Forward lookups
@@ -48,19 +48,19 @@ class TestEventXML(unittest.TestCase):
def test_007_participant_status_map_reverse_lookup(self):
# Reverse lookups
- self.assertEqual([k for k, v in self.attendee.participant_status_map.iteritems() if v == 0][0], "NEEDS-ACTION")
- self.assertEqual([k for k, v in self.attendee.participant_status_map.iteritems() if v == 1][0], "ACCEPTED")
- self.assertEqual([k for k, v in self.attendee.participant_status_map.iteritems() if v == 2][0], "DECLINED")
- self.assertEqual([k for k, v in self.attendee.participant_status_map.iteritems() if v == 3][0], "TENTATIVE")
- self.assertEqual([k for k, v in self.attendee.participant_status_map.iteritems() if v == 4][0], "DELEGATED")
- self.assertEqual([k for k, v in self.attendee.participant_status_map.iteritems() if v == 5][0], "IN-PROCESS")
- self.assertEqual([k for k, v in self.attendee.participant_status_map.iteritems() if v == 6][0], "COMPLETED")
+ self.assertEqual([k for k, v in self.attendee.participant_status_map.items() if v == 0][0], "NEEDS-ACTION")
+ self.assertEqual([k for k, v in self.attendee.participant_status_map.items() if v == 1][0], "ACCEPTED")
+ self.assertEqual([k for k, v in self.attendee.participant_status_map.items() if v == 2][0], "DECLINED")
+ self.assertEqual([k for k, v in self.attendee.participant_status_map.items() if v == 3][0], "TENTATIVE")
+ self.assertEqual([k for k, v in self.attendee.participant_status_map.items() if v == 4][0], "DELEGATED")
+ self.assertEqual([k for k, v in self.attendee.participant_status_map.items() if v == 5][0], "IN-PROCESS")
+ self.assertEqual([k for k, v in self.attendee.participant_status_map.items() if v == 6][0], "COMPLETED")
def test_008_default_rsvp(self):
self.assertEqual(self.attendee.get_rsvp(), 0)
def test_009_rsvp_map_length(self):
- self.assertEqual(len(self.attendee.rsvp_map.keys()), 2)
+ self.assertEqual(len(self.attendee.rsvp_map), 2)
def test_010_rsvp_map_forward_lookup_boolean(self):
self.assertEqual(self.attendee.rsvp_map["TRUE"], True)
@@ -71,18 +71,18 @@ class TestEventXML(unittest.TestCase):
self.assertEqual(self.attendee.rsvp_map["FALSE"], 0)
def test_012_rsvp_map_reverse_lookup_boolean(self):
- self.assertEqual([k for k, v in self.attendee.rsvp_map.iteritems() if v is True][0], "TRUE")
- self.assertEqual([k for k, v in self.attendee.rsvp_map.iteritems() if v is False][0], "FALSE")
+ self.assertEqual([k for k, v in self.attendee.rsvp_map.items() if v is True][0], "TRUE")
+ self.assertEqual([k for k, v in self.attendee.rsvp_map.items() if v is False][0], "FALSE")
def test_013_rsvp_map_reverse_lookup_integer(self):
- self.assertEqual([k for k, v in self.attendee.rsvp_map.iteritems() if v == 1][0], "TRUE")
- self.assertEqual([k for k, v in self.attendee.rsvp_map.iteritems() if v == 0][0], "FALSE")
+ self.assertEqual([k for k, v in self.attendee.rsvp_map.items() if v == 1][0], "TRUE")
+ self.assertEqual([k for k, v in self.attendee.rsvp_map.items() if v == 0][0], "FALSE")
def test_014_default_role(self):
self.assertEqual(self.attendee.get_role(), 0)
def test_015_role_map_length(self):
- self.assertEqual(len(self.attendee.role_map.keys()), 4)
+ self.assertEqual(len(self.attendee.role_map), 4)
def test_016_role_map_forward_lookup(self):
self.assertEqual(self.attendee.role_map["REQ-PARTICIPANT"], 0)
@@ -91,13 +91,13 @@ class TestEventXML(unittest.TestCase):
self.assertEqual(self.attendee.role_map["NON-PARTICIPANT"], 3)
def test_017_role_map_reverse_lookup(self):
- self.assertEqual([k for k, v in self.attendee.role_map.iteritems() if v == 0][0], "REQ-PARTICIPANT")
- self.assertEqual([k for k, v in self.attendee.role_map.iteritems() if v == 1][0], "CHAIR")
- self.assertEqual([k for k, v in self.attendee.role_map.iteritems() if v == 2][0], "OPT-PARTICIPANT")
- self.assertEqual([k for k, v in self.attendee.role_map.iteritems() if v == 3][0], "NON-PARTICIPANT")
+ self.assertEqual([k for k, v in self.attendee.role_map.items() if v == 0][0], "REQ-PARTICIPANT")
+ self.assertEqual([k for k, v in self.attendee.role_map.items() if v == 1][0], "CHAIR")
+ self.assertEqual([k for k, v in self.attendee.role_map.items() if v == 2][0], "OPT-PARTICIPANT")
+ self.assertEqual([k for k, v in self.attendee.role_map.items() if v == 3][0], "NON-PARTICIPANT")
def test_015_cutype_map_length(self):
- self.assertEqual(len(self.attendee.cutype_map.keys()), 5)
+ self.assertEqual(len(self.attendee.cutype_map), 5)
def test_016_cutype_map_forward_lookup(self):
self.assertEqual(self.attendee.cutype_map["GROUP"], kolabformat.CutypeGroup)
@@ -107,11 +107,11 @@ class TestEventXML(unittest.TestCase):
self.assertEqual(self.attendee.cutype_map["UNKNOWN"], kolabformat.CutypeUnknown)
def test_017_cutype_map_reverse_lookup(self):
- self.assertEqual([k for k, v in self.attendee.cutype_map.iteritems() if v == kolabformat.CutypeGroup][0], "GROUP")
- self.assertEqual([k for k, v in self.attendee.cutype_map.iteritems() if v == kolabformat.CutypeIndividual][0], "INDIVIDUAL")
- self.assertEqual([k for k, v in self.attendee.cutype_map.iteritems() if v == kolabformat.CutypeResource][0], "RESOURCE")
- self.assertEqual([k for k, v in self.attendee.cutype_map.iteritems() if v == kolabformat.CutypeRoom][0], "ROOM")
- self.assertEqual([k for k, v in self.attendee.cutype_map.iteritems() if v == kolabformat.CutypeUnknown][0], "UNKNOWN")
+ self.assertEqual([k for k, v in self.attendee.cutype_map.items() if v == kolabformat.CutypeGroup][0], "GROUP")
+ self.assertEqual([k for k, v in self.attendee.cutype_map.items() if v == kolabformat.CutypeIndividual][0], "INDIVIDUAL")
+ self.assertEqual([k for k, v in self.attendee.cutype_map.items() if v == kolabformat.CutypeResource][0], "RESOURCE")
+ self.assertEqual([k for k, v in self.attendee.cutype_map.items() if v == kolabformat.CutypeRoom][0], "ROOM")
+ self.assertEqual([k for k, v in self.attendee.cutype_map.items() if v == kolabformat.CutypeUnknown][0], "UNKNOWN")
def test_018_partstat_label(self):
self.assertEqual(participant_status_label('NEEDS-ACTION'), "Needs Action")
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 8b23830..4137855 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -460,7 +460,7 @@ class TestEventXML(unittest.TestCase):
self.assertIsInstance(_tz.tzinfo, datetime.tzinfo)
def test_016_start_with_timezone(self):
- _start = datetime.datetime(2012, 05, 23, 11, 58, 00, tzinfo=pytz.timezone("Europe/Zurich"))
+ _start = datetime.datetime(2012, 5, 23, 11, 58, 00, tzinfo=pytz.timezone("Europe/Zurich"))
_start_utc = _start.astimezone(pytz.utc)
# self.assertEqual(_start.__str__(), "2012-05-23 11:58:00+01:00")
# self.assertEqual(_start_utc.__str__(), "2012-05-23 10:58:00+00:00")
@@ -469,7 +469,7 @@ class TestEventXML(unittest.TestCase):
self.assertEqual(_start.tzinfo, pytz.timezone("Europe/Zurich"))
def test_017_allday_without_timezone(self):
- _start = datetime.date(2012, 05, 23)
+ _start = datetime.date(2012, 5, 23)
self.assertEqual(_start.__str__(), "2012-05-23")
self.event.set_start(_start)
self.assertEqual(hasattr(_start, 'tzinfo'), False)
@@ -553,12 +553,12 @@ END:VEVENT
def test_019_as_string_itip(self):
self.event.set_summary("test")
- self.event.set_start(datetime.datetime(2014, 05, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))
- self.event.set_end(datetime.datetime(2014, 05, 23, 12, 30, 00, tzinfo=pytz.timezone("Europe/London")))
+ self.event.set_start(datetime.datetime(2014, 5, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))
+ self.event.set_end(datetime.datetime(2014, 5, 23, 12, 30, 00, tzinfo=pytz.timezone("Europe/London")))
self.event.set_sequence(3)
self.event.set_classification('CONFIDENTIAL')
self.event.add_custom_property('X-Custom', 'check')
- self.event.set_recurrence_id(datetime.datetime(2014, 05, 23, 11, 0, 0), True)
+ self.event.set_recurrence_id(datetime.datetime(2014, 5, 23, 11, 0, 0), True)
rrule = RecurrenceRule()
rrule.set_frequency(kolabformat.RecurrenceRule.Weekly)
@@ -592,8 +592,8 @@ END:VEVENT
def test_019_to_message_itip(self):
self.event = Event()
self.event.set_summary("test")
- self.event.set_start(datetime.datetime(2014, 05, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))
- self.event.set_end(datetime.datetime(2014, 05, 23, 12, 30, 00, tzinfo=pytz.timezone("Europe/London")))
+ self.event.set_start(datetime.datetime(2014, 5, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))
+ self.event.set_end(datetime.datetime(2014, 5, 23, 12, 30, 00, tzinfo=pytz.timezone("Europe/London")))
self.event.set_organizer("me@kolab.org")
self.event.add_attendee("john@doe.org")
self.event.add_attendee("jane@doe.org")
@@ -742,17 +742,17 @@ END:VEVENT
def test_021_ical_exceptions(self):
self.event.set_summary("test")
- self.event.set_start(datetime.datetime(2014, 05, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))
- self.event.set_end(datetime.datetime(2014, 05, 23, 12, 30, 00, tzinfo=pytz.timezone("Europe/London")))
+ self.event.set_start(datetime.datetime(2014, 5, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))
+ self.event.set_end(datetime.datetime(2014, 5, 23, 12, 30, 00, tzinfo=pytz.timezone("Europe/London")))
rrule = kolabformat.RecurrenceRule()
rrule.setFrequency(kolabformat.RecurrenceRule.Weekly)
self.event.set_recurrence(rrule)
xmlexception = Event(from_string=str(self.event))
- xmlexception.set_start(datetime.datetime(2014, 05, 30, 14, 00, 00, tzinfo=pytz.timezone("Europe/London")))
- xmlexception.set_end(datetime.datetime(2014, 05, 30, 16, 00, 00, tzinfo=pytz.timezone("Europe/London")))
- xmlexception.set_recurrence_id(datetime.datetime(2014, 05, 30, 11, 0, 0), False)
+ xmlexception.set_start(datetime.datetime(2014, 5, 30, 14, 00, 00, tzinfo=pytz.timezone("Europe/London")))
+ xmlexception.set_end(datetime.datetime(2014, 5, 30, 16, 00, 00, tzinfo=pytz.timezone("Europe/London")))
+ xmlexception.set_recurrence_id(datetime.datetime(2014, 5, 30, 11, 0, 0), False)
self.event.add_exception(xmlexception)
ical = icalendar.Calendar.from_ical(self.event.as_string_itip())
diff --git a/tests/unit/test-008-sievelib.py b/tests/unit/test-008-sievelib.py
index 9226ad6..e3395e8 100644
--- a/tests/unit/test-008-sievelib.py
+++ b/tests/unit/test-008-sievelib.py
@@ -53,5 +53,5 @@ class TestSievelib(unittest.TestCase):
i += 1
result = sieve_parser.parse(sieve_str)
if not result:
- print "Sieve line: %r" % (sieve_parser.lexer.text.split('\n')[(sieve_parser.lexer.text[:sieve_parser.lexer.pos].count('\n'))])
+ print("Sieve line: %r" % (sieve_parser.lexer.text.split('\n')[(sieve_parser.lexer.text[:sieve_parser.lexer.pos].count('\n'))]))
raise Exception("Failed parsing Sieve script #%d: %s" % (i, sieve_parser.error))
diff --git a/tests/unit/test-011-wallace_resources.py b/tests/unit/test-011-wallace_resources.py
index 35d85a0..210d85d 100644
--- a/tests/unit/test-011-wallace_resources.py
+++ b/tests/unit/test-011-wallace_resources.py
@@ -3,6 +3,7 @@ import logging
import datetime
from pykolab import itip
+from pykolab.imap import IMAP
from icalendar import Calendar
from email import message
from email import message_from_string
@@ -41,7 +42,7 @@ CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
UID:626421779C777FBE9C9B85A80D04DDFA-A4BF5BBB9FEAA271
-DTSTAMP:20120713T1254140
+DTSTAMP:20120713T125414
DTSTART;TZID=3DEurope/London:20120713T100000
DTEND;TZID=3DEurope/London:20120713T110000
SUMMARY:test
@@ -75,7 +76,7 @@ CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
UID:626421779C777FBE9C9B85A80D04DDFA-A4BF5BBB9FEAA271
-DTSTAMP:20120713T1254140
+DTSTAMP:20120713T125414
DTSTART;TZID=3DEurope/London:20120713T100000
DTEND;TZID=3DEurope/London:20120713T110000
SUMMARY:test
@@ -105,6 +106,12 @@ class TestWallaceResources(unittest.TestCase):
self.patch(pykolab.auth.Auth, "get_entry_attributes", self._mock_get_entry_attributes)
self.patch(pykolab.auth.Auth, "search_entry_by_attribute", self._mock_search_entry_by_attribute)
+ # Mock IMAP operations
+ self.patch(pykolab.imap.IMAP, "connect", self._mock_nop)
+ self.patch(pykolab.imap.IMAP, "disconnect", self._mock_nop)
+ self.patch(pykolab.imap.IMAP, "set_acl", self._mock_nop)
+ self.patch(pykolab.imap.IMAP, "append", self._mock_imap_append)
+
# intercept calls to smtplib.SMTP.sendmail()
import smtplib
self.patch(smtplib.SMTP, "__init__", self._mock_smtp_init)
@@ -113,8 +120,9 @@ class TestWallaceResources(unittest.TestCase):
self.patch(smtplib.SMTP, "sendmail", self._mock_smtp_sendmail)
self.smtplog = []
+ self.imap_append_log = []
- def _mock_nop(self, domain=None):
+ def _mock_nop(self, domain=None, arg3=None, arg4=None):
pass
def _mock_find_resource(self, address):
@@ -142,6 +150,10 @@ class TestWallaceResources(unittest.TestCase):
self.smtplog.append((from_addr, to_addr, message))
return []
+ def _mock_imap_append(self, folder, msg):
+ self.imap_append_log.append((folder, msg))
+ return True
+
def _get_ics_part(self, message):
ics_part = None
for part in message.walk():
@@ -234,3 +246,41 @@ class TestWallaceResources(unittest.TestCase):
self.assertIn("ACCEPTED".lower(), response2['subject'].lower(), "Delegation message subject: %r" % (response2['subject']))
self.assertEqual(ical2['attendee'].__str__(), "MAILTO:resource-car-audi-a4@example.org")
self.assertEqual(ical2['attendee'].params['PARTSTAT'], u"ACCEPTED")
+
+ def test_007_accept_reservation_request_store_and_notify(self):
+ itip_event = itip.events_from_message(message_from_string(itip_multipart))[0]
+
+ resource = {
+ 'mail': 'resource-collection-car@example.org',
+ 'kolabtargetfolder': 'shared/Resources/Test@example.org',
+ 'dn': 'cn=cars,ou=Resources,cd=example,dc=org',
+ 'cn': 'Cars',
+ 'owner': 'uid=foo,ou=People,cd=example,dc=org',
+ 'kolabinvitationpolicy': [module_resources.ACT_STORE_AND_NOTIFY]
+ }
+
+ conf.command_set('wallace', 'webmail_url', 'https://%(domain)s/roundcube')
+ module_resources.imap = IMAP()
+
+ module_resources.accept_reservation_request(itip_event, resource)
+
+ # Assert no reply message sent to the organizer
+ self.assertEqual(len(self.smtplog), 1)
+ self.assertEqual(len(self.imap_append_log), 1)
+
+ # Assert the notification sent to the resource owner
+ mail = message_from_string(self.smtplog[0][2])
+
+ self.assertEqual("resource-collection-car@example.org", self.smtplog[0][0])
+ self.assertEqual("resource-collection-car@example.org", mail['from'])
+ self.assertEqual("foo@example.org", self.smtplog[0][1])
+ self.assertEqual("foo@example.org", mail['to'])
+ self.assertFalse(mail.is_multipart())
+ self.assertIn("New booking request for Cars", mail['subject'])
+ body = mail.get_payload(decode=True)
+ self.assertIn("The resource booking request is for Cars by Doe, John <doe@example.org>", body)
+ self.assertIn("You can change the status via https://example.org/roundcube?_task=calendar", body)
+
+ # Assert the message appended to the resource folder
+ self.assertEqual(resource['kolabtargetfolder'], self.imap_append_log[0][0])
+ self.assertIn("<text>NEEDS-ACTION</text>", self.imap_append_log[0][1])
diff --git a/ucs/kolab_sieve.py b/ucs/kolab_sieve.py
index d7125a7..70ae4b8 100755
--- a/ucs/kolab_sieve.py
+++ b/ucs/kolab_sieve.py
@@ -77,10 +77,10 @@ def handler(*args, **kw):
new = utils.normalize(args[1])
old = utils.normalize(args[2])
- if isinstance(old, dict) and len(old.keys()) > 0:
+ if isinstance(old, dict) and len(old) > 0:
# Either the entry changed or was deleted
- if isinstance(new, dict) and len(new.keys()) > 0:
+ if isinstance(new, dict) and len(new) > 0:
# The entry was modified.
result_attr = conf.get('cyrus-sasl', 'result_attribute')
@@ -128,7 +128,7 @@ def handler(*args, **kw):
# Sieve Script Management
return
- elif isinstance(new, dict) and len(new.keys()) > 0:
+ elif isinstance(new, dict) and len(new) > 0:
# Old is not a dict (or empty), so the entry is just created
# See if the mailserver_attribute exists
diff --git a/ucs/listener.py b/ucs/listener.py
index 67c3dca..a36075f 100755
--- a/ucs/listener.py
+++ b/ucs/listener.py
@@ -83,13 +83,13 @@ def handler(*args, **kw):
new = utils.normalize(args[1])
old = utils.normalize(args[2])
- if isinstance(old, dict) and len(old.keys()) > 0:
+ if isinstance(old, dict) and len(old) > 0:
# Two options:
# - entry changed
# - entry deleted
log.info("user %r, old is dict" % (dn))
- if isinstance(new, dict) and len(new.keys()) > 0:
+ if isinstance(new, dict) and len(new) > 0:
log.info("Modify entry %r" % (dn))
mailserver_attribute = conf.get('ldap', 'mailserver_attribute').lower()
@@ -160,7 +160,7 @@ def handler(*args, **kw):
entry=old
)
- elif isinstance(new, dict) and len(new.keys()) > 0:
+ elif isinstance(new, dict) and len(new) > 0:
# Old is not a dict (or empty), so the entry is just created
log.info("Add entry %r" % (dn))
diff --git a/wallace.py b/wallace.py
index a45f34a..ebfddda 100755
--- a/wallace.py
+++ b/wallace.py
@@ -18,6 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import sys
# For development purposes
@@ -27,9 +29,9 @@ from pykolab.translate import _
try:
from pykolab.constants import *
-except ImportError, e:
- print >> sys.stderr, _("Cannot load pykolab/constants.py:")
- print >> sys.stderr, "%s" % e
+except ImportError as e:
+ print(_("Cannot load pykolab/constants.py:"), file=sys.stderr)
+ print("%s" % e, file=sys.stderr)
sys.exit(1)
import wallace
diff --git a/wallace/__init__.py b/wallace/__init__.py
index 4a22e3e..6f11b01 100644
--- a/wallace/__init__.py
+++ b/wallace/__init__.py
@@ -31,7 +31,10 @@ import socket
import struct
import sys
import tempfile
-from threading import _Timer
+try:
+ from threading import _Timer
+except:
+ from threading import Timer as _Timer
import time
import pykolab
@@ -39,8 +42,8 @@ from pykolab import utils
from pykolab.logger import StderrToLogger
from pykolab.translate import _ as _l
-import modules
-from modules import cb_action_ACCEPT
+from . import modules
+from .modules import cb_action_ACCEPT
# pylint: disable=invalid-name
log = pykolab.getLogger('pykolab.wallace')
diff --git a/wallace/module_footer.py b/wallace/module_footer.py
index 73916fb..96e8cf6 100644
--- a/wallace/module_footer.py
+++ b/wallace/module_footer.py
@@ -25,7 +25,7 @@ import time
from email import message_from_file
from email.encoders import encode_quopri
-import modules
+from . import modules
import pykolab
from pykolab.translate import _
@@ -165,12 +165,12 @@ def execute(*args, **kw):
if content_type == "text/plain":
content = part.get_payload(decode=True)
- content = append_footer(content, footer['plain'], footer_position, false)
+ content = append_footer(content, footer['plain'], footer_position, False)
footer_added = set_part_content(part, content)
elif content_type == "text/html":
content = part.get_payload(decode=True)
- content = append_footer(content, footer['html'], footer_position, true)
+ content = append_footer(content, footer['html'], footer_position, True)
footer_added = set_part_content(part, content)
if footer_added:
diff --git a/wallace/module_gpgencrypt.py b/wallace/module_gpgencrypt.py
index e623fe1..e98bf0d 100644
--- a/wallace/module_gpgencrypt.py
+++ b/wallace/module_gpgencrypt.py
@@ -34,7 +34,7 @@ import email.mime.text
import email.encoders
import gnupg
-import modules
+from . import modules
import pykolab
@@ -102,7 +102,7 @@ def execute(*args, **kw):
if not os.path.isdir(os.path.join(mybasepath, stage)):
os.makedirs(os.path.join(mybasepath, stage))
- if kw.has_key('stage'):
+ if 'stage' in kw:
log.debug(_("Issuing callback after processing to stage %s") % (kw['stage']), level=8)
log.debug(_("Testing cb_action_%s()") % (kw['stage']), level=8)
if hasattr(modules, 'cb_action_%s' % (kw['stage'])):
@@ -286,7 +286,7 @@ def execute(*args, **kw):
os.unlink(filepath)
exec('modules.cb_action_%s(%r, %r)' % ('ACCEPT','gpgencrypt', new_filepath))
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("An error occurred: %r") % (errmsg))
if conf.debuglevel > 8:
import traceback
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index 46e506d..da6eec9 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import datetime
import os
@@ -23,7 +24,10 @@ import random
import signal
import tempfile
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import urllib
import hashlib
import traceback
@@ -34,7 +38,7 @@ from email.parser import Parser
from email.utils import formataddr
from email.utils import getaddresses
-import modules
+from . import modules
import pykolab
import kolabformat
@@ -138,7 +142,7 @@ policy_name_map = {
'ACT_SAVE_AND_FORWARD': ACT_SAVE_AND_FORWARD + COND_TYPE_EVENT,
}
-policy_value_map = dict([(v &~ COND_TYPE_ALL, k) for (k, v) in policy_name_map.iteritems()])
+policy_value_map = dict([(v &~ COND_TYPE_ALL, k) for (k, v) in policy_name_map.items()])
object_type_conditons = {
'event': COND_TYPE_EVENT,
@@ -227,12 +231,12 @@ def execute(*args, **kw):
imap = IMAP()
# ignore calls on lock files
- if '/locks/' in filepath or kw.has_key('stage') and kw['stage'] == 'locks':
+ if '/locks/' in filepath or 'stage' in kw and kw['stage'] == 'locks':
return False
log.debug("Invitation policy executing for %r, %r" % (filepath, '/locks/' in filepath), level=8)
- if kw.has_key('stage'):
+ if 'stage' in kw:
log.debug(_("Issuing callback after processing to stage %s") % (kw['stage']), level=8)
log.debug(_("Testing cb_action_%s()") % (kw['stage']), level=8)
@@ -280,7 +284,7 @@ def execute(*args, **kw):
# is an iTip message by checking the length of this list.
try:
itip_events = objects_from_message(message, ['VEVENT','VTODO'], ['REQUEST', 'REPLY', 'CANCEL'])
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Failed to parse iTip objects from message: %r" % (errmsg)))
itip_events = []
@@ -292,7 +296,7 @@ def execute(*args, **kw):
log.debug(_("iTip objects attached to this message contain the following information: %r") % (itip_events), level=8)
# See if any iTip actually allocates a user.
- if any_itips and len([x['uid'] for x in itip_events if x.has_key('attendees') or x.has_key('organizer')]) > 0:
+ if any_itips and len([x['uid'] for x in itip_events if 'attendees' in x or 'organizer' in x]) > 0:
auth.connect()
# we're looking at the first itip object
@@ -329,7 +333,7 @@ def execute(*args, **kw):
# for replies, the organizer is the recipient
if itip_event['method'] == 'REPLY':
# Outlook can send iTip replies without an organizer property
- if itip_event.has_key('organizer'):
+ if 'organizer' in itip_event:
organizer_mailto = str(itip_event['organizer']).split(':')[-1]
user_attendees = [organizer_mailto] if organizer_mailto in recipient_emails else []
else:
@@ -337,10 +341,10 @@ def execute(*args, **kw):
else:
# Limit the attendees to the one that is actually invited with the current message.
- attendees = [str(a).split(':')[-1] for a in (itip_event['attendees'] if itip_event.has_key('attendees') else [])]
+ attendees = [str(a).split(':')[-1] for a in (itip_event['attendees'] if 'attendees' in itip_event else [])]
user_attendees = [a for a in attendees if a in recipient_emails]
- if itip_event.has_key('organizer'):
+ if 'organizer' in itip_event:
sender_email = itip_event['xml'].get_organizer().email()
# abort if no attendee matches the envelope recipient
@@ -354,7 +358,7 @@ def execute(*args, **kw):
recipient_email = user_attendees[0]
# change gettext language to the preferredlanguage setting of the receiving user
- if receiving_user.has_key('preferredlanguage'):
+ if 'preferredlanguage' in receiving_user:
pykolab.translate.setUserLanguage(receiving_user['preferredlanguage'])
# find user's kolabInvitationPolicy settings and the matching policy values
@@ -369,7 +373,7 @@ def execute(*args, **kw):
}
done = None
- if method_processing_map.has_key(itip_event['method']):
+ if itip_event['method'] in method_processing_map:
processor_func = method_processing_map[itip_event['method']]
# connect as cyrus-admin
@@ -413,7 +417,7 @@ def process_itip_request(itip_event, policy, recipient_email, sender_email, rece
try:
receiving_attendee = itip_event['xml'].get_attendee_by_email(recipient_email)
log.debug(_("Receiving attendee: %r") % (receiving_attendee.to_dict()), level=8)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error("Could not find envelope attendee: %r" % (errmsg))
return MESSAGE_FORWARD
@@ -486,7 +490,7 @@ def process_itip_request(itip_event, policy, recipient_email, sender_email, rece
# if RSVP, send an iTip REPLY
if rsvp or scheduling_required:
# set attendee's CN from LDAP record if yet missing
- if not receiving_attendee.get_name() and receiving_user.has_key('cn'):
+ if not receiving_attendee.get_name() and 'cn' in receiving_user:
receiving_attendee.set_name(receiving_user['cn'])
# send iTip reply
@@ -542,7 +546,7 @@ def process_itip_reply(itip_event, policy, recipient_email, sender_email, receiv
try:
sender_attendee = itip_event['xml'].get_attendee_by_email(sender_email)
log.debug(_("Sender Attendee: %r") % (sender_attendee), level=8)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error("Could not find envelope sender attendee: %r" % (errmsg))
return MESSAGE_FORWARD
@@ -565,7 +569,7 @@ def process_itip_reply(itip_event, policy, recipient_email, sender_email, receiv
existing.set_attendee_participant_status(sender_email, sender_attendee.get_participant_status(), rsvp=False)
existing_attendee = existing.get_attendee(sender_email)
updated_attendees.append(existing_attendee)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error("Could not find corresponding attende in organizer's copy: %r" % (errmsg))
# append delegated-from attendee ?
@@ -598,7 +602,7 @@ def process_itip_reply(itip_event, policy, recipient_email, sender_email, receiv
existing.update_attendees([existing_attendee])
log.debug(_("Update delegator: %r") % (existing_attendee.to_dict()), level=8)
- except Exception, errmsg:
+ except Exception as errmsg:
log.error("Could not find delegated-to attendee: %r" % (errmsg))
# update the organizer's copy of the object
@@ -693,7 +697,7 @@ def user_dn_from_email_address(email_address):
auth.connect()
# return cached value
- if user_dn_from_email_address.cache.has_key(email_address):
+ if email_address in user_dn_from_email_address.cache:
return user_dn_from_email_address.cache[email_address]
local_domains = auth.list_domains()
@@ -709,7 +713,7 @@ def user_dn_from_email_address(email_address):
user_dn = auth.find_user_dn(email_address, True)
- if isinstance(user_dn, basestring):
+ if isinstance(user_dn, string_types):
log.debug(_("User DN: %r") % (user_dn), level=8)
else:
log.debug(_("No user record(s) found for %r") % (email_address), level=8)
@@ -724,7 +728,7 @@ user_dn_from_email_address.cache = {}
def get_matching_invitation_policies(receiving_user, sender_email, type_condition=COND_TYPE_ALL):
# get user's kolabInvitationPolicy settings
- policies = receiving_user['kolabinvitationpolicy'] if receiving_user.has_key('kolabinvitationpolicy') else []
+ policies = receiving_user['kolabinvitationpolicy'] if 'kolabinvitationpolicy' in receiving_user else []
if policies and not isinstance(policies, list):
policies = [policies]
@@ -742,7 +746,7 @@ def get_matching_invitation_policies(receiving_user, sender_email, type_conditio
if domain == '' or domain == '*' or str(sender_email).endswith(domain):
value = value.upper()
- if policy_name_map.has_key(value):
+ if value in policy_name_map:
val = policy_name_map[value]
# append if type condition matches
if val & type_condition:
@@ -767,7 +771,7 @@ def imap_proxy_auth(user_rec):
mail_attribute = mail_attribute.lower()
- if not user_rec.has_key(mail_attribute):
+ if mail_attribute not in user_rec:
log.error(_("User record doesn't have the mailbox attribute %r set" % (mail_attribute)))
return False
@@ -780,7 +784,7 @@ def imap_proxy_auth(user_rec):
imap.disconnect()
imap.connect(login=False)
imap.login_plain(admin_login, admin_password, user_rec[mail_attribute])
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("IMAP proxy authentication failed: %r") % (errmsg))
return False
@@ -910,7 +914,7 @@ def find_existing_object(uid, type, recurrence_id, user_rec, lock=False):
try:
msguid = re.search(r"\WUID (\d+)", data[0][0]).group(1)
- except Exception, errmsg:
+ except Exception:
log.error(_("No UID found in IMAP response: %r") % (data[0][0]))
continue
@@ -936,7 +940,7 @@ def find_existing_object(uid, type, recurrence_id, user_rec, lock=False):
setattr(event, '_lock_key', lock_key)
setattr(event, '_msguid', msguid)
- except Exception, errmsg:
+ except Exception:
log.error(_("Failed to parse %s from message %s/%s: %s") % (type, folder, num, traceback.format_exc()))
event = None
master = None
@@ -961,7 +965,7 @@ def check_availability(itip_event, receiving_user):
conflict = False
# return previously detected conflict
- if itip_event.has_key('_conflicts'):
+ if '_conflicts' in itip_event:
return not itip_event['_conflicts']
for folder in list_user_folders(receiving_user, 'event'):
@@ -977,7 +981,7 @@ def check_availability(itip_event, receiving_user):
try:
event = event_from_message(message_from_string(data[0][1]))
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Failed to parse event from message %s/%s: %r") % (folder, num, errmsg))
continue
@@ -1087,12 +1091,12 @@ def store_object(object, user_rec, targetfolder=None, master=None):
oc = object.get_classification()
# use *.confidential/private folder for confidential/private invitations
- if oc == kolabformat.ClassConfidential and user_rec.has_key('_confidential_folder'):
+ if oc == kolabformat.ClassConfidential and '_confidential_folder' in user_rec:
targetfolder = user_rec['_confidential_folder']
- elif oc == kolabformat.ClassPrivate and user_rec.has_key('_private_folder'):
+ elif oc == kolabformat.ClassPrivate and '_private_folder' in user_rec:
targetfolder = user_rec['_private_folder']
# use *.default folder if exists
- elif user_rec.has_key('_default_folder'):
+ elif '_default_folder' in user_rec:
targetfolder = user_rec['_default_folder']
# fallback to any existing folder of specified type
elif targetfolders is not None and len(targetfolders) > 0:
@@ -1122,7 +1126,7 @@ def store_object(object, user_rec, targetfolder=None, master=None):
)
return result
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Failed to save %s to user folder at %r: %r") % (
saveobj.type, targetfolder, errmsg
))
@@ -1160,7 +1164,7 @@ def delete_object(existing):
imap.imap.m.expunge()
return True
- except Exception, errmsg:
+ except Exception as errmsg:
log.error(_("Failed to delete %s from folder %r: %r") % (
existing.type, targetfolder, errmsg
))
@@ -1205,7 +1209,7 @@ def send_update_notification(object, receiving_user, old=None, reply=True, sende
for attendee in object.get_attendees():
parstat = attendee.get_participant_status(True)
- if partstats.has_key(parstat):
+ if parstat in partstats:
partstats[parstat].append(attendee.get_displayname())
else:
partstats['PENDING'].append(attendee.get_displayname())
@@ -1243,7 +1247,7 @@ def send_update_notification(object, receiving_user, old=None, reply=True, sende
if itip_comment is not None:
roundup += "\n" + itip_comment
- for status,attendees in partstats.iteritems():
+ for status,attendees in partstats.items():
if len(attendees) > 0:
roundup += "\n" + participant_status_label(status) + ":\n\t" + "\n\t".join(attendees) + "\n"
else:
diff --git a/wallace/module_optout.py b/wallace/module_optout.py
index 632753f..9220ebe 100644
--- a/wallace/module_optout.py
+++ b/wallace/module_optout.py
@@ -22,14 +22,17 @@ import os
import random
import tempfile
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import urllib
from email import message_from_file
from email.utils import formataddr
from email.utils import getaddresses
-import modules
+from . import modules
import pykolab
@@ -57,7 +60,7 @@ def execute(*args, **kw):
# TODO: Test for correct call.
filepath = args[0]
- if kw.has_key('stage'):
+ if 'stage' in kw:
log.debug(_("Issuing callback after processing to stage %s") % (kw['stage']), level=8)
log.debug(_("Testing cb_action_%s()") % (kw['stage']), level=8)
if hasattr(modules, 'cb_action_%s' % (kw['stage'])):
@@ -90,7 +93,7 @@ def execute(*args, **kw):
"Cc": []
}
- for recipient_type in recipients.keys():
+ for recipient_type in recipients:
for recipient in recipients[recipient_type]:
log.debug(
_("Running opt-out consult from envelope sender '%s " + \
@@ -136,7 +139,7 @@ def execute(*args, **kw):
use_this = False
- for recipient_type in _recipients[answer].keys():
+ for recipient_type in _recipients[answer]:
_message.__delitem__(recipient_type)
if not len(_recipients[answer][recipient_type]) == 0:
_message.__setitem__(
@@ -177,7 +180,7 @@ def request(params=None):
try:
f = urllib.urlopen(optout_url, params)
- except Exception, e:
+ except Exception:
log.error(_("Could not send request to optout_url %s") % (optout_url))
return "DEFER"
@@ -185,8 +188,8 @@ def request(params=None):
try:
response_data = json.loads(response)
- except ValueError, e:
+ except ValueError:
# Some data is not JSON
- print "Response data is not JSON"
+ print("Response data is not JSON")
return response_data['result']
diff --git a/wallace/module_resources.py b/wallace/module_resources.py
index 798577d..afaf384 100644
--- a/wallace/module_resources.py
+++ b/wallace/module_resources.py
@@ -36,7 +36,7 @@ import uuid
from dateutil.tz import tzlocal
-import modules
+from . import modules
import kolabformat
@@ -58,14 +58,17 @@ COND_NOTIFY = 256
ACT_MANUAL = 1
ACT_ACCEPT = 2
ACT_REJECT = 8
+ACT_STORE = 16
ACT_ACCEPT_AND_NOTIFY = ACT_ACCEPT + COND_NOTIFY
+ACT_STORE_AND_NOTIFY = ACT_STORE + COND_NOTIFY
# noqa: E241
policy_name_map = {
'ACT_MANUAL': ACT_MANUAL, # noqa: E241
'ACT_ACCEPT': ACT_ACCEPT, # noqa: E241
'ACT_REJECT': ACT_REJECT, # noqa: E241
- 'ACT_ACCEPT_AND_NOTIFY': ACT_ACCEPT_AND_NOTIFY
+ 'ACT_ACCEPT_AND_NOTIFY': ACT_ACCEPT_AND_NOTIFY,
+ 'ACT_STORE_AND_NOTIFY': ACT_STORE_AND_NOTIFY
}
# pylint: disable=invalid-name
@@ -705,7 +708,7 @@ def check_availability(itip_events, resource_dns, resources, receiving_attendee=
num_messages = 0
available_resource = None
- for resource in resources.keys():
+ for resource in resources:
# skip this for resource collections
if 'kolabtargetfolder' not in resources[resource]:
continue
@@ -1031,11 +1034,14 @@ def accept_reservation_request(
):
"""
Accepts the given iTip event by booking it into the resource's
- calendar. Then set the attendee status of the given resource to
- ACCEPTED and sends an iTip reply message to the organizer.
+ calendar. Then, depending on the policy, set the attendee status of the given resource to
+ ACCEPTED/TENTATIVE and send an iTip reply message to the organizer, or set the status to
+ NEEDS-ACTION and don't send a reply to the organizer.
"""
owner = get_resource_owner(resource)
confirmation_required = False
+ do_send_response = True
+ partstat = 'ACCEPTED'
if not confirmed and owner:
if invitationpolicy is None:
@@ -1046,9 +1052,13 @@ def accept_reservation_request(
for policy in invitationpolicy:
if policy & ACT_MANUAL and owner['mail']:
confirmation_required = True
+ partstat = 'TENTATIVE'
+ break
+ if policy & ACT_STORE:
+ partstat = 'NEEDS-ACTION'
+ # Do not send an immediate response to the organizer
+ do_send_response = False
break
-
- partstat = 'TENTATIVE' if confirmation_required else 'ACCEPTED'
itip_event['xml'].set_transparency(False)
itip_event['xml'].set_attendee_participant_status(
@@ -1063,7 +1073,7 @@ def accept_reservation_request(
level=8
)
- if saved:
+ if saved and do_send_response:
send_response(delegator['mail'] if delegator else resource['mail'], itip_event, owner)
if owner and confirmation_required:
@@ -1110,7 +1120,6 @@ def save_resource_event(itip_event, resource):
"""
try:
save_event = itip_event['xml']
- targetfolder = imap.folder_quote(resource['kolabtargetfolder'])
# add exception to existing recurring main event
if resource.get('existing_master') is not None:
@@ -1132,18 +1141,17 @@ def save_resource_event(itip_event, resource):
else:
imap.set_acl(
- targetfolder,
+ resource['kolabtargetfolder'],
conf.get(conf.get('kolab', 'imap_backend'), 'admin_login'),
"lrswipkxtecda"
)
# append new version
- result = imap.imap.m.append(
- targetfolder,
- None,
- None,
+ result = imap.append(
+ resource['kolabtargetfolder'],
save_event.to_message(creator="Kolab Server <wallace@localhost>").as_string()
)
+
return result
# pylint: disable=broad-except
@@ -1642,16 +1650,21 @@ def send_owner_notification(resource, owner, itip_event, success=True):
if 'preferredlanguage' in owner:
pykolab.translate.setUserLanguage(owner['preferredlanguage'])
- message_text = owner_notification_text(resource, owner, itip_event['xml'], success)
+ message_text = owner_notification_text(resource, owner, itip_event['xml'], success, status)
msg = MIMEText(utils.stripped_message(message_text), _charset='utf-8')
msg['To'] = owner['mail']
msg['From'] = resource['mail']
msg['Date'] = formatdate(localtime=True)
- msg['Subject'] = utils.str2unicode(_('Booking for %s has been %s') % (
- resource['cn'], participant_status_label(status) if success else _('failed')
- ))
+ if status == 'NEEDS-ACTION':
+ msg['Subject'] = utils.str2unicode(_('New booking request for %s') % (
+ resource['cn']
+ ))
+ else:
+ msg['Subject'] = utils.str2unicode(_('Booking for %s has been %s') % (
+ resource['cn'], participant_status_label(status) if success else _('failed')
+ ))
seed = random.randint(0, 6)
alarm_after = (seed * 10) + 60
@@ -1663,19 +1676,37 @@ def send_owner_notification(resource, owner, itip_event, success=True):
signal.alarm(0)
-def owner_notification_text(resource, owner, event, success):
+def owner_notification_text(resource, owner, event, success, status):
organizer = event.get_organizer()
status = event.get_attendee_by_email(resource['mail']).get_participant_status(True)
+ domain = resource['mail'].split('@')[1]
+ url = conf.get('wallace', 'webmail_url')
if success:
- message_text = _(
- """
- The resource booking for %(resource)s by %(orgname)s <%(orgemail)s> has been
- %(status)s for %(date)s.
+ if status == 'NEEDS-ACTION':
+ message_text = _(
+ """
+ The resource booking request is for %(resource)s by %(orgname)s <%(orgemail)s> for %(date)s.
- *** This is an automated message, sent to you as the resource owner. ***
- """
- )
+ *** This is an automated message, sent to you as the resource owner. ***
+ """
+ )
+ else:
+ message_text = _(
+ """
+ The resource booking for %(resource)s by %(orgname)s <%(orgemail)s> has been
+ %(status)s for %(date)s.
+
+ *** This is an automated message, sent to you as the resource owner. ***
+ """
+ )
+
+
+ if url:
+ message_text += (
+ "\n "
+ + _("You can change the status via %(url)s") % { 'url': url } + '?_task=calendar'
+ )
else:
message_text = _(
"""
@@ -1695,7 +1726,8 @@ def owner_notification_text(resource, owner, event, success):
'date': event.get_date_text(),
'status': participant_status_label(status),
'orgname': organizer.name(),
- 'orgemail': organizer.email()
+ 'orgemail': organizer.email(),
+ 'domain': domain
}
diff --git a/wallace/module_signature.py b/wallace/module_signature.py
index dda2d92..cfebcb5 100644
--- a/wallace/module_signature.py
+++ b/wallace/module_signature.py
@@ -26,7 +26,7 @@ from email.encoders import encode_quopri
from email.parser import Parser
from email.utils import getaddresses
-import modules
+from . import modules
import pykolab
from pykolab.auth import Auth
@@ -163,7 +163,7 @@ def execute(*args, **kw): # noqa: C901
if not signature_html and not signature_text and signature_rules is not None:
for signature_rule in signature_rules:
try:
- for attr, regex in signature_rule.iteritems():
+ for attr, regex in signature_rule.items():
if attr == "html":
if not os.path.exists(signature_rule['html']):
raise ValueError
diff --git a/wallace/modules.py b/wallace/modules.py
index 3f27bbd..a1eaa7a 100644
--- a/wallace/modules.py
+++ b/wallace/modules.py
@@ -18,6 +18,7 @@
#
from __future__ import print_function
+from six import string_types
import os
import sys
@@ -64,7 +65,7 @@ def initialize():
module_name = filename.replace('.py', '')
name = module_name.replace('module_', '')
# print("exec(\"from %s import __init__ as %s_register\")" % (module_name,name))
- exec("from %s import __init__ as %s_register" % (module_name, name))
+ exec("from .%s import __init__ as %s_register" % (module_name, name))
exec("%s_register()" % (name))
for dirname in dirnames:
@@ -78,7 +79,7 @@ def list_modules(*args, **kw):
__modules = {}
- for module in modules.keys():
+ for module in modules:
if isinstance(module, tuple):
module_group, module = module
__modules[module_group] = {
@@ -133,10 +134,10 @@ def execute(name, *args, **kw):
log.exception(_("Module %r - Unknown error occurred; %r") % (name, errmsg))
def heartbeat(name, *args, **kw):
- if not modules.has_key(name):
+ if name not in modules:
log.warning(_("No such module %r in modules %r (1).") % (name, modules))
- if modules[name].has_key('heartbeat'):
+ if 'heartbeat' in modules[name]:
return modules[name]['heartbeat'](*args, **kw)
def _sendmail(sender, recipients, msg):
@@ -407,7 +408,7 @@ def register_group(dirname, module):
name = module_name.replace('module_', '')
# TODO: Error recovery from incomplete / incorrect modules.
exec(
- "from %s.%s import __init__ as %s_%s_register" % (
+ "from .%s.%s import __init__ as %s_%s_register" % (
module,
module_name,
module,
@@ -423,10 +424,10 @@ def register(name, func, group=None, description=None, aliases=[], heartbeat=Non
else:
module = name
- if isinstance(aliases, basestring):
+ if isinstance(aliases, string_types):
aliases = [aliases]
- if modules.has_key(module):
+ if module in modules:
log.fatal(_("Module '%s' already registered") % (module))
sys.exit(1)