diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:49:31 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:49:34 +0900 |
commit | 51369246466a689b3cc9798d22a73fb7fa86871f (patch) | |
tree | d9e45d9bd8e2d7e480ae3420eeca50775003c80c /gi/pygi-info.c | |
parent | 5f38b080de58de48d88b88ef55849ae296901613 (diff) | |
download | pygobject2-51369246466a689b3cc9798d22a73fb7fa86871f.tar.gz pygobject2-51369246466a689b3cc9798d22a73fb7fa86871f.tar.bz2 pygobject2-51369246466a689b3cc9798d22a73fb7fa86871f.zip |
Imported Upstream version 3.8.2
Change-Id: Ied3493b571ffbcc68a9078d5806b02d9511409e6
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi/pygi-info.c')
-rw-r--r-- | gi/pygi-info.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/gi/pygi-info.c b/gi/pygi-info.c index 362e7cd..02b9350 100644 --- a/gi/pygi-info.c +++ b/gi/pygi-info.c @@ -90,8 +90,8 @@ _base_info_richcompare (PyGIBaseInfo *self, PyObject *other, int op) PYGLIB_DEFINE_TYPE("gi.BaseInfo", PyGIBaseInfo_Type, PyGIBaseInfo); -static PyObject * -_wrap_g_base_info_get_name (PyGIBaseInfo *self) +gboolean +_pygi_is_python_keyword (const gchar *name) { /* It may be better to use keyword.iskeyword(); keep in sync with * python -c 'import keyword; print(keyword.kwlist)' */ @@ -115,20 +115,32 @@ _wrap_g_base_info_get_name (PyGIBaseInfo *self) #error Need keyword list for this major Python version #endif - const gchar *name, **i; - - name = g_base_info_get_name (self->info); + const gchar **i; - /* escape keywords */ for (i = keywords; *i != NULL; ++i) { if (strcmp (name, *i) == 0) { - gchar *escaped = g_strconcat (name, "_", NULL); - PyObject *obj = PYGLIB_PyUnicode_FromString (escaped); - g_free (escaped); - return obj; + return TRUE; } } + return FALSE; +} + +static PyObject * +_wrap_g_base_info_get_name (PyGIBaseInfo *self) +{ + const gchar *name; + + name = g_base_info_get_name (self->info); + + /* escape keywords */ + if (_pygi_is_python_keyword (name)) { + gchar *escaped = g_strconcat (name, "_", NULL); + PyObject *obj = PYGLIB_PyUnicode_FromString (escaped); + g_free (escaped); + return obj; + } + return PYGLIB_PyUnicode_FromString (name); } @@ -419,11 +431,19 @@ _g_arg_get_pytype_hint (PyGIBaseInfo *self) } else { Py_DecRef(py_type); if (type_tag == GI_TYPE_TAG_INTERFACE) { + const char *info_name; + PyObject *py_string; GIBaseInfo *iface = g_type_info_get_interface(&type_info); + + info_name = g_base_info_get_name (iface); + if (info_name == NULL) { + g_base_info_unref (iface); + return PYGLIB_PyUnicode_FromString(g_type_tag_to_string(type_tag)); + } + gchar *name = g_strdup_printf("%s.%s", g_base_info_get_namespace(iface), - g_base_info_get_name (iface)); - PyObject *py_string; + info_name); g_base_info_unref(iface); py_string = PYGLIB_PyUnicode_FromString(name); g_free(name); |