def Parse(self, textinput, mime_type='application/magic-envelope+xml'):
    ns = 'http://salmon-protocol.org/ns/magic-env'

    # TODO(jpanzer): Support JSON format, do real sanity checks against
    # mime type
    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 = d.getroot()
    else:
      raise ValueError('Unrecognized input format')

    def Squeeze(s):  # Remove all whitespace
      return re.sub(_WHITESPACE_RE, '', s)

    data_el = env_el.find(_ME_NS+'data')

    # Pull magic envelope fields out into dict. Don't forget
    # to remove leading and trailing whitepace from each field's
    # 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')),
    )
Helper method to generate URLs.
dataset/ETHPy150Open mimecuvalo/helloworld/packages/magicsig/__init__.py/MagicEnvelopeProtocol.Parse--crossover with--dataset/ETHPy150Open home-assistant/home-assistant/tests/components/device_tracker/test_locative.py/_url