예제 #1
0
def setlocale(space, category, w_locale=None):
    "(integer,string=None) -> string. Activates/queries locale processing."

    if space.is_w(w_locale, space.w_None) or w_locale is None:
        locale = None
    else:
        locale = space.str_w(w_locale)
    try:
        result = rlocale.setlocale(category, locale)
    except rlocale.LocaleError, e:
        raise rewrap_error(space, e)
예제 #2
0
파일: interp_locale.py 프로젝트: njues/Sypy
def setlocale(space, category, w_locale=None):
    "(integer,string=None) -> string. Activates/queries locale processing."

    if space.is_w(w_locale, space.w_None) or w_locale is None:
        locale = None
    else:
        locale = space.str_w(w_locale)
    try:
        result = rlocale.setlocale(category, locale)
    except rlocale.LocaleError, e:
        raise rewrap_error(space, e)
예제 #3
0
def _getfilesystemencoding(space):
    if (space.config.translation.type_system == 'ootype'):
        # XXX: fix this for ootype
        return base_encoding
    #
    encoding = base_encoding
    if rlocale.HAVE_LANGINFO and rlocale.CODESET:
        try:
            oldlocale = rlocale.setlocale(rlocale.LC_CTYPE, None)
            rlocale.setlocale(rlocale.LC_CTYPE, "")
            try:
                loc_codeset = rlocale.nl_langinfo(rlocale.CODESET)
                if loc_codeset:
                    codecmod = space.getbuiltinmodule('_codecs')
                    w_res = space.call_method(codecmod, 'lookup',
                                              space.wrap(loc_codeset))
                    if space.is_true(w_res):
                        encoding = loc_codeset
            finally:
                rlocale.setlocale(rlocale.LC_CTYPE, oldlocale)
        except rlocale.LocaleError:
            pass
    return encoding
예제 #4
0
def _getfilesystemencoding(space):
    if (space.config.translation.type_system == 'ootype'):
        # XXX: fix this for ootype
        return base_encoding
    #
    encoding = base_encoding
    if rlocale.HAVE_LANGINFO and rlocale.CODESET:
        try:
            oldlocale = rlocale.setlocale(rlocale.LC_CTYPE, None)
            rlocale.setlocale(rlocale.LC_CTYPE, "")
            try:
                loc_codeset = rlocale.nl_langinfo(rlocale.CODESET)
                if loc_codeset:
                    codecmod = space.getbuiltinmodule('_codecs')
                    w_res = space.call_method(codecmod, 'lookup',
                                              space.wrap(loc_codeset))
                    if space.is_true(w_res):
                        encoding = loc_codeset
            finally:
                rlocale.setlocale(rlocale.LC_CTYPE, oldlocale)
        except rlocale.LocaleError:
            pass
    return encoding
예제 #5
0
파일: test_rlocale.py 프로젝트: njues/Sypy
 def teardown_class(cls):
     if hasattr(cls, "oldlocale"):
         setlocale(LC_ALL, cls.oldlocale)
예제 #6
0
파일: test_rlocale.py 프로젝트: njues/Sypy
 def setup_class(cls):
     try:
         cls.oldlocale = setlocale(LC_ALL, "pl_PL.utf8")
     except LocaleError:
         py.test.skip("polish locale unsupported")