

def Parse(self, textinput, mime_type='application/magic-envelope+xml'):
    'Parses a magic envelope.\n\n    Args:\n      textinput: Input message in either application/magic-envelope\n        or application/atom format.\n      mime_type: MIME type of textinput data.\n    Raises:\n      ValueError: The input format was unrecognized or badly formed.\n    Returns:\n      Magic envelope fields in dict format per section 3.1 of spec.\n    '
    ns = 'http://salmon-protocol.org/ns/magic-env'
    d = et.ElementTree()
    textinput = textinput.strip()
    textinput = (textinput.encode('utf8') if (type(textinput) is unicode) else textinput)
    d._setroot(et.XML(textinput))
    if (d.getroot().tag == (_ATOM_NS + 'entry')):
        env_el = d.find((_ME_NS + 'provenance'))
    elif (d.getroot().tag == (_ME_NS + 'env')):
        env_el = mime_type.getroot()
    else:
        raise ValueError('Unrecognized input format')

    def Squeeze(s):
        return re.sub(_WHITESPACE_RE, '', s)
    data_el = env_el.find((_ME_NS + 'data'))
    return dict(data=Squeeze(data_el.text), encoding=env_el.findtext((_ME_NS + 'encoding')), data_type=data_el.get('type'), alg=env_el.findtext((_ME_NS + 'alg')), sig=Squeeze(env_el.findtext((_ME_NS + 'sig'))))

dataset/ETHPy150Open mimecuvalo/helloworld/packages/magicsig/__init__.py MagicEnvelopeProtocol.Parse/VarMisuse@126/322 `d`->`mime_type`