MCPcopy Index your code
hub / github.com/ipython/ipython / get_stream_enc

Function get_stream_enc

IPython/utils/encoding.py:25–36  ·  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: Any, default: str | None = None)

Source from the content-addressed store, hash-verified

23
24# to deal with the possibility of sys.std* not being a stream at all
25def get_stream_enc(stream: Any, default: str | None = None) -> str | None:
26 """Return the given stream's encoding or a default.
27
28 There are cases where ``sys.std*`` might not actually be a stream, so
29 check for the encoding attribute prior to returning it, and return
30 a default if it doesn't exist or evaluates as False. ``default``
31 is None if not provided.
32 """
33 if not hasattr(stream, "encoding") or not stream.encoding:
34 return default
35 else:
36 return stream.encoding
37
38
39_sentinel: object = object()

Callers 1

getdefaultencodingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…