[PATCH pyphosphor 3/5] Remove name mangling from find_dbus_interfaces

OpenBMC Patches openbmc-patches at stwcx.xyz
Wed Jun 29 07:10:44 AEST 2016


From: Brad Bishop <bradleyb at fuzziesquirrel.com>

Double underscore in Python mangles names and sometimes is
used as a way to make things private; however, in general
this isn't considered best practice and there isn't a compelling
reason for it here.

Rather, the convention for denoting a private interface is
to use a single leading underscore.

For more information:
http://www.artima.com/weblogs/viewpost.jsp?thread=211430

Signed-off-by: Brad Bishop <bradleyb at fuzziesquirrel.com>
---
 obmc/dbuslib/introspection.py | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/obmc/dbuslib/introspection.py b/obmc/dbuslib/introspection.py
index 26f0555..ec252c6 100644
--- a/obmc/dbuslib/introspection.py
+++ b/obmc/dbuslib/introspection.py
@@ -137,53 +137,53 @@ class IntrospectionParser:
 
 
 def find_dbus_interfaces(conn, service, path, match):
-    class __FindInterfaces(object):
+    class _FindInterfaces(object):
         def __init__(self):
             self.results = {}
 
         @staticmethod
-        def __introspect(service, path):
+        def _introspect(service, path):
             obj = conn.get_object(service, path, introspect=False)
             iface = dbus.Interface(obj, dbus.INTROSPECTABLE_IFACE)
             return iface.Introspect()
 
         @staticmethod
-        def __get_managed_objects(service, om):
+        def _get_managed_objects(service, om):
             obj = conn.get_object(service, om, introspect=False)
             iface = dbus.Interface(
                 obj, dbus.BUS_DAEMON_IFACE + '.ObjectManager')
             return iface.GetManagedObjects()
 
         @staticmethod
-        def __to_path(elements):
+        def _to_path(elements):
             return '/' + '/'.join(elements)
 
         @staticmethod
-        def __to_path_elements(path):
+        def _to_path_elements(path):
             return filter(bool, path.split('/'))
 
         def __call__(self, service, path):
             self.results = {}
-            self.__find_interfaces(service, path)
+            self._find_interfaces(service, path)
             return self.results
 
         @staticmethod
-        def __match(iface):
+        def _match(iface):
             return iface == dbus.BUS_DAEMON_IFACE + '.ObjectManager' \
                 or match(iface)
 
-        def __find_interfaces(self, service, path):
-            path_elements = self.__to_path_elements(path)
-            path = self.__to_path(path_elements)
-            root = ET.fromstring(self.__introspect(service, path))
+        def _find_interfaces(self, service, path):
+            path_elements = self._to_path_elements(path)
+            path = self._to_path(path_elements)
+            root = ET.fromstring(self._introspect(service, path))
 
             ifaces = filter(
-                self.__match,
+                self._match,
                 [x.attrib.get('name') for x in root.findall('interface')])
             self.results[path] = ifaces
 
             if dbus.BUS_DAEMON_IFACE + '.ObjectManager' in ifaces:
-                objs = self.__get_managed_objects(service, path)
+                objs = self._get_managed_objects(service, path)
                 for k, v in objs.iteritems():
                     self.results[k] = v
             else:
@@ -191,11 +191,11 @@ def find_dbus_interfaces(conn, service, path, match):
                     bool,
                     [x.attrib.get('name') for x in root.findall('node')])
                 children = [
-                    self.__to_path(
-                        path_elements + self.__to_path_elements(x))
+                    self._to_path(
+                        path_elements + self._to_path_elements(x))
                     for x in sorted(children)]
                 for child in children:
                     if child not in self.results:
-                        self.__find_interfaces(service, child)
+                        self._find_interfaces(service, child)
 
-    return __FindInterfaces()(service, path)
+    return _FindInterfaces()(service, path)
-- 
2.9.0




More information about the openbmc mailing list