Пример #1
0
 def availableLanguages(cls):
     """see python lib, getdefaultlocale (which only returns the first one)"""
     localenames = [getdefaultlocale()[0]]
     for variable in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
         try:
             localename = os.environ[variable]
         except KeyError:
             continue
         else:
             if variable == 'LANGUAGE':
                 localenames.extend(localename.split(':'))
             else:
                 localenames.append(localename)
     if Debug.i18n:
         Internal.logger.debug('localenames: {}'.format(
             ','.join(localenames)))
     languages = list(
         _parse_localename(x)[0] for x in localenames if len(x))
     if Debug.i18n:
         Internal.logger.debug('languages: {}'.format(','.join(languages)))
     for resourceDir in cls.localeDirectories():
         for sysLanguage in sorted(os.listdir(resourceDir)):
             if cls.__isLanguageInstalledForKajongg(sysLanguage):
                 languages.append(sysLanguage)
     if languages:
         languages = uniqueList(cls.extendRegionLanguages(languages))
         languages = list(x for x in languages
                          if cls.isLanguageInstalled(x))
     if 'en_US' not in languages:
         languages.extend(['en_US', 'en'])
     if Debug.i18n:
         Internal.logger.debug('languages available: {}'.format(
             ':'.join(languages)))
     return ':'.join(languages)
Пример #2
0
    def test_defaults_UTF8(self):
        # Issue #18378: on (at least) macOS setting LC_CTYPE to "UTF-8" is
        # valid. Futhermore LC_CTYPE=UTF is used by the UTF-8 locale coercing
        # during interpreter startup (on macOS).
        import _locale
        import os

        self.assertEqual(locale._parse_localename('UTF-8'), (None, 'UTF-8'))

        if hasattr(_locale, '_getdefaultlocale'):
            orig_getlocale = _locale._getdefaultlocale
            del _locale._getdefaultlocale
        else:
            orig_getlocale = None

        orig_env = {}
        try:
            for key in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'):
                if key in os.environ:
                    orig_env[key] = os.environ[key]
                    del os.environ[key]

            os.environ['LC_CTYPE'] = 'UTF-8'

            self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8'))

        finally:
            for k in orig_env:
                os.environ[k] = orig_env[k]

            if 'LC_CTYPE' not in orig_env:
                del os.environ['LC_CTYPE']

            if orig_getlocale is not None:
                _locale._getdefaultlocale = orig_getlocale
Пример #3
0
 def getExtraEncodings(self, extraEncodingLookup):
     # Calling undocumented method to save copying it, best not to crash if it has been renamed.
     # Don't do this on Windows, the variables concerned don't apply there anyway
     if extraEncodingLookup and os.name != "nt" and hasattr(locale, "_parse_localename"):
         # Copied from locale.getdefaultlocale, would be nice if we could actually call this code
         for variable in self.langVars:
             localename = extraEncodingLookup(variable)
             if localename:
                 if variable == 'LANGUAGE':
                     localename = localename.split(':')[0]
                 extraEncoding = locale._parse_localename(localename)[1]
                 if extraEncoding and extraEncoding not in self.encodings and extraEncoding.lower() not in self.encodings:
                     return [ extraEncoding ]
     return []
Пример #4
0
def getlocale(category=_locale.LC_CTYPE):

    localename = _locale._setlocale(category)
    if category == _locale.LC_ALL and ';' in localename:
        raise TypeError('category LC_ALL is not supported')

    locale = _locale._parse_localename(localename)

    code_page = locale[1]

    if code_page.isdigit() and int(code_page) in Locale.CODE_PAGES:
        code_page = Locale.CODE_PAGES[int(code_page)].replace('windows-', 'cp')

    return locale[0], code_page
Пример #5
0
 def getExtraEncodings(self, extraEncodingLookup):
     # Calling undocumented method to save copying it, best not to crash if it has been renamed.
     # Don't do this on Windows, the variables concerned don't apply there anyway
     if extraEncodingLookup and os.name != "nt" and hasattr(locale, "_parse_localename"):
         # Copied from locale.getdefaultlocale, would be nice if we could actually call this code
         for variable in self.langVars:
             localename = extraEncodingLookup(variable)
             if localename:
                 if variable == 'LANGUAGE':
                     localename = localename.split(':')[0]
                 extraEncoding = locale._parse_localename(localename)[1]
                 if extraEncoding and extraEncoding not in self.encodings and extraEncoding.lower() not in self.encodings:
                     return [extraEncoding]
     return []
Пример #6
0
def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
    try:
        import _locale as _locale_

        code, encoding = _locale_._getdefaultlocale()

        if code and code[:2] == "0x":
            code = _locale.windows_locale.get(int(code, 0))

        res = (code, encoding)

    except (ImportError, AttributeError):
        for variable in envvars:
            localename = os.environ.get(variable, None)
            if localename:
                if variable == 'LANGUAGE':
                    localename = localename.split(':')[0]
                break
        else:
            localename = 'C'

        res = _locale._parse_localename(localename)

    return res
Пример #7
0
Convert a restructured text document to html.

Inline math markup can uses the *math* directive, or it can use latex
style *\$expression\$*.  Math can be rendered using simple html and
unicode, or with mathjax.
"""

import re
from contextlib import contextmanager

# CRUFT: locale.getlocale() fails on some versions of OS X
# See https://bugs.python.org/issue18378
import locale
if hasattr(locale, '_parse_localename'):
    try:
        locale._parse_localename('UTF-8')
    except ValueError:
        _old_parse_localename = locale._parse_localename

        def _parse_localename(localename):
            code = locale.normalize(localename)
            if code == 'UTF-8':
                return None, code
            else:
                return _old_parse_localename(localename)

        locale._parse_localename = _parse_localename

from docutils.core import publish_parts
from docutils.writers.html4css1 import HTMLTranslator
from docutils.nodes import SkipNode
Пример #8
0
 def update_event(self, inp=-1):
     self.set_output_val(0, locale._parse_localename(self.input(0)))
Пример #9
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with "Meresco Core"; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# 
## end license ##

if not __debug__:
    raise AssertionError("Do not use optimized code, because Meresco uses assert statements. (See http://docs.python.org/release/2.5.2/ref/assert.html)")

from sys import getdefaultencoding as _getdefaultencoding
from locale import getdefaultlocale, _parse_localename
assert _getdefaultencoding() == 'utf-8', 'Please ensure that the default encoding is utf-8'
assert getdefaultlocale() == _parse_localename('en_US.UTF-8'), "We expect the default locale to be set to utf-8, e.g. use the environment setting LANG=en_US.UTF-8"

from observable import Observable, Transparent
from weightless.core import be as _be

from generatorutils import decorate, decorateWith, asyncreturn, asyncnoreturnvalue
from transaction import TransactionException, Transaction
from transactionscope import TransactionScope
from resourcemanager import ResourceManager

def be(*args, **kwargs):
    from warnings import warn
    warn("be from meresco.core is deprecated. Please use be from weightless.core.", DeprecationWarning)
    return _be(*args, **kwargs)
Пример #10
0
# along with "Meresco Core"; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
## end license ##

if not __debug__:
    raise AssertionError(
        "Do not use optimized code, because Meresco uses assert statements. (See http://docs.python.org/release/2.5.2/ref/assert.html)"
    )

from sys import getdefaultencoding as _getdefaultencoding
from locale import getdefaultlocale, _parse_localename
assert _getdefaultencoding(
) == 'utf-8', 'Please ensure that the default encoding is utf-8'
assert getdefaultlocale() == _parse_localename(
    'en_US.UTF-8'
), "We expect the default locale to be set to utf-8, e.g. use the environment setting LANG=en_US.UTF-8"

from .observable import Observable, Transparent
from weightless.core import be as _be

from .generatorutils import decorate, decorateWith, asyncreturn, asyncnoreturnvalue
from .transaction import TransactionException, Transaction
from .transactionscope import TransactionScope
from .resourcemanager import ResourceManager


def be(*args, **kwargs):
    from warnings import warn
    warn(
        "be from meresco.core is deprecated. Please use be from weightless.core.",