]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: Import cstr from the rados module
authorDavid Coles <dcoles@gaikai.com>
Tue, 20 Oct 2015 17:55:44 +0000 (10:55 -0700)
committerDavid Coles <dcoles@gaikai.com>
Fri, 13 Nov 2015 01:26:25 +0000 (17:26 -0800)
Since rados is required for rbd, we can avoid duplication of code across these
two modules.

Signed-off-by: David Coles <dcoles@gaikai.com>
src/pybind/rbd.py

index c15a943be769d31783f68c24e89293b1f0433468..b0bf552ebf462c7fd6698d801f0eed5932fa1ca9 100644 (file)
@@ -20,6 +20,8 @@ import ctypes
 import errno
 import sys
 
+from rados import cstr
+
 ANONYMOUS_AUID = 0xffffffffffffffff
 ADMIN_AUID = 0
 
@@ -202,23 +204,6 @@ def load_librbd():
         raise EnvironmentError("Unable to load librbd: %s" % e)
 
 
-def cstr(val, encoding="utf-8"):
-    """
-    Create a C-style string from a Python string
-
-    :param str val: Python string
-    :rtype: c_char_p
-    """
-    if val is None:
-        return c_char_p(None)
-
-    if _python2 and isinstance(val, str):
-        # Don't encode str on Python 2, as it's already an 8-bit string
-        return c_char_p(val)
-    else:
-        return c_char_p(val.encode(encoding))
-
-
 class RBD(object):
     """
     This class wraps librbd CRUD functions.