ldp_rs.py 2.2 KB

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