VirtualMailManager/__init__.py
branchv0.6.x
changeset 209 c705a9e38962
parent 208 efa1327b721f
child 215 33f727efa7c4
equal deleted inserted replaced
208:efa1327b721f 209:c705a9e38962
     1 # -*- coding: UTF-8 -*-
     1 # -*- coding: UTF-8 -*-
     2 # Copyright (c) 2007 - 2010, Pascal Volk
     2 # Copyright (c) 2007 - 2010, Pascal Volk
     3 # See COPYING for distribution information.
     3 # See COPYING for distribution information.
     4 # package initialization code
     4 
     5 #
     5 """
       
     6     VirtualMailManager
       
     7 
       
     8     VirtualMailManager package initialization code
       
     9 """
     6 
    10 
     7 import gettext
    11 import gettext
     8 import os
    12 import os
     9 import re
    13 import re
    10 import locale
    14 import locale
    21 __all__ = [
    25 __all__ = [
    22     # imported modules
    26     # imported modules
    23     'os', 're', 'locale',
    27     'os', 're', 'locale',
    24     # version information from VERSION
    28     # version information from VERSION
    25     '__author__', '__date__', '__version__',
    29     '__author__', '__date__', '__version__',
    26     # error codes
    30     # defined stuff
    27     'ENCODING', 'ace2idna', 'check_domainname', 'check_localpart', 'exec_ok',
    31     'ENCODING', 'ace2idna', 'check_domainname', 'check_localpart', 'exec_ok',
    28     'expand_path', 'get_unicode', 'idn2ascii', 'is_dir',
    32     'expand_path', 'get_unicode', 'idn2ascii', 'is_dir',
    29 ]
    33 ]
    30 
    34 
    31 
    35 
    64         return os.path.expanduser(path)
    68         return os.path.expanduser(path)
    65     return path
    69     return path
    66 
    70 
    67 
    71 
    68 def is_dir(path):
    72 def is_dir(path):
    69     """Checks if ``path`` is a directory.
    73     """Checks if `path` is a directory.
    70 
    74 
    71     Throws a `VMMException` if ``path`` is not a directory.
    75     Throws a `VMMException` if `path` is not a directory.
    72     """
    76     """
    73     path = expand_path(path)
    77     path = expand_path(path)
    74     if not os.path.isdir(path):
    78     if not os.path.isdir(path):
    75         raise VMMException(_(u'“%s” is not a directory') %
    79         raise VMMException(_(u"'%s' is not a directory") %
    76                             get_unicode(path), NO_SUCH_DIRECTORY)
    80                             get_unicode(path), NO_SUCH_DIRECTORY)
    77     return path
    81     return path
    78 
    82 
    79 
    83 
    80 def exec_ok(binary):
    84 def exec_ok(binary):
    81     """Checks if the ``binary`` exists and if it is executable.
    85     """Checks if the `binary` exists and if it is executable.
    82 
    86 
    83     Throws a `VMMException` if the ``binary`` isn't a file or is not
    87     Throws a `VMMException` if the `binary` isn't a file or is not
    84     executable.
    88     executable.
    85     """
    89     """
    86     binary = expand_path(binary)
    90     binary = expand_path(binary)
    87     if not os.path.isfile(binary):
    91     if not os.path.isfile(binary):
    88         raise VMMException(_(u'“%s” is not a file') % get_unicode(binary),
    92         raise VMMException(_(u"'%s' is not a file") % get_unicode(binary),
    89                            NO_SUCH_BINARY)
    93                            NO_SUCH_BINARY)
    90     if not os.access(binary, os.X_OK):
    94     if not os.access(binary, os.X_OK):
    91         raise VMMException(_(u'File is not executable: “%s”') %
    95         raise VMMException(_(u"File is not executable: '%s'") %
    92                            get_unicode(binary), NOT_EXECUTABLE)
    96                            get_unicode(binary), NOT_EXECUTABLE)
    93     return binary
    97     return binary
    94 
    98 
    95 
    99 
    96 def idn2ascii(domainname):
   100 def idn2ascii(domainname):
   120                            DOMAIN_INVALID)
   124                            DOMAIN_INVALID)
   121     return domainname
   125     return domainname
   122 
   126 
   123 
   127 
   124 def check_localpart(localpart):
   128 def check_localpart(localpart):
   125     """Returns the validated local-part *localpart*.
   129     """Returns the validated local-part `localpart`.
   126 
   130 
   127     Throws a `VMMException` if the local-part is too long or contains
   131     Throws a `VMMException` if the local-part is too long or contains
   128     invalid characters.
   132     invalid characters.
   129     """
   133     """
   130     if len(localpart) > 64:
   134     if len(localpart) > 64: