MCPcopy Create free account
hub / github.com/ipython/ipython / get_stream_enc

Function get_stream_enc

IPython/utils/encoding.py:21–32  ·  view source on GitHub ↗

Return the given stream's encoding or a default. There are cases where ``sys.std*`` might not actually be a stream, so check for the encoding attribute prior to returning it, and return a default if it doesn't exist or evaluates as False. ``default`` is None if not provided.

(stream, default=None)

Source from the content-addressed store, hash-verified

19
20# to deal with the possibility of sys.std* not being a stream at all
21def get_stream_enc(stream, default=None):
22 """Return the given stream's encoding or a default.
23
24 There are cases where ``sys.std*`` might not actually be a stream, so
25 check for the encoding attribute prior to returning it, and return
26 a default if it doesn't exist or evaluates as False. ``default``
27 is None if not provided.
28 """
29 if not hasattr(stream, 'encoding') or not stream.encoding:
30 return default
31 else:
32 return stream.encoding
33
34# Less conservative replacement for sys.getdefaultencoding, that will try
35# to match the environment.

Callers 2

split_user_inputFunction · 0.90
getdefaultencodingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected