def fromHTML(cls, uri, html): """Parse the given document as HTML looking for an OpenID <link rel=...> @rtype: [OpenIDServiceEndpoint] """ discovery_types = [ (OPENID_2_0_TYPE, 'openid2.provider', 'openid2.local_id'), (OPENID_1_1_TYPE, 'openid.server', 'openid.delegate'), ] link_attrs = html_parse.parseLinkAttrs(html) services = [] for type_uri, op_endpoint_rel, local_id_rel in discovery_types: op_endpoint_url = html_parse.findFirstHref( link_attrs, op_endpoint_rel) if op_endpoint_url is None: continue service = cls() service.claimed_id = uri service.local_id = html_parse.findFirstHref( link_attrs, local_id_rel) service.server_url = op_endpoint_url service.type_uris = [type_uri] services.append(service) return services
def runTest(self): actual = parseLinkAttrs(self.case) i = 0 for optional, exp_link in self.expected: if optional: if i >= len(actual): continue act_link = actual[i] for k, (o, v) in list(exp_link.items()): if o: act_v = act_link.get(k) if act_v is None: continue else: act_v = act_link[k] if optional and v != act_v: break self.assertEqual(v, act_v) else: i += 1 assert i == len(actual)