Procházet zdrojové kódy

Update module paths.

Stefano Cossu před 5 roky
rodič
revize
29644d6397

+ 1 - 1
docs/api.rst

@@ -10,7 +10,7 @@ The Lakesuperior API modules of most interest for a client are:
 - :mod:`lakesupeiror.api.query`
 - :mod:`lakesuperior.api.admin`
 
-:mod:`lakesuperior.model.ldpr` is used to manipulate resources.
+:mod:`lakesuperior.model.ldp.ldpr` is used to manipulate resources.
 
 The full API docs are listed below.
 

+ 4 - 4
docs/apidoc/lakesuperior.model.rst

@@ -7,7 +7,7 @@ Submodules
 lakesuperior\.model\.ldp\_factory module
 ----------------------------------------
 
-.. automodule:: lakesuperior.model.ldp_factory
+.. automodule:: lakesuperior.model.ldp.ldp_factory
     :members:
     :undoc-members:
     :show-inheritance:
@@ -15,7 +15,7 @@ lakesuperior\.model\.ldp\_factory module
 lakesuperior\.model\.ldp\_nr module
 -----------------------------------
 
-.. automodule:: lakesuperior.model.ldp_nr
+.. automodule:: lakesuperior.model.ldp.ldp_nr
     :members:
     :undoc-members:
     :show-inheritance:
@@ -23,7 +23,7 @@ lakesuperior\.model\.ldp\_nr module
 lakesuperior\.model\.ldp\_rs module
 -----------------------------------
 
-.. automodule:: lakesuperior.model.ldp_rs
+.. automodule:: lakesuperior.model.ldp.ldp_rs
     :members:
     :undoc-members:
     :show-inheritance:
@@ -31,7 +31,7 @@ lakesuperior\.model\.ldp\_rs module
 lakesuperior\.model\.ldpr module
 --------------------------------
 
-.. automodule:: lakesuperior.model.ldpr
+.. automodule:: lakesuperior.model.ldp.ldpr
     :members:
     :undoc-members:
     :show-inheritance:

+ 1 - 1
lakesuperior/api/admin.py

@@ -77,7 +77,7 @@ def fixity_check(uid):
         resource is not an LDP-NR.
     """
     from lakesuperior.api import resource as rsrc_api
-    from lakesuperior.model.ldp_factory import LDP_NR_TYPE
+    from lakesuperior.model.ldp.ldp_factory import LDP_NR_TYPE
 
     rsrc = rsrc_api.get(uid)
     if LDP_NR_TYPE not in rsrc.ldp_types:

+ 8 - 8
lakesuperior/api/resource.py

@@ -15,8 +15,8 @@ from lakesuperior.exceptions import (
         InvalidResourceError, ResourceNotExistsError, TombstoneError)
 from lakesuperior import env, thread_env
 from lakesuperior.globals import RES_DELETED, RES_UPDATED
-from lakesuperior.model.ldp_factory import LDP_NR_TYPE, LdpFactory
-from lakesuperior.store.ldp_rs.graph import SimpleGraph
+from lakesuperior.model.ldp.ldp_factory import LDP_NR_TYPE, LdpFactory
+from lakesuperior.model.graph.graph import SimpleGraph
 
 
 logger = logging.getLogger(__name__)
@@ -200,13 +200,13 @@ def create(parent, slug=None, **kwargs):
     :param str parent: UID of the parent resource.
     :param str slug: Tentative path relative to the parent UID.
     :param \*\*kwargs: Other parameters are passed to the
-      :py:meth:`~lakesuperior.model.ldp_factory.LdpFactory.from_provided`
+      :py:meth:`~lakesuperior.model.ldp.ldp_factory.LdpFactory.from_provided`
       method.
 
-    :rtype: tuple(str, lakesuperior.model.ldpr.Ldpr)
+    :rtype: tuple(str, lakesuperior.model.ldp.ldpr.Ldpr)
     :return: A tuple of:
         1. Event type (str): whether the resource was created or updated.
-        2. Resource (lakesuperior.model.ldpr.Ldpr): The new or updated resource.
+        2. Resource (lakesuperior.model.ldp.ldpr.Ldpr): The new or updated resource.
     """
     uid = LdpFactory.mint_uid(parent, slug)
     logger.debug('Minted UID for new resource: {}'.format(uid))
@@ -224,13 +224,13 @@ def create_or_replace(uid, **kwargs):
 
     :param string uid: UID of the resource to be created or updated.
     :param \*\*kwargs: Other parameters are passed to the
-        :py:meth:`~lakesuperior.model.ldp_factory.LdpFactory.from_provided`
+        :py:meth:`~lakesuperior.model.ldp.ldp_factory.LdpFactory.from_provided`
         method.
 
-    :rtype: tuple(str, lakesuperior.model.ldpr.Ldpr)
+    :rtype: tuple(str, lakesuperior.model.ldp.ldpr.Ldpr)
     :return: A tuple of:
         1. Event type (str): whether the resource was created or updated.
-        2. Resource (lakesuperior.model.ldpr.Ldpr): The new or updated resource.
+        2. Resource (lakesuperior.model.ldp.ldpr.Ldpr): The new or updated resource.
     """
     rsrc = LdpFactory.from_provided(uid, **kwargs)
     return rsrc.create_or_replace(), rsrc

+ 5 - 5
lakesuperior/endpoints/ldp.py

@@ -25,10 +25,10 @@ from lakesuperior.exceptions import (
         ServerManagedTermError, InvalidResourceError, SingleSubjectError,
         ResourceExistsError, IncompatibleLdpTypeError)
 from lakesuperior.globals import RES_CREATED
-from lakesuperior.model.ldp_factory import LdpFactory
-from lakesuperior.model.ldp_nr import LdpNr
-from lakesuperior.model.ldp_rs import LdpRs
-from lakesuperior.model.ldpr import Ldpr
+from lakesuperior.model.ldp.ldp_factory import LdpFactory
+from lakesuperior.model.ldp.ldp_nr import LdpNr
+from lakesuperior.model.ldp.ldp_rs import LdpRs
+from lakesuperior.model.ldp.ldpr import Ldpr
 from lakesuperior.toolbox import Toolbox
 
 
@@ -668,7 +668,7 @@ def _headers_from_metadata(rsrc, out_fmt='text/turtle'):
     """
     Create a dict of headers from a metadata graph.
 
-    :param lakesuperior.model.ldpr.Ldpr rsrc: Resource to extract metadata
+    :param lakesuperior.model.ldp.ldpr.Ldpr rsrc: Resource to extract metadata
         from.
     """
     rsp_headers = defaultdict(list)

+ 3 - 10
lakesuperior/model/graph/graph.pyx

@@ -186,7 +186,7 @@ cdef class SimpleGraph:
     """
 
     def __cinit__(
-            self, Keyset keyset=None, store=None, set data=set()):
+            self, Keyset keyset=None, store=None, set data=set(), **kwargs):
         """
         Initialize the graph with pre-existing data or by looking up a store.
 
@@ -231,11 +231,6 @@ cdef class SimpleGraph:
         self.store = store or env.app_globals.rdf_store
         self._pool = Pool()
 
-        cdef:
-            size_t i = 0
-            TripleKey spok
-            term.Buffer pk_t
-
         # Initialize empty data set.
         if keyset:
             # Populate with triples extracted from provided key set.
@@ -676,7 +671,7 @@ cdef class Imr(SimpleGraph):
     Some set operations that produce a new object (``-``, ``|``, ``&``, ``^``)
     will create a new ``Imr`` instance with the same subject URI.
     """
-    def __init__(self, str uri, *args, **kwargs):
+    def __init__(self, uri, *args, **kwargs):
         """
         Initialize the graph with pre-existing data or by looking up a store.
 
@@ -692,9 +687,7 @@ cdef class Imr(SimpleGraph):
             Any and all elements may be ``None``.
         :param lmdbStore store: the store to look data up.
         """
-        super().__init__(*args, **kwargs)
-
-        self.uri = uri
+        self.uri = str(uri)
 
 
     @property

+ 4 - 4
lakesuperior/model/ldp/ldp_factory.py

@@ -8,15 +8,15 @@ from rdflib.resource import Resource
 from rdflib.namespace import RDF
 
 from lakesuperior import env
-from lakesuperior.model.ldpr import Ldpr
-from lakesuperior.model.ldp_nr import LdpNr
-from lakesuperior.model.ldp_rs import LdpRs, Ldpc, LdpDc, LdpIc
+from lakesuperior.model.ldp.ldpr import Ldpr
+from lakesuperior.model.ldp.ldp_nr import LdpNr
+from lakesuperior.model.ldp.ldp_rs import LdpRs, Ldpc, LdpDc, LdpIc
 from lakesuperior.config_parser import config
 from lakesuperior.dictionaries.namespaces import ns_collection as nsc
 from lakesuperior.exceptions import (
         IncompatibleLdpTypeError, InvalidResourceError, ResourceExistsError,
         ResourceNotExistsError, TombstoneError)
-from lakesuperior.store.ldp_rs.graph import Imr
+from lakesuperior.model.graph.graph import Imr
 
 
 LDP_NR_TYPE = nsc['ldp'].NonRDFSource

+ 2 - 2
lakesuperior/model/ldp/ldp_nr.py

@@ -8,8 +8,8 @@ from rdflib.term import URIRef, Literal, Variable
 
 from lakesuperior import env
 from lakesuperior.dictionaries.namespaces import ns_collection as nsc
-from lakesuperior.model.ldpr import Ldpr
-from lakesuperior.model.ldp_rs import LdpRs
+from lakesuperior.model.ldp.ldpr import Ldpr
+from lakesuperior.model.ldp.ldp_rs import LdpRs
 
 
 nonrdfly = env.app_globals.nonrdfly

+ 1 - 1
lakesuperior/model/ldp/ldp_rs.py

@@ -5,7 +5,7 @@ from rdflib import Graph
 from lakesuperior import env
 from lakesuperior.globals import RES_UPDATED
 from lakesuperior.dictionaries.namespaces import ns_collection as nsc
-from lakesuperior.model.ldpr import Ldpr
+from lakesuperior.model.ldp.ldpr import Ldpr
 
 
 logger = logging.getLogger(__name__)

+ 6 - 6
lakesuperior/model/ldp/ldpr.py

@@ -26,7 +26,7 @@ from lakesuperior.dictionaries.srv_mgd_terms import (
 from lakesuperior.exceptions import (
     InvalidResourceError, RefIntViolationError, ResourceNotExistsError,
     ServerManagedTermError, TombstoneError)
-from lakesuperior.store.ldp_rs.graph import SimpleGraph, Imr
+from lakesuperior.model.graph.graph import SimpleGraph, Imr
 from lakesuperior.store.ldp_rs.rsrc_centric_layout import VERS_CONT_LABEL
 from lakesuperior.toolbox import Toolbox
 
@@ -47,7 +47,7 @@ class Ldpr(metaclass=ABCMeta):
     **Note**: Even though LdpNr (which is a subclass of Ldpr) handles binary
     files, it still has an RDF representation in the triplestore. Hence, some
     of the RDF-related methods are defined in this class rather than in
-    :class:`~lakesuperior.model.ldp_rs.LdpRs`.
+    :class:`~lakesuperior.model.ldp.ldp_rs.LdpRs`.
 
     **Note:** Only internal facing (``info:fcres``-prefixed) URIs are handled
     in this class. Public-facing URI conversion is handled in the
@@ -462,7 +462,7 @@ class Ldpr(metaclass=ABCMeta):
             }
 
         # Bury descendants.
-        from lakesuperior.model.ldp_factory import LdpFactory
+        from lakesuperior.model.ldp.ldp_factory import LdpFactory
         for desc_uri in rdfly.get_descendants(self.uid):
             try:
                 desc_rsrc = LdpFactory.from_stored(
@@ -513,7 +513,7 @@ class Ldpr(metaclass=ABCMeta):
         self.modify(RES_CREATED, remove_trp, add_trp)
 
         # Resurrect descendants.
-        from lakesuperior.model.ldp_factory import LdpFactory
+        from lakesuperior.model.ldp.ldp_factory import LdpFactory
         descendants = env.app_globals.rdfly.get_descendants(self.uid)
         for desc_uri in descendants:
             LdpFactory.from_stored(
@@ -856,7 +856,7 @@ class Ldpr(metaclass=ABCMeta):
         a LDP-NR has "children" under ``fcr:versions``) by setting this to
         True.
         """
-        from lakesuperior.model.ldp_factory import LdpFactory
+        from lakesuperior.model.ldp.ldp_factory import LdpFactory
 
         if '/' in self.uid.lstrip('/'):
             # Traverse up the hierarchy to find the parent.
@@ -908,7 +908,7 @@ class Ldpr(metaclass=ABCMeta):
         add_trp = {(self.uri, nsc['fcrepo'].hasParent, cont_rsrc.uri)}
 
         if self.MBR_RSRC_URI in cont_p and self.MBR_REL_URI in cont_p:
-            from lakesuperior.model.ldp_factory import LdpFactory
+            from lakesuperior.model.ldp.ldp_factory import LdpFactory
 
             s = cont_rsrc.metadata.value(self.MBR_RSRC_URI)
             p = cont_rsrc.metadata.value(self.MBR_REL_URI)

+ 2 - 2
tests/1_api/test_resource_api.py

@@ -13,8 +13,8 @@ from lakesuperior.exceptions import (
         IncompatibleLdpTypeError, InvalidResourceError, ResourceNotExistsError,
         TombstoneError)
 from lakesuperior.globals import RES_CREATED, RES_UPDATED
-from lakesuperior.model.ldpr import Ldpr
-from lakesuperior.store.ldp_rs.graph import SimpleGraph, Imr
+from lakesuperior.model.ldp.ldpr import Ldpr
+from lakesuperior.model.graph.graph import SimpleGraph, Imr
 
 
 @pytest.fixture(scope='module')

+ 1 - 1
tests/2_endpoints/test_ldp.py

@@ -18,7 +18,7 @@ from rdflib.term import Literal, URIRef
 
 from lakesuperior import env
 from lakesuperior.dictionaries.namespaces import ns_collection as nsc
-from lakesuperior.model.ldpr import Ldpr
+from lakesuperior.model.ldp.ldpr import Ldpr
 
 
 digest_algo = env.app_globals.config['application']['uuid']['algo']