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)
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
def teardown_class(cls): if hasattr(cls, "oldlocale"): setlocale(LC_ALL, cls.oldlocale)
def setup_class(cls): try: cls.oldlocale = setlocale(LC_ALL, "pl_PL.utf8") except LocaleError: py.test.skip("polish locale unsupported")