MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / as_unicode

Function as_unicode

src/commoncode/text.py:136–147  ·  view source on GitHub ↗

Return a unicode string for a string be it bytes or unicode.

(s)

Source from the content-addressed store, hash-verified

134
135
136def as_unicode(s):
137 """
138 Return a unicode string for a string be it bytes or unicode.
139 """
140 if isinstance(s, str):
141 return s
142 if s == b"":
143 return ""
144 if not s:
145 return s
146 assert isinstance(s, bytes), "s must be bytes but is: {}".format(s)
147 return UnicodeDammit(s).unicode_markup

Callers 6

safe_pathFunction · 0.90
nopunctuationFunction · 0.70
unixlinesepFunction · 0.70
nolinesepFunction · 0.70
toasciiFunction · 0.70
python_safe_nameFunction · 0.70

Calls 2

UnicodeDammitClass · 0.85
formatMethod · 0.45

Tested by

no test coverage detected