1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
:mod:`VirtualMailManager` --- Initialization code and some functions
=====================================================================
.. module:: VirtualMailManager
:synopsis: Initialization code and some functions
.. moduleauthor:: Pascal Volk <neverseen@users.sourceforge.net>
.. toctree::
:maxdepth: 2
When the VirtualMailManager module, or one of its sub modules, is imported,
the following actions will be performed:
- :func:`locale.setlocale` (with :const:`locale.LC_ALL`) is called, to set
:const:`ENCODING`
- :func:`gettext.install` is called, to have 18N support.
Constants and data
------------------
.. data:: ENCODING
The systems current character encoding, e.g. ``'UTF-8'`` or
``'ANSI_X3.4-1968'`` (aka ASCII).
Functions
---------
.. function:: ace2idna(domainname)
Converts the idn domain name *domainname* into punycode.
:param domainname: the domain-ace representation (``xn--…``)
:type domainname: str
:rtype: unicode
.. function:: check_domainname(domainname)
Returns the validated domain name *domainname*.
It also converts the name of the domain from IDN to ASCII, if necessary.
:param domainname: the name of the domain
:type domainname: :obj:`basestring`
:rtype: str
:raise VirtualMailManager.errors.VMMError: if the domain name is
too long or doesn't look like a valid domain name (label.label.label).
.. function:: check_localpart(localpart)
Returns the validated local-part *localpart* of an e-mail address.
:param localpart: The local-part of an e-mail address.
:type localpart: str
:rtype: str
:raise VirtualMailManager.errors.VMMError: if the local-part is too
long or contains invalid characters.
.. function:: exec_ok(binary)
Checks if the *binary* exists and if it is executable.
:param binary: path to the binary
:type binary: str
:rtype: str
:raise VirtualMailManager.errors.VMMError: if *binary* isn't a file
or is not executable.
.. function:: expand_path(path)
Expands paths, starting with ``.`` or ``~``, to an absolute path.
:param path: Path to a file or directory
:type path: str
:rtype: str
.. function:: get_unicode(string)
Converts `string` to `unicode`, if necessary.
:param string: The string taht should be converted
:type string: str
:rtype: unicode
.. function:: idn2ascii(domainname)
Converts the idn domain name *domainname* into punycode.
:param domainname: the unicode representation of the domain name
:type domainname: unicode
:rtype: str
.. function:: is_dir(path)
Checks if *path* is a directory.
:param path: Path to a directory
:type path: str
:rtype: str
:raise VirtualMailManager.errors.VMMError: if *path* is not a directory.
Examples
--------
>>> from VirtualMailManager import *
>>> ace2idna('xn--pypal-4ve.tld')
u'p\u0430ypal.tld'
>>> idn2ascii(u'öko.de')
'xn--ko-eka.de'
>>> check_domainname(u'pаypal.tld')
'xn--pypal-4ve.tld'
>>> check_localpart('john.doe')
'john.doe'
>>> exec_ok('usr/bin/vim')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "./VirtualMailManager/__init__.py", line 93, in exec_ok
NO_SUCH_BINARY)
VirtualMailManager.errors.VMMError: 'usr/bin/vim' is not a file
>>> exec_ok('/usr/bin/vim')
'/usr/bin/vim'
>>> expand_path('.')
'/home/user/hg/vmm'
>>> get_unicode('hello world')
u'hello world'
>>> is_dir('~/hg')
'/home/user/hg'
>>>
|