ldp_nr.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from rdflib import Graph
  2. from rdflib.namespace import RDF, XSD
  3. from rdflib.resource import Resource
  4. from rdflib.term import URIRef, Literal, Variable
  5. from lakesuperior.config_parser import config
  6. from lakesuperior.dictionaries.namespaces import ns_collection as nsc
  7. from lakesuperior.model.ldpr import Ldpr, transactional, must_exist
  8. from lakesuperior.util.digest import Digest
  9. class LdpNr(Ldpr):
  10. '''LDP-NR (Non-RDF Source).
  11. Definition: https://www.w3.org/TR/ldp/#ldpnr
  12. '''
  13. base_types = {
  14. nsc['fcrepo'].Binary,
  15. nsc['ldp'].NonRDFSource,
  16. }
  17. ## LDP METHODS ##
  18. def get(self, *args, **kwargs):
  19. raise NotImplementedError()
  20. def post(self, stream):
  21. '''
  22. Create a new binary resource with a corresponding RDF representation.
  23. @param file (Stream) A Stream resource representing the uploaded file.
  24. '''
  25. #self._logger.debug('Data: {}'.format(data[:256]))
  26. metadata_rsrc = Resource(Graph(), self.urn)
  27. for t in self.base_types:
  28. metadata_rsrc.add(RDF.type, t)
  29. cksum = self.nonrdfly.persist(stream)
  30. cksum_term = URIRef('urn:sha1:{}'.format(cksum))
  31. metadata_rsrc.add(nsc['premis'].hasMessageDigest, cksum_term)
  32. def put(self, data):
  33. raise NotImplementedError()