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

Function networkString

src/twisted/python/compat.py:442–461  ·  view source on GitHub ↗

Convert a string to L{bytes} using ASCII encoding. This is useful for sending text-like bytes that are constructed using string interpolation. For example:: networkString("Hello %d" % (n,)) @param s: A string to convert to bytes. @type s: L{str} @raise UnicodeEr

(s: str)

Source from the content-addressed store, hash-verified

440
441
442def networkString(s: str) -> bytes:
443 """
444 Convert a string to L{bytes} using ASCII encoding.
445
446 This is useful for sending text-like bytes that are constructed using
447 string interpolation. For example::
448
449 networkString("Hello %d" % (n,))
450
451 @param s: A string to convert to bytes.
452 @type s: L{str}
453
454 @raise UnicodeError: The input string is not ASCII encodable.
455 @raise TypeError: The input is not L{str}.
456
457 @rtype: L{bytes}
458 """
459 if not isinstance(s, str):
460 raise TypeError("Can only convert strings to bytes")
461 return s.encode("ascii")
462
463
464@deprecated(Version("Twisted", 21, 2, 0), replacement="os.environb")

Callers 15

getChallengeMethod · 0.90
formatResponseMethod · 0.90
test_invalidOpaqueMethod · 0.90
test_oldNonceMethod · 0.90
setUpMethod · 0.90
test_destinationMethod · 0.90
setUpMethod · 0.90
test_equalityMethod · 0.90
_packAttributesMethod · 0.90
_cbOpenFileMethod · 0.90

Calls 1

encodeMethod · 0.45

Tested by 15

formatResponseMethod · 0.72
test_invalidOpaqueMethod · 0.72
test_oldNonceMethod · 0.72
setUpMethod · 0.72
test_destinationMethod · 0.72
setUpMethod · 0.72
test_equalityMethod · 0.72
_underUnderPathTestMethod · 0.72
_uncleanSocketTestMethod · 0.72