oldman.rest package

oldman.rest.crud module

class oldman.rest.crud.CRUDController(manager)[source]

Bases: object

A CRUDController object helps you to manipulate your Resource objects in a RESTful-like manner.

Please note that REST/HTTP only manipulates hash-less IRIs. A hash IRI is the combination of a hash-less IRI (fragment-less IRI) and a fragment. Multiple hashed IRIs may have the same hash-less IRI and only differ by their fragment values. This is a concern for each type of HTTP operation.

This class is generic and does not support the Collection pattern (there is no append method).

Parameters:managerResourceManager object.

Possible improvements:

  • Add a PATCH method.
delete(hashless_iri)[source]

Deletes every Resource object having this hash-less IRI.

Parameters:hashless_iri – Hash-less IRI.
get(hashless_iri, content_type='text/turtle')[source]

Gets the main Resource object having its hash-less IRI.

When multiple Resource objects have this hash-less IRI, one of them has to be selected. If one has no fragment value, it is selected. Otherwise, this selection is currently arbitrary.

TODO: stop selecting the resources and returns the list.

Raises an ObjectNotFoundError exception if no resource is found.

Parameters:
  • hashless_iri – hash-less of the resource.
  • content_type – Content type of its representation.
Returns:

The selected Resource object.

update(hashless_iri, document_content, content_type, allow_new_type=False, allow_type_removal=False)[source]

Updates every Resource object having this hash-less IRI.

Raises an OMDifferentBaseIRIError exception if tries to create of modify non-blank Resource objects that have a different hash-less IRI. This restriction is motivated by security concerns.

Accepts JSON, JSON-LD and RDF formats supported by RDFlib.

Parameters:
  • hashless_iri – Document IRI.
  • document_content – Payload.
  • content_type – Content type of the payload.
  • allow_new_type – If True, new types can be added. Defaults to False. See oldman.resource.Resource.full_update() for explanations about the security concerns.
  • allow_type_removal – If True, new types can be removed. Same security concerns than above. Defaults to False.