MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Binary

Class Binary

tools/python-3.11.9-amd64/Lib/xmlrpc/client.py:393–426  ·  view source on GitHub ↗

Wrapper for binary data.

Source from the content-addressed store, hash-verified

391# @param data An 8-bit string containing arbitrary data.
392
393class Binary:
394 """Wrapper for binary data."""
395
396 def __init__(self, data=None):
397 if data is None:
398 data = b""
399 else:
400 if not isinstance(data, (bytes, bytearray)):
401 raise TypeError("expected bytes or bytearray, not %s" %
402 data.__class__.__name__)
403 data = bytes(data) # Make a copy of the bytes!
404 self.data = data
405
406 ##
407 # Get buffer contents.
408 #
409 # @return Buffer contents, as an 8-bit string.
410
411 def __str__(self):
412 return str(self.data, "latin-1") # XXX encoding?!
413
414 def __eq__(self, other):
415 if isinstance(other, Binary):
416 other = other.data
417 return self.data == other
418
419 def decode(self, data):
420 self.data = base64.decodebytes(data)
421
422 def encode(self, out):
423 out.write("<value><base64>\n")
424 encoded = base64.encodebytes(self.data)
425 out.write(encoded.decode('ascii'))
426 out.write("</base64></value>\n")
427
428def _binary(data):
429 # decode xml element contents into a Binary structure

Callers 2

_binaryFunction · 0.70
end_base64Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected