浏览代码

Use dict.get instead of setdefault where appropriate.

Stefano Cossu 7 年之前
父节点
当前提交
21a9708d96

+ 3 - 3
lakesuperior/endpoints/ldp.py

@@ -190,8 +190,8 @@ def post_resource(parent):
 
 @ldp.route('/<path:uuid>/fcr:versions', methods=['POST'])
 def post_version(uuid):
-    slug = request.headers.setdefault('slug', None)
-    if not slug:
+    label = request.headers.get('slug', None)
+    if not label:
         return 'Specify label for version.', 400
 
     parent_uuid = uuid + '/fcr:versions'
@@ -469,7 +469,7 @@ def parse_repr_options(retr_opts):
     logger.debug('Parsing retrieval options: {}'.format(retr_opts))
     imr_options = {}
 
-    if retr_opts.setdefault('value') == 'minimal':
+    if retr_opts.get('value') == 'minimal':
         imr_options = {
             'embed_children' : False,
             'incl_children' : False,

+ 2 - 2
lakesuperior/messaging/formatters.py

@@ -81,7 +81,7 @@ class ASResourceFormatter(BaseASFormatter):
                 'updated' : self.time,
                 'type' : self.type,
             },
-            'actor' : self.metadata.setdefault('actor', None),
+            'actor' : self.metadata.get('actor', None),
         }
 
         return json.dumps(ret)
@@ -108,7 +108,7 @@ class ASDeltaFormatter(BaseASFormatter):
                 'updated' : self.time,
                 'type' : self.type,
             },
-            'actor' : self.metadata.setdefault('actor', None),
+            'actor' : self.metadata.get('actor', None),
             'data' : self.data,
         }
 

+ 1 - 1
lakesuperior/model/ldpr.py

@@ -370,7 +370,7 @@ class Ldpr(metaclass=ABCMeta):
         # Remove digest hash.
         self.imr.remove(nsc['premis'].hasMessageDigest)
 
-        if not self._imr_options.setdefault('incl_srv_mgd', True):
+        if not self._imr_options.get('incl_srv_mgd', True):
             for p in srv_mgd_predicates:
                 self._logger.debug('Removing predicate: {}'.format(p))
                 self.imr.remove(p)

+ 1 - 1
lakesuperior/store_layouts/ldp_rs/simple_layout.py

@@ -124,5 +124,5 @@ class SimpleLayout(BaseRdfLayout):
         for t in add_trp:
             self.ds.add(t)
 
-        if current_app.config.setdefault('messaging') and metadata:
+        if current_app.config.get('messaging') and metadata:
             request.changelog.append((set(remove_trp), set(add_trp), metadata))