Skip to content

API Changes

Pre-release
Pre-release

Choose a tag to compare

@wharris wharris released this 29 Aug 10:45
· 93 commits to master since this release
  • Attributes have been renamed to properties.

  • The template token for CURIEs is now {rel}, rather than {relation}.

  • Improved API for Document().add_link. The second argument can now be a
    URI string or a Document object as well as a Link object. Additional
    keyword arguments are added to the link's properties.

  • Document and Link objects are now iterable, yeilding themselves
    exactly once, so single and multiple links for a relation can be treated the
    same with a for loop.

    Example:

    >>> import dougrain
    >>> doc = dougrain.Document.empty("http://localhost/")
    >>> doc.add_link('child', "/1")
    >>> doc.links['child']
    <Link 'http://localhost/1'>
    >>> [link.href for link in doc.links['child']]
    ['/1']
    >>> doc.add_link('child', "/2")
    >>> doc.links['child']
    [<Link 'http://localhost/1'>, <Link 'http://localhost/2'>]
    >>> [link.href for link in doc.links['child']]
    ['/1', '/2']
  • Document now treats link relationship types as equal if they are
    equivalent to the same URI when expanded.

    Example:

    >>> import dougrain
    >>> doc = dougrain.Document.empty("http://localhost/")
    >>> doc.set_curie('role', "/roles/{rel}")
    >>> doc.add_link("role:app", "/apps/1")
    >>> doc.add_link("/roles/app", "/apps/2")
    >>> doc.add_link("http://localhost/roles/app", "/apps/3")
    >>> [link.href for link in doc.links["role:app"]]
    ['/apps/1', '/apps/2', '/apps/3']
    >>> [link.href for link in doc.links["/roles/app"]]
    ['/apps/1', '/apps/2', '/apps/3']
    >>> [link.href for link in doc.links["http://localhost/roles/app"]]
    ['/apps/1', '/apps/2', '/apps/3']