# 1. `VirtualMailManager` — Initialization code and some functions

When the VirtualMailManager module, or one of its sub modules, is imported, the following actions will be performed:

> - `locale.setlocale()` (with `locale.LC_ALL`) is called, to set `ENCODING`

> - `gettext.install()` is called, to have 18N support.

## 1.1. Constants and data

VirtualMailManager.ENCODING

  The systems current character encoding, e.g. `'UTF-8'` or `'ANSI_X3.4-1968'` (aka ASCII).

## 1.2. Functions

VirtualMailManager.ace2idna(domainname)

  Converts the idn domain name domainname into punycode.

  Parameters:

    domainname (str) – the domain-ace representation (`xn--…`)

  Return type:

    unicode

VirtualMailManager.check_domainname(domainname)

  Returns the validated domain name domainname.

  It also converts the name of the domain from IDN to ASCII, if necessary.

  Parameters:

    domainname (`basestring`) – the name of the domain

  Return type:

    str

  Raises:

    VirtualMailManager.errors.VMMError – if the domain name is too long or doesn’t look like a valid domain name (label.label.label).

VirtualMailManager.check_localpart(localpart)

  Returns the validated local-part localpart of an e-mail address.

  Parameters:

    localpart (str) – The local-part of an e-mail address.

  Return type:

    str

  Raises:

    VirtualMailManager.errors.VMMError – if the local-part is too long or contains invalid characters.

VirtualMailManager.exec_ok(binary)

  Checks if the binary exists and if it is executable.

  Parameters:

    binary (str) – path to the binary

  Return type:

    str

  Raises:

    VirtualMailManager.errors.VMMError – if binary isn’t a file or is not executable.

VirtualMailManager.expand_path(path)

  Expands paths, starting with `.` or `~`, to an absolute path.

  Parameters:

    path (str) – Path to a file or directory

  Return type:

    str

VirtualMailManager.get_unicode(string)

  Converts string to unicode, if necessary.

  Parameters:

    string (str) – The string taht should be converted

  Return type:

    unicode

VirtualMailManager.idn2ascii(domainname)

  Converts the idn domain name domainname into punycode.

  Parameters:

    domainname (unicode) – the unicode representation of the domain name

  Return type:

    str

VirtualMailManager.is_dir(path)

  Checks if path is a directory.

  Parameters:

    path (str) – Path to a directory

  Return type:

    str

  Raises:

    VirtualMailManager.errors.VMMError – if path is not a directory.

## 1.3. 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'
    >>>