[Fix build on systems with Python 3 1/3] qmi-codegen python3: change string.replace() class method use to str.replace() instance method

Shawn J. Goff shawn7400 at gmail.com
Mon Dec 17 13:29:15 PST 2012


From: "Shawn J. Goff" <shawn.goff at accelecon.com>

Python 3 doesn't support the replace class method; it's now an instance method only.
string.replace(object, old, new) changes to object.replace(old, new)

sed:
s/string\.replace(\([^,]*\), /\1.replace(/
---
 build-aux/qmi-codegen/Client.py        |  2 +-
 build-aux/qmi-codegen/VariableArray.py |  2 +-
 build-aux/qmi-codegen/utils.py         | 11 +++++------
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/build-aux/qmi-codegen/Client.py b/build-aux/qmi-codegen/Client.py
index 12d4cd6..071c91b 100644
--- a/build-aux/qmi-codegen/Client.py
+++ b/build-aux/qmi-codegen/Client.py
@@ -208,7 +208,7 @@ class Client:
                     translations['output_camelcase'] = utils.build_camelcase_name(message.output.fullname)
                     translations['bundle_type'] = 'QMI_TYPE_' + utils.remove_prefix(utils.build_underscore_uppercase_name(message.output.fullname), 'QMI_')
                     translations['service'] = self.service.upper()
-                    translations['message_name_dashed'] = string.replace(message.name, ' ', '-')
+                    translations['message_name_dashed'] = message.name.replace(' ', '-')
                     inner_template += (
                         '\n'
                         '    /**\n'
diff --git a/build-aux/qmi-codegen/VariableArray.py b/build-aux/qmi-codegen/VariableArray.py
index f2b122c..c5aadf9 100644
--- a/build-aux/qmi-codegen/VariableArray.py
+++ b/build-aux/qmi-codegen/VariableArray.py
@@ -86,7 +86,7 @@ class VariableArray(Variable):
     def clear_func_name(self):
         # element public format might be a base type like 'gchar *' rather
         # than a structure name like QmiFooBar
-        elt_name = string.replace(self.array_element.public_format, '*', 'pointer')
+        elt_name = self.array_element.public_format.replace('*', 'pointer')
         return utils.build_underscore_name(self.name) + \
              '_' + \
              utils.build_underscore_name_from_camelcase(utils.build_camelcase_name(elt_name))
diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py
index 5095155..e9d4ea1 100644
--- a/build-aux/qmi-codegen/utils.py
+++ b/build-aux/qmi-codegen/utils.py
@@ -54,8 +54,7 @@ def add_copyright(f):
 Build a header guard string based on the given filename
 """
 def build_header_guard(output_name):
-    return "__LIBQMI_GLIB_" + string.replace(output_name, '-', '_').upper() + "__"
-
+    return "__LIBQMI_GLIB_" + output_name.replace('-', '_').upper() + "__"
 
 """
 Write the common header start chunk
@@ -145,7 +144,7 @@ Build an underscore name from the given full name
 e.g.: "This is a message" --> "this_is_a_message"
 """
 def build_underscore_name(name):
-    return string.replace(name, ' ', '_').lower()
+    return name.replace(' ', '_').lower()
 
 
 """
@@ -153,7 +152,7 @@ Build an underscore uppercase name from the given full name
 e.g.: "This is a message" --> "THIS_IS_A_MESSAGE"
 """
 def build_underscore_uppercase_name(name):
-    return string.replace(name, ' ', '_').upper()
+    return name.replace(' ', '_').upper()
 
 
 """
@@ -170,7 +169,7 @@ Build a camelcase name from the given full name
 e.g.: "This is a message" --> "ThisIsAMessage"
 """
 def build_camelcase_name(name):
-    return string.replace(string.capwords(name), ' ', '')
+    return string.capwords(name).replace(' ', '')
 
 
 """
@@ -178,7 +177,7 @@ Build a dashed lowercase name from the given full name
 e.g.: "This is a message" --> "this-is-a-message"
 """
 def build_dashed_name(name):
-    return string.replace(name.lower(), ' ', '-')
+    return name.lower().replace(' ', '-')
 
 
 """
-- 
1.8.0.2



More information about the libqmi-devel mailing list