]> git.apps.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>
Wed, 5 May 2021 06:32:24 +0000 (14:32 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 31ea5a7e930978151265678aedf4e37ae9e97776)

src/pybind/rados/rados.pyx

index c8e20b7c8e0fb40f5c32f8a55406b7e51dacf941..dbd150540b67d6f58df4694d983ba9d96bcd3ecc 100644 (file)
@@ -557,6 +557,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
@@ -1537,8 +1542,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
@@ -1551,8 +1555,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