ldp_rs.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import logging
  2. from rdflib import Graph
  3. from lakesuperior import env
  4. from lakesuperior.globals import RES_UPDATED
  5. from lakesuperior.dictionaries.namespaces import ns_collection as nsc
  6. from lakesuperior.model.ldp.ldpr import Ldpr
  7. logger = logging.getLogger(__name__)
  8. class LdpRs(Ldpr):
  9. """
  10. LDP-RS (LDP RDF source).
  11. https://www.w3.org/TR/ldp/#ldprs
  12. """
  13. def __init__(self, uuid, repr_opts={}, handling='lenient', **kwargs):
  14. """
  15. Extends :meth:`Ldpr.__init__`by adding LDP-RS specific parameters.
  16. :param str handling: One of ``strict``, ``lenient`` (the default) or
  17. ``none``. ``strict`` raises an error if a server-managed term is in the
  18. graph. ``lenient`` removes all sever-managed triples encountered.
  19. ``none`` skips all server-managed checks. It is used for internal
  20. modifications.
  21. """
  22. super().__init__(uuid, **kwargs)
  23. self.base_types = super().base_types | {
  24. nsc['fcrepo'].Container,
  25. nsc['ldp'].Container,
  26. }
  27. # provided_imr can be empty. If None, it is an outbound resource.
  28. if self.provided_imr is not None:
  29. self.workflow = self.WRKF_INBOUND
  30. else:
  31. self.workflow = self.WRKF_OUTBOUND
  32. self._imr_options = repr_opts
  33. self.handling = handling
  34. class Ldpc(LdpRs):
  35. """LDPC (LDP Container)."""
  36. def __init__(self, uuid, *args, **kwargs):
  37. super().__init__(uuid, *args, **kwargs)
  38. self.base_types |= {
  39. nsc['fcrepo'].Container,
  40. nsc['ldp'].Container,
  41. }
  42. class LdpBc(Ldpc):
  43. """LDP-BC (LDP Basic Container)."""
  44. def __init__(self, uuid, *args, **kwargs):
  45. super().__init__(uuid, *args, **kwargs)
  46. self.base_types |= {
  47. nsc['ldp'].BasicContainer,
  48. }
  49. class LdpDc(Ldpc):
  50. """LDP-DC (LDP Direct Container)."""
  51. def __init__(self, uuid, *args, **kwargs):
  52. super().__init__(uuid, *args, **kwargs)
  53. self.base_types |= {
  54. nsc['ldp'].DirectContainer,
  55. }
  56. class LdpIc(Ldpc):
  57. """LDP-IC (LDP Indirect Container)."""
  58. def __init__(self, uuid, *args, **kwargs):
  59. super().__init__(uuid, *args, **kwargs)
  60. self.base_types |= {
  61. nsc['ldp'].IndirectContainer,
  62. }