def write(self, framing=True): """Return a string representation of the data. Validation is always performed, so calling this function on invalid data may raise a ValueError. Arguments: framing (bool): if true, append a framing bit (see load) """ self.validate() def _encode(value): if not isinstance(value, bytes): return value.encode('utf-8') return value f = BytesIO() vendor = _encode(self.vendor) f.write(cdata.to_uint_le(len(vendor))) f.write(vendor) f.write(cdata.to_uint_le(len(self))) for tag, value in self: tag = _encode(tag) value = _encode(value) comment = tag + b"=" + value f.write(cdata.to_uint_le(len(comment))) f.write(comment) if framing: f.write(b"\x01") return f.getvalue()
def write(self, framing=True): """Return a string representation of the data. Validation is always performed, so calling this function on invalid data may raise a ValueError. Keyword arguments: * framing -- if true, append a framing bit (see load) """ self.validate() def _encode(value): if not isinstance(value, bytes): return value.encode('utf-8') return value f = BytesIO() vendor = _encode(self.vendor) f.write(cdata.to_uint_le(len(vendor))) f.write(vendor) f.write(cdata.to_uint_le(len(self))) for tag, value in self: tag = _encode(tag) value = _encode(value) comment = tag + b"=" + value f.write(cdata.to_uint_le(len(comment))) f.write(comment) if framing: f.write(b"\x01") return f.getvalue()
def write(self, framing=True): """Return a string representation of the data. Validation is always performed, so calling this function on invalid data may raise a ValueError. Keyword arguments: framing -- if true, append a framing bit (see load) """ self.validate() f = BytesIO() f.write(cdata.to_uint_le(len(self.vendor.encode('utf-8')))) f.write(self.vendor.encode('utf-8')) f.write(cdata.to_uint_le(len(self))) for tag, value in self._internal: if isinstance(value, bytes): value = value.decode("utf-8") comment = tag.encode('ascii') + b"=" + value.encode('utf-8') f.write(cdata.to_uint_le(len(comment))) f.write(comment) if framing: f.write(b"\x01") return f.getvalue()
def write(self, framing=True): """Return a string representation of the data. Validation is always performed, so calling this function on invalid data may raise a ValueError. Keyword arguments: framing -- if true, append a framing bit (see load) """ self.validate() f = StringIO() f.write(cdata.to_uint_le(len(self.vendor.encode('utf-8')))) f.write(self.vendor.encode('utf-8')) f.write(cdata.to_uint_le(len(self))) for tag, value in self: comment = "%s=%s" % (tag, value.encode('utf-8')) f.write(cdata.to_uint_le(len(comment))) f.write(comment) if framing: f.write("\x01") return f.getvalue()