VirtualMailManager/__init__.py
author Pascal Volk <neverseen@users.sourceforge.net>
Sun, 24 Jan 2010 06:40:38 +0000
branchv0.6.x
changeset 174 974bafa59330
parent 162 0ac9ef587769
child 185 6e1ef32fbd82
permissions -rw-r--r--
VMM/Config: reworked configuration handling. Implemented LazyConfig(RawConfigParser) and LazyConfigOption(object) Rewrote Config class: * use default values and added some validation stuff * removed attributes: __VMMsections and __changes * replaced methods __chkSections() and __chkOptions() with __chkCfg VMM/VMM: Adjusted to reworked Config class. * removed attribute __cfgSections * removed methods: cfgGetBoolean(), cfgGetInt(), cfgGetString() * added methods: cfgDget(), cfgPget(), cfgSet() VMM/__init__: added function get_unicode() vmm: Adjusted to replaced methods in VMM/VMM.

# -*- coding: UTF-8 -*-
# Copyright (c) 2007 - 2010, Pascal Volk
# See COPYING for distribution information.
# package initialization code
#

import os
import re
import locale

from constants.VERSION import *
import constants.ERROR as ERR

# Try to set all of the locales according to the current
# environment variables and get the character encoding.
try:
    locale.setlocale(locale.LC_ALL, '')
except locale.Error:
    locale.setlocale(locale.LC_ALL, 'C')
ENCODING = locale.nl_langinfo(locale.CODESET)

def w_std(*args):
    """Writes each arg of args, encoded in the current ENCODING, to stdout and
    appends a newline."""
    _write = os.sys.stdout.write
    for arg in args:
        _write(arg.encode(ENCODING, 'replace'))
        _write('\n')

def w_err(code, *args):
    """Writes each arg of args, encoded in the current ENCODING, to stderr and
    appends a newline.
    This function additional interrupts the program execution and uses 'code'
    system exit status."""
    _write = os.sys.stderr.write
    for arg in args:
        _write(arg.encode(ENCODING, 'replace'))
        _write('\n')
    os.sys.exit(code)

def get_unicode(string):
    """Converts `string` to `unicode`, if necessary."""
    if isinstance(string, unicode):
        return string
    return unicode(string, ENCODING, 'replace')

__all__ = [
        # imported modules
        'os', 're', 'locale',
        # version information from VERSION
        '__author__', '__date__', '__version__',
        # error codes
        'ERR',
        # defined stuff
        'ENCODING', 'get_unicode', 'w_std', 'w_err'
        ]
# EOF