]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: extract flatten_dict() out
authorKefu Chai <kchai@redhat.com>
Sat, 23 Feb 2019 14:19:11 +0000 (22:19 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 23 Feb 2019 14:47:03 +0000 (22:47 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/rados/rados.pyx

index 052c491517df838e010923d9094ee6859b21c615..3751e8332e7aab0886460a0b4403a42175654e6e 100644 (file)
@@ -556,6 +556,11 @@ def decode_cstr(val, encoding="utf-8"):
     return val.decode(encoding)
 
 
+def flatten_dict(d):
+    items = chain.from_iterable(d.items())
+    return ''.join(i + '\0' for i in items)
+
+
 cdef char* opt_str(s) except? NULL:
     if s is None:
         return NULL
@@ -1513,8 +1518,7 @@ Rados object in state %s." % self.state)
         """
         service = cstr(service, 'service')
         daemon = cstr(daemon, 'daemon')
-        metadata_dict = '\0'.join(chain.from_iterable(metadata.items()))
-        metadata_dict += '\0'
+        metadata_dict = flatten_dict(metadata)
         cdef:
             char *_service = service
             char *_daemon = daemon
@@ -1527,8 +1531,7 @@ Rados object in state %s." % self.state)
 
     @requires(('metadata', dict))
     def service_daemon_update(self, status):
-        status_dict = '\0'.join(chain.from_iterable(status.items()))
-        status_dict += '\0'
+        status_dict = flatten_dict(status)
         cdef:
             char *_status = status_dict