MCPcopy Index your code
hub / github.com/python/cpython / Binary

Class Binary

Lib/xmlrpc/client.py:367–400  ·  view source on GitHub ↗

Wrapper for binary data.

Source from the content-addressed store, hash-verified

365# @param data An 8-bit string containing arbitrary data.
366
367class Binary:
368 """Wrapper for binary data."""
369
370 def __init__(self, data=None):
371 if data is None:
372 data = b""
373 else:
374 if not isinstance(data, (bytes, bytearray)):
375 raise TypeError("expected bytes or bytearray, not %s" %
376 data.__class__.__name__)
377 data = bytes(data) # Make a copy of the bytes!
378 self.data = data
379
380 ##
381 # Get buffer contents.
382 #
383 # @return Buffer contents, as an 8-bit string.
384
385 def __str__(self):
386 return str(self.data, "latin-1") # XXX encoding?!
387
388 def __eq__(self, other):
389 if isinstance(other, Binary):
390 other = other.data
391 return self.data == other
392
393 def decode(self, data):
394 self.data = base64.decodebytes(data)
395
396 def encode(self, out):
397 out.write("<value><base64>\n")
398 encoded = base64.encodebytes(self.data)
399 out.write(encoded.decode('ascii'))
400 out.write("</base64></value>\n")
401
402def _binary(data):
403 # decode xml element contents into a Binary structure

Callers 2

_binaryFunction · 0.85
end_base64Method · 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…