def __init__(self, e): if isinstance(e, str): try: e = xml.fromstring(e) except xml.ParseError: logger.warn("Skipping malformed line: {line}".format(line=e), exc_info=True) return if isinstance(e, xml.Element): e = etree_to_dict(e) if isinstance(e, dict): e = DictObject.objectify(e) assert isinstance(e, DictObject) assert hasattr(e.item, "type") self.type = ascii_integers_to_string(e.item.type) self.code = ascii_integers_to_string(e.item.code) self.length = int(e.item.length) if "data" in e.item: assert self.length > 0 # length is zero if data is undefined. self.data = encoded_to_str(e.item.data["#text"], e.item.data["@encoding"], as_bytes=True) if e.item.data["@encoding"] == "base64": self._data_base64 = to_unicode(e.item.data["#text"]) else: self._data_base64 = None else: assert self.length == 0 # length is zero if data is undefined. self.data = to_binary("") self._data_base64 = None
def base64(self): if self._base64: return self._base64 if self._binary: self._base64 = encodebytes(to_binary(self._binary)) return self._base64 else: return None
def base64(self): if self._base64: print("AirplayCoverArt: base 64 - created size %d" % len(self._base64)) return self._base64 if self._binary: print("AirplayCoverArt: base 64: binary - created size %d" % len(self._binary)) self._base64 = encodebytes(to_binary(self._binary)) return self._base64 else: return None
def do_write_text(self, msg, content_type="text/plain", is_binary=False): # Now do servery stuff. if not is_binary: msg = to_binary(msg) if msg is None: self.send_response(404) self.end_headers() return self.send_response(200) self.send_header("Content-type", content_type) self.send_header("Content-Length", str(len(msg))) self.end_headers() self.wfile.write(msg) return
def test_other_impl(self): false = False true = True null = None test_data = { 'CAADBAADwwADmFmqDf6xBrPTReqHFgQ': { "version": 4, "subVersion": 22, "typeId": 8, "dc_id": 4, "hasReference": false, "hasWebLocation": false, "type": "sticker", "id": 984697977903775939, "access_hash": -8653026958495010306 }, 'CAACAgQAAxkBAAIC4l9CWDGzVUcDejU0TETLWbOdfsCoAALDAAOYWaoN_rEGs9NF6ocbBA': { "version": 4, "subVersion": 27, "typeId": 8, "dc_id": 4, "hasReference": true, "hasWebLocation": false, "type": "sticker", "fileReference": "01000002e25f425831b35547037a35344c44cb59b39d7ec0a8", "id": 984697977903775939, "access_hash": -8653026958495010306 }, 'CAADBAADwwADmFmqDf6xBrPTReqHAg': { "version": 2, "subVersion": 0, "typeId": 8, "dc_id": 4, "hasReference": false, "hasWebLocation": false, "type": "sticker", "id": 984697977903775939, "access_hash": -8653026958495010306 }, 'CAADAgAD8wkAAgKLowABpAz7kZfM7jcC': { "version": 2, "subVersion": 0, "typeId": 8, "dc_id": 2, "hasReference": false, "hasWebLocation": false, "type": "sticker", "id": 46033261910034931, "access_hash": 4030383667904449700 }, 'CAACAgIAAxkBAAIBGV9DozZKicI-6IkNYlzxMUPaNnwBAALzCQACAoujAAGkDPuRl8zuNxsE': { "version": 4, "subVersion": 27, "typeId": 8, "dc_id": 2, "hasReference": true, "hasWebLocation": false, "type": "sticker", "fileReference": "01000001195f43a3364a89c23ee8890d625cf13143da367c01", "id": 46033261910034931, "access_hash": 4030383667904449700 }, 'BQADAgAD3AkAAgKLowABKlAd1pemg-gC': { "version": 2, "subVersion": 0, "typeId": 5, "dc_id": 2, "hasReference": false, "hasWebLocation": false, "type": "document", "id": 46033261910034908, "access_hash": -1692325863898656726 }, 'CAACAgIAAxkBAAIEVF9Do80olppb0490gLH2I1cszuoMAALcCQACAoujAAEqUB3Wl6aD6BsE': { "version": 4, "subVersion": 27, "typeId": 8, "dc_id": 2, "hasReference": true, "hasWebLocation": false, "type": "sticker", "fileReference": "01000004545f43a3cd28969a5bd38f7480b1f623572cceea0c", "id": 46033261910034908, "access_hash": -1692325863898656726 }, 'CAADAgADIwYAAmpiTwttSWWW_Tc0aQI': { "version": 2, "subVersion": 0, "typeId": 8, "dc_id": 2, "hasReference": false, "hasWebLocation": false, "type": "sticker", "id": 814978264983406115, "access_hash": 7580745635060861293 }, 'CAACAgIAAxkBAAIEVl9DpKV6azEUxxqd204SZQzixxO0AAIjBgACamJPC21JZZb9NzRpGwQ': { "version": 4, "subVersion": 27, "typeId": 8, "dc_id": 2, "hasReference": true, "hasWebLocation": false, "type": "sticker", "fileReference": "01000004565f43a4a57a6b3114c71a9ddb4e12650ce2c713b4", "id": 814978264983406115, "access_hash": 7580745635060861293 }, } for file_id, expected in test_data.items(): obj = FileId.from_file_id(file_id) self.assertIsInstance(obj, FileId, msg=f'file_id = {file_id!r}') self.assertIsInstance(obj, DocumentFileId, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('version'), obj.version, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('subVersion'), obj.sub_version, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('typeId'), obj.type_id, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('type'), obj.type_detailed, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('dc_id'), obj.dc_id, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('hasReference'), obj.has_reference, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('hasWebLocation'), obj.has_web_location, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('id'), obj.id, msg=f'file_id = {file_id!r}') self.assertEqual(expected.pop('access_hash', None), obj.access_hash, msg=f'file_id = {file_id!r}') self.assertEqual( to_binary(expected.pop('fileReference', b'')), encode((obj.file_reference if obj.file_reference else b''), 'hex'), msg=f'file_id = {file_id!r}') self.assertEqual( {}, expected, msg=f'file_id = {file_id!r} - array shall be empty now.')
def data_base64(self): if self._data_base64: return self._data_base64 else: return encodebytes(to_binary(self.data))