How to use pydataportability.discoveryΒΆ

Theoretically you shouldn’t have much to do but feeding a URI into the discovery mechanism which will then return a Resource object as defined in pydataportability.model.resource and explained in the documentation of pydataportability.xrd.

Here is an example where we assume that the URI for discovery is stored in uri.

import zope.configuration.xmlconfig
from pydataportability.discovery import discover

zope.configuration.xmlconfig.file('configure.zcml', package=pydataportability.webfinger)

resource = discover(uri, ['hostmeta'])
print "Subject: ", resource.subject
print

for link in resource.links:
    print "Rels: ", link.rels
    print "URIs:", link.uris
    print "Media Types:", link.media_types
    print "Prio:", link.priority
    print "Templates:", link.templates
    print

There are two important parts to this. The first one is the line:

zope.configuration.xmlconfig.file('configure.zcml', package=pydataportability.discovery)

This initiates all the components used for the discovery process. It will e.g. setup all plugins you might have defined to control the discovery process. Usually you can use the predefined components though.

More on this can be found in the Extending and configuring the discovery process chapter.

The next important part is:

resource = discover(uri, ['hostmeta'])

Here the discovery function is used by calling it with the URI of the resource we want the Resource Description for and with a list of methods to try (hostmeta only in this case). Additionally you can give it a list of relationships you want it to search for only.

Note

At the time of this writing only hostmeta is implemented which is mainly used for WebFinger discovery. Later we will also implement the remaining methods linkheader and link as defined in the LRDD specification.

This method will return an instance of pydataportability.model.resource.models.Resource. You can find a description of it’s attributes and methods in the documentation of pydataportability.xrd.

Previous topic

Installing pydataportability.discovery

Next topic

Implementation Details

This Page

Quick search