MCPcopy Create free account
hub / github.com/twisted/twisted / nativeString

Function nativeString

src/twisted/python/compat.py:329–344  ·  view source on GitHub ↗

Convert C{bytes} or C{str} to C{str} type, using ASCII encoding if conversion is necessary. @raise UnicodeError: The input string is not ASCII encodable/decodable. @raise TypeError: The input is neither C{bytes} nor C{str}.

(s: AnyStr)

Source from the content-addressed store, hash-verified

327
328
329def nativeString(s: AnyStr) -> str:
330 """
331 Convert C{bytes} or C{str} to C{str} type, using ASCII encoding if
332 conversion is necessary.
333
334 @raise UnicodeError: The input string is not ASCII encodable/decodable.
335 @raise TypeError: The input is neither C{bytes} nor C{str}.
336 """
337 if not isinstance(s, (bytes, str)):
338 raise TypeError("%r is neither bytes nor str" % s)
339 if isinstance(s, bytes):
340 return s.decode("ascii")
341 else:
342 # Ensure we're limited to ASCII subset:
343 s.encode("ascii")
344 return s
345
346
347def _matchingString(constantString, inputString):

Callers 15

decodeMethod · 0.90
getChallengeMethod · 0.90
filenameToModuleNameFunction · 0.90
_isPythonIdentifierFunction · 0.90
__init__Method · 0.90
_absPathMethod · 0.90
request_exit_signalMethod · 0.90
secureConnectionMethod · 0.90
gotGlobalRequestMethod · 0.90
gotHasKeyMethod · 0.90
getPasswordMethod · 0.90
_getPasswordMethod · 0.90

Calls 2

decodeMethod · 0.45
encodeMethod · 0.45

Tested by 14

_getPasswordMethod · 0.72
getpassMethod · 0.72
assertNativeStringMethod · 0.72
_ipFunction · 0.72
test_authInfoInURLMethod · 0.72
testFetchHeadersMethod · 0.72
test_synchronousFetchMethod · 0.72