Kaynağa Gözat

Merge pull request #113 from scossu/static_forget

Make `LdpRs.forget()` a static method.
Stefano Cossu 4 yıl önce
ebeveyn
işleme
a904a8caf7

+ 4 - 3
lakesuperior/api/resource.py

@@ -17,6 +17,7 @@ from lakesuperior.exceptions import (
 from lakesuperior import env, thread_env
 from lakesuperior.globals import RES_DELETED, RES_UPDATED
 from lakesuperior.model.ldp.ldp_factory import LDP_NR_TYPE, LdpFactory
+from lakesuperior.model.ldp.ldpr import Ldpr
 from lakesuperior.util.toolbox import rel_uri_to_urn
 
 
@@ -325,13 +326,13 @@ def delete(uid, soft=True, inbound=True):
     # to break them.
     refint = env.app_globals.rdfly.config['referential_integrity']
     inbound = True if refint else inbound
-    repr_opts = {'incl_inbound' : True} if inbound else {}
 
-    rsrc = LdpFactory.from_stored(uid, repr_opts, strict=soft)
     if soft:
+        repr_opts = {'incl_inbound' : True} if inbound else {}
+        rsrc = LdpFactory.from_stored(uid, repr_opts)
         return rsrc.bury(inbound)
     else:
-        return rsrc.forget(inbound)
+        Ldpr.forget(uid, inbound)
 
 
 @transaction(True)

+ 9 - 8
lakesuperior/model/ldp/ldpr.py

@@ -155,13 +155,13 @@ class Ldpr(metaclass=ABCMeta):
         Instantiate an in-memory LDP resource.
 
         :param str uid: uid of the resource. If None (must be explicitly
-        set) it refers to the root node. It can also be the full URI or URN,
-        in which case it will be converted.
+            set) it refers to the root node. It can also be the full URI or
+            URN, in which case it will be converted.
         :param dict repr_opts: Options used to retrieve the IMR. See
-        `parse_rfc7240` for format details.
+            `parse_rfc7240` for format details.
         :param str provided_imr: RDF data provided by the client in
-        operations such as `PUT` or `POST`, serialized as a string. This sets
-        the `provided_imr` property.
+            operations such as `PUT` or `POST`, serialized as a string. This
+            sets the `provided_imr` property.
         """
         self.uid = (
             rdfly.uri_to_uid(uid) if isinstance(uid, URIRef) else uid)
@@ -488,13 +488,14 @@ class Ldpr(metaclass=ABCMeta):
         return RES_DELETED
 
 
-    def forget(self, inbound=True):
+    @staticmethod
+    def forget(uid, inbound=True):
         """
         Remove all traces of a resource and versions.
         """
-        logger.info('Forgetting resource {}'.format(self.uid))
+        logger.info('Forgetting resource {}'.format(uid))
 
-        rdfly.forget_rsrc(self.uid, inbound)
+        rdfly.forget_rsrc(uid, inbound)
 
         return RES_DELETED
 

+ 1 - 1
lakesuperior/store/ldp_nr/default_layout.py

@@ -125,7 +125,7 @@ class DefaultLayout(BaseNonRdfLayout):
             os.unlink(tmp_fname)
             raise
         if size == 0:
-            logger.warn('Zero-length file received.')
+            logger.warning('Zero-length file received.')
 
         # If the file exists already, don't bother rewriting it.
         dst = __class__.local_path(