[pygobject] Do not escape enum and flag names that are Python keywords



commit cb70ae0aa52ab7624b2b8c30297d8a52a7db7f44
Author: Martin Pitt <martinpitt gnome org>
Date:   Mon Jun 25 16:32:45 2012 +0200

    Do not escape enum and flag names that are Python keywords
    
    These are translated to upper case, and thus can never be keywords. This broke
    existing API such as Gtk.ShadowType.IN.

 gi/module.py     |    2 +-
 gi/pygi-info.c   |    7 +++++++
 tests/test_gi.py |    3 +++
 3 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index 8cd80ef..4e60c85 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -134,7 +134,7 @@ class IntrospectionModule(object):
                     'abcdefgjhijklmnopqrstuvwxyz',
                     'ABCDEFGJHIJKLMNOPQRSTUVWXYZ')
                 for value_info in info.get_values():
-                    value_name = value_info.get_name().translate(ascii_upper_trans)
+                    value_name = value_info.get_name_unescaped().translate(ascii_upper_trans)
                     setattr(wrapper, value_name, wrapper(value_info.get_value()))
 
             if g_type != _gobject.TYPE_NONE:
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index 4efb467..f3fedab 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -135,6 +135,12 @@ _wrap_g_base_info_get_name (PyGIBaseInfo *self)
 }
 
 static PyObject *
+_wrap_g_base_info_get_name_unescaped (PyGIBaseInfo *self)
+{
+    return PYGLIB_PyUnicode_FromString (g_base_info_get_name (self->info));
+}
+
+static PyObject *
 _wrap_g_base_info_get_namespace (PyGIBaseInfo *self)
 {
     return PYGLIB_PyUnicode_FromString (g_base_info_get_namespace (self->info));
@@ -157,6 +163,7 @@ _wrap_g_base_info_get_container (PyGIBaseInfo *self)
 
 static PyMethodDef _PyGIBaseInfo_methods[] = {
     { "get_name", (PyCFunction) _wrap_g_base_info_get_name, METH_NOARGS },
+    { "get_name_unescaped", (PyCFunction) _wrap_g_base_info_get_name_unescaped, METH_NOARGS },
     { "get_namespace", (PyCFunction) _wrap_g_base_info_get_namespace, METH_NOARGS },
     { "get_container", (PyCFunction) _wrap_g_base_info_get_container, METH_NOARGS },
     { NULL, NULL, 0 }
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 6aa7445..ce988c0 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2229,3 +2229,6 @@ class TestKeywords(unittest.TestCase):
         # we cannot currently instantiate GLib.Timer objects, so just ensure
         # the method exists
         self.assertTrue(callable(GLib.Timer.continue_))
+
+    def test_uppercase(self):
+        self.assertEqual(GLib.IOCondition.IN.value_nicks, ['in'])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]