Beispiel #1
0
    def nl_langinfo(space, key):
        """nl_langinfo(key) -> string
        Return the value for the locale information associated with key."""

        try:
            return space.wrap(rlocale.nl_langinfo(key))
        except ValueError:
            raise oefmt(space.w_ValueError, "unsupported langinfo constant")
Beispiel #2
0
    def nl_langinfo(space, key):
        """nl_langinfo(key) -> string
        Return the value for the locale information associated with key."""

        try:
            return space.newtext(rlocale.nl_langinfo(key))
        except ValueError:
            raise oefmt(space.w_ValueError, "unsupported langinfo constant")
Beispiel #3
0
    def nl_langinfo(space, key):
        """nl_langinfo(key) -> string
        Return the value for the locale information associated with key."""

        try:
            w_val = space.newbytes(rlocale.nl_langinfo(key))
        except ValueError:
            raise oefmt(space.w_ValueError, "unsupported langinfo constant")
        return space.call_function(space.w_unicode, w_val,
             space.newtext('utf-8'), space.newtext('surrogateescape'))
Beispiel #4
0
def _getfilesystemencoding(space):
    encoding = base_encoding
    if rlocale.HAVE_LANGINFO:
        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.newtext(loc_codeset))
                    if space.is_true(w_res):
                        encoding = loc_codeset
            finally:
                rlocale.setlocale(rlocale.LC_CTYPE, oldlocale)
        except rlocale.LocaleError:
            pass
    return encoding
Beispiel #5
0
def device_encoding(space, fd):
    """device_encoding(fd) -> str

    Return a string describing the encoding of the device if the output
    is a terminal; else return None.
    """
    if not (rposix.is_valid_fd(fd) and os.isatty(fd)):
        return space.w_None
    if _WIN32:
        if fd == 0:
            return space.wrap('cp%d' % rwin32.GetConsoleCP())
        if fd in (1, 2):
            return space.wrap('cp%d' % rwin32.GetConsoleOutputCP())
    from rpython.rlib import rlocale
    if rlocale.HAVE_LANGINFO:
        codeset = rlocale.nl_langinfo(rlocale.CODESET)
        if codeset:
            return space.wrap(codeset)
    return space.w_None
Beispiel #6
0
def _getfilesystemencoding(space):
    encoding = base_encoding
    if rlocale.HAVE_LANGINFO:
        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
Beispiel #7
0
def device_encoding(space, fd):
    """device_encoding(fd) -> str

    Return a string describing the encoding of the device if the output
    is a terminal; else return None.
    """
    if not (rposix.is_valid_fd(fd) and os.isatty(fd)):
        return space.w_None
    if _WIN32:
        if fd == 0:
            return space.wrap('cp%d' % rwin32.GetConsoleCP())
        if fd in (1, 2):
            return space.wrap('cp%d' % rwin32.GetConsoleOutputCP())
    from rpython.rlib import rlocale
    if rlocale.HAVE_LANGINFO:
        codeset = rlocale.nl_langinfo(rlocale.CODESET)
        if codeset:
            return space.wrap(codeset)
    return space.w_None