async def dereference(self, profile: Profile, did_url: str) -> Union[Service, VerificationMethod]: """Dereference a DID URL to its corresponding DID Doc object.""" # TODO Use cached DID Docs when possible try: did_url = DIDUrl.parse(did_url) doc = await self.resolve(profile, did_url.did) return doc.dereference(did_url) except DIDError as err: raise ResolverError( "Failed to parse DID URL from {}".format(did_url)) from err
async def dereference(self, profile: Profile, did_url: str) -> Resource: """Dereference a DID URL to its corresponding DID Doc object.""" # TODO Use cached DID Docs when possible try: parsed = DIDUrl.parse(did_url) if not parsed.did: raise ValueError("Invalid DID URL") doc_dict = await self.resolve(profile, parsed.did) return pydid.deserialize_document(doc_dict).dereference(parsed) except DIDError as err: raise ResolverError( "Failed to parse DID URL from {}".format(did_url)) from err
async def dereference(self, profile: Profile, did_url: str, *, cls: Type[ResourceType] = Resource) -> ResourceType: """Dereference a DID URL to its corresponding DID Doc object.""" # TODO Use cached DID Docs when possible try: parsed = DIDUrl.parse(did_url) if not parsed.did: raise ValueError("Invalid DID URL") except DIDError as err: raise ResolverError( "Failed to parse DID URL from {}".format(did_url)) from err doc_dict = await self.resolve(profile, parsed.did) # Use non-conformant doc as the "least common denominator" try: return NonconformantDocument.deserialize(doc_dict).dereference_as( cls, parsed) except IDNotFoundError as error: raise ResolverError( "Failed to dereference DID URL: {}".format(error)) from error
def test_relative_url(): url = DIDUrl.parse("/some/path?query=value#fragment") assert not url.did assert url.path assert url.query assert url.fragment
def test_did_url_parse_x(bad_url): with pytest.raises(InvalidDIDUrlError): DIDUrl.parse(bad_url)
def test_did_url_neq(lhs, rhs): lhs = DIDUrl.parse(lhs) assert lhs != rhs rhs = DIDUrl.parse(rhs) assert lhs != rhs assert lhs != {"not a": "DIDUrl"}
def test_did_url_parse(url, parts): assert DIDUrl.parse(url) == DIDUrl(**parts)