def parse(client, xml_data): data = StringIO.StringIO(xml_data) try: element = ElementTree.parse(data).getroot().attrib except: raise MSNObjectParseError(xml_data) creator = element["Creator"] size = int(element["Size"]) type = int(element["Type"]) if "Location" in element: location = xml.unescape(element["Location"]) else: location = "0" if "Friendly" in element: friendly = b64_decode(xml.unescape(element["Friendly"])) else: friendly = '\x00\x00' shad = element.get("SHA1D", None) if shad is not None: try: shad = b64_decode(shad) except TypeError: logger.warning("Invalid SHA1D in MSNObject: %s" % shad) shad = None shac = element.get("SHA1C", None) if shac is not None: try: shac = b64_decode(shac) except TypeError: logger.warning("Invalid SHA1C in MSNObject: %s" % shac) shac = None try: result = MSNObject(creator, size, type, location, friendly, shad, shac) result._repr = xml_data except ValueError: raise MSNObjectParseError(xml_data) return result
def context(self): try: context = self.get_header("Context") return b64_decode(context) except (KeyError, TypeError): return None