# HG changeset patch # User Pascal Volk # Date 1252096059 0 # Node ID 28f26f7f3d8fc544e70863dcc184b246fef21ff7 # Parent ecd6a379e52357c5de6f378de3b64918327ef37b Reduced the mixing/concatenating of str and unicode objects. Optimized list generation in Domain class. diff -r ecd6a379e523 -r 28f26f7f3d8f VirtualMailManager/Domain.py --- a/VirtualMailManager/Domain.py Fri Sep 04 19:38:50 2009 +0000 +++ b/VirtualMailManager/Domain.py Fri Sep 04 20:27:39 2009 +0000 @@ -231,8 +231,9 @@ dbc.close() accounts = [] if len(users) > 0: - for account in users: - accounts.append('%s@%s' % (account[0], self._name)) + addr = u'@'.join + _dom = self._name + accounts = [addr((account[0], _dom)) for account in users] return accounts def getAliases(self): @@ -244,8 +245,9 @@ dbc.close() aliases = [] if len(addresses) > 0: - for alias in addresses: - aliases.append('%s@%s' % (alias[0], self._name)) + addr = u'@'.join + _dom = self._name + aliases = [addr((alias[0], _dom)) for alias in addresses] return aliases def getRelocated(self): @@ -257,8 +259,9 @@ dbc.close() relocated = [] if len(addresses) > 0: - for address in addresses: - relocated.append('%s@%s' % (address[0], self._name)) + addr = u'@'.join + _dom = self._name + relocated = [addr((address[0], _dom)) for address in addresses] return relocated def getAliaseNames(self): @@ -270,8 +273,7 @@ dbc.close() aliasdomains = [] if len(anames) > 0: - for aname in anames: - aliasdomains.append(aname[0]) + aliasdomains = [aname[0] for aname in anames] return aliasdomains def search(dbh, pattern=None, like=False): diff -r ecd6a379e523 -r 28f26f7f3d8f vmm --- a/vmm Fri Sep 04 19:38:50 2009 +0000 +++ b/vmm Fri Sep 04 20:27:39 2009 +0000 @@ -70,78 +70,78 @@ def _getOrder(): order = () if vmm.cfgGetInt('misc', 'dovecotvers') > 11: - sieve_name = 'sieve' + sieve_name = u'sieve' else: - sieve_name = 'managesieve' + sieve_name = u'managesieve' if argv[1] in ['di', 'domaininfo']: - order = (('domainname', 0), ('gid', 1), ('transport', 0), - ('domaindir', 0), ('aliasdomains', 0), ('accounts', 0), - ('aliases', 0), ('relocated', 0)) + order = ((u'domainname', 0), (u'gid', 1), (u'transport', 0), + (u'domaindir', 0), (u'aliasdomains', 0), (u'accounts', 0), + (u'aliases', 0), (u'relocated', 0)) elif argv[1] in ['ui', 'userinfo']: if argc == 4 and argv[3] != 'aliases'\ or vmm.cfgGetBoolean('maildir', 'diskusage'): - order = (('address', 0), ('name', 0), ('uid', 1), ('gid', 1), - ('transport', 0), ('maildir', 0), ('disk usage', 0), - ('smtp', 1), ('pop3', 1), ('imap', 1), (sieve_name, 1)) + order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), + (u'transport', 0), (u'maildir', 0), (u'disk usage', 0), + (u'smtp', 1), (u'pop3', 1), (u'imap', 1), (sieve_name, 1)) else: - order = (('address', 0), ('name', 0), ('uid', 1), ('gid', 1), - ('transport', 0), ('maildir', 0), ('smtp', 1), ('pop3', 1), - ('imap', 1), (sieve_name, 1)) + order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), + (u'transport', 0), (u'maildir', 0), (u'smtp', 1), + (u'pop3', 1), (u'imap', 1), (sieve_name, 1)) elif argv[1] in ['gu', 'getuser']: - order = (('uid', 1), ('gid', 1), ('address', 0)) + order = ((u'uid', 1), (u'gid', 1), (u'address', 0)) return order def _printInfo(info, title): - msg = '%s %s' % (title, _('information')) - w_std ('%s\n%s' % (msg, '-'*len(msg))) + msg = u'%s %s' % (title, _(u'information')) + w_std (u'%s\n%s' % (msg, u'-'*len(msg))) for k,u in _getOrder(): if u: - w_std('\t%s: %s' % (k.upper().ljust(15, '.'), info[k])) + w_std(u'\t%s: %s' % (k.upper().ljust(15, u'.'), info[k])) else: - w_std('\t%s: %s' % (k.title().ljust(15, '.'), info[k])) + w_std(u'\t%s: %s' % (k.title().ljust(15, u'.'), info[k])) print def _printList(alist, title): - msg = '%s %s' % (_('Available'), title) - w_std('%s\n%s' % (msg, '-'*len(msg))) + msg = u'%s %s' % (_(u'Available'), title) + w_std(u'%s\n%s' % (msg, u'-'*len(msg))) if len(alist) > 0: - if title != _('alias domains'): + if title != _(u'alias domains'): for val in alist: - w_std('\t%s' % val) + w_std(u'\t%s' % val) else: for dom in alist: if not dom.startswith('xn--'): - w_std('\t%s' % dom) + w_std(u'\t%s' % dom) else: - w_std('\t%s (%s)' % (dom, vmm.ace2idna(dom))) + w_std(u'\t%s (%s)' % (dom, vmm.ace2idna(dom))) else: - w_std(_('\tNone')) + w_std(_(u'\tNone')) print def _printAliases(alias, targets): - msg = _('Alias information') - w_std('%s\n%s' % (msg, '-'*len(msg))) - w_std(_('\tMail for %s will be redirected to:') % alias) + msg = _(u'Alias information') + w_std(u'%s\n%s' % (msg, u'-'*len(msg))) + w_std(_(u'\tMail for %s will be redirected to:') % alias) if len(targets) > 0: for target in targets: - w_std('\t * %s' % target) + w_std(u'\t * %s' % target) else: - w_std(_('\tNone')) + w_std(_(u'\tNone')) print def _printRelocated(addr_dest): msg = _(u'Relocated information') - w_std('%s\n%s' % (msg, '-'*len(msg))) + w_std(u'%s\n%s' % (msg, u'-'*len(msg))) w_std(_(u'\tUser ā€œ%(addr)sā€ has moved to ā€œ%(dest)sā€') % addr_dest) print def _formatDom(domain, main=True): if domain.startswith('xn--'): - domain = '%s (%s)' % (domain, vmm.ace2idna(domain)) + domain = u'%s (%s)' % (domain, vmm.ace2idna(domain)) if main: - return '\t[+] %s' % domain + return u'\t[+] %s' % domain else: - return '\t[-] %s' % domain + return u'\t[-] %s' % domain def _printDomList(dids, domains): if argc < 3: @@ -196,24 +196,24 @@ if argc < 3: usage(EXIT.MISSING_ARGS, _(u'Missing domain name.')) elif argc < 4: - _printInfo(vmm.domainInfo(argv[2].lower()), _('Domain')) + _printInfo(vmm.domainInfo(argv[2].lower()), _(u'Domain')) else: details = argv[3].lower() infos = vmm.domainInfo(argv[2].lower(), details) - _printInfo(infos[0], _('Domain')) + _printInfo(infos[0], _(u'Domain')) if details == 'accounts': - _printList(infos[1], _('accounts')) + _printList(infos[1], _(u'accounts')) elif details == 'aliasdomains': - _printList(infos[1], _('alias domains')) + _printList(infos[1], _(u'alias domains')) elif details == 'aliases': - _printList(infos[1], _('aliases')) + _printList(infos[1], _(u'aliases')) elif details == 'relocated': - _printList(infos[1], _('relocated users')) + _printList(infos[1], _(u'relocated users')) else: - _printList(infos[1], _('alias domains')) - _printList(infos[2], _('accounts')) - _printList(infos[3], _('aliases')) - _printList(infos[4], _('relocated users')) + _printList(infos[1], _(u'alias domains')) + _printList(infos[2], _(u'accounts')) + _printList(infos[3], _(u'aliases')) + _printList(infos[4], _(u'relocated users')) def domain_transport(): if argc < 3: @@ -276,15 +276,15 @@ if argc < 3: usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address.')) elif argc < 4: - _printInfo(vmm.userInfo(argv[2].lower()), 'Account') + _printInfo(vmm.userInfo(argv[2].lower()), u'Account') else: arg3 = argv[3].lower() info = vmm.userInfo(argv[2].lower(), arg3) if arg3 in ['aliases', 'full']: - _printInfo(info[0], 'Account') + _printInfo(info[0], u'Account') _printList(info[1], _(u'alias addresses')) else: - _printInfo(info, 'Account') + _printInfo(info, u'Account') def user_name(): if argc < 3: