diff -r 84e6e898e6c5 -r 33f727efa7c4 VirtualMailManager/__init__.py --- a/VirtualMailManager/__init__.py Wed Feb 24 05:48:15 2010 +0000 +++ b/VirtualMailManager/__init__.py Thu Feb 25 17:56:08 2010 +0000 @@ -18,13 +18,12 @@ from VirtualMailManager.constants.ERROR import \ DOMAIN_INVALID, DOMAIN_TOO_LONG, LOCALPART_INVALID, LOCALPART_TOO_LONG, \ NOT_EXECUTABLE, NO_SUCH_BINARY, NO_SUCH_DIRECTORY -from VirtualMailManager.constants.VERSION import * +from VirtualMailManager.constants.version import __author__, __date__, \ + __version__ from VirtualMailManager.Exceptions import VMMException __all__ = [ - # imported modules - 'os', 're', 'locale', # version information from VERSION '__author__', '__date__', '__version__', # defined stuff @@ -41,16 +40,14 @@ locale.setlocale(locale.LC_ALL, 'C') ENCODING = locale.nl_langinfo(locale.CODESET) -RE_DOMAIN = r"^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$" -RE_LOCALPART = r"[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]" +# there may be many domain and e-mail address checks +RE_DOMAIN = re.compile(r"^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$") +RE_LOCALPART = re.compile(r"[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]") + +gettext.install('vmm', '/usr/local/share/locale', unicode=1) -# there may be many domain and e-mail address checks -re_obj_domain = re.compile(RE_DOMAIN) -re_obj_localpart = re.compile(RE_LOCALPART) - - -gettext.install('vmm', '/usr/local/share/locale', unicode=1) +_ = lambda msg: msg def get_unicode(string): @@ -73,6 +70,7 @@ """Checks if `path` is a directory. Throws a `VMMException` if `path` is not a directory. + """ path = expand_path(path) if not os.path.isdir(path): @@ -86,6 +84,7 @@ Throws a `VMMException` if the `binary` isn't a file or is not executable. + """ binary = expand_path(binary) if not os.path.isfile(binary): @@ -110,16 +109,18 @@ def check_domainname(domainname): """Returns the validated domain name `domainname`. - It also converts the name of the domain from IDN to ASCII, if necessary. + It also converts the name of the domain from IDN to ASCII, if + necessary. - Throws an `VMMException`, if the domain name is too long or doesn't look - like a valid domain name (label.label.label). + Throws an `VMMException`, if the domain name is too long or doesn't + look like a valid domain name (label.label.label). + """ - if not re_obj_domain.match(domainname): + if not RE_DOMAIN.match(domainname): domainname = idn2ascii(domainname) if len(domainname) > 255: raise VMMException(_(u'The domain name is too long'), DOMAIN_TOO_LONG) - if not re_obj_domain.match(domainname): + if not RE_DOMAIN.match(domainname): raise VMMException(_(u'The domain name %r is invalid') % domainname, DOMAIN_INVALID) return domainname @@ -130,11 +131,12 @@ Throws a `VMMException` if the local-part is too long or contains invalid characters. + """ if len(localpart) > 64: raise VMMException(_(u'The local-part %r is too long') % localpart, LOCALPART_TOO_LONG) - invalid_chars = set(re_obj_localpart.findall(localpart)) + invalid_chars = set(RE_LOCALPART.findall(localpart)) if invalid_chars: i_chars = u''.join((u'"%s" ' % c for c in invalid_chars)) raise VMMException(_(u"The local-part %(l_part)r contains invalid \ @@ -142,3 +144,6 @@ {'l_part': localpart, 'i_chars': i_chars}, LOCALPART_INVALID) return localpart + + +del _