19 from .encodingsniffer
import get_console_encoding, get_system_encoding
20 from .compat
import isatty
21 from .platform
import JYTHON, IRONPYTHON, PY3
22 from .robottypes
import is_unicode
23 from .unic
import unic
30 NON_TTY_ENCODING_CAN_BE_TRUSTED = \
31 not (IRONPYTHON
or JYTHON
and not os.getenv(
'PYTHONIOENCODING'))
46 if is_unicode(string)
and not (IRONPYTHON
and force):
48 encoding = {
'CONSOLE': CONSOLE_ENCODING,
49 'SYSTEM': SYSTEM_ENCODING}.get(encoding.upper(), encoding)
51 return string.decode(encoding)
64 if PY3
and encoding !=
'UTF-8':
65 return string.encode(encoding, errors).decode(encoding)
68 return string.encode(encoding, errors)
72 encoding = getattr(stream,
'encoding',
None)
73 if encoding
and (NON_TTY_ENCODING_CAN_BE_TRUSTED
or isatty(stream)):
75 return CONSOLE_ENCODING
if isatty(stream)
else SYSTEM_ENCODING
79 if PY3
or JYTHON
or IRONPYTHON:
92 return string.decode(SYSTEM_ENCODING)
102 string =
unic(string)
103 return string.encode(SYSTEM_ENCODING, errors)
def system_decode(string)
Decodes bytes from system (e.g.
def console_decode(string, encoding=CONSOLE_ENCODING, force=False)
Decodes bytes from console encoding to Unicode.
def system_encode(string, errors='replace')
Encodes Unicode to system encoding (e.g.
def _get_console_encoding(stream)
def console_encode(string, errors='replace', stream=sys.__stdout__)
Encodes Unicode to bytes in console or system encoding.
def get_system_encoding()
def get_console_encoding()