Blob Blame History Raw
From 24116cfe98d40c51cbbf24059460b9910064c93e Mon Sep 17 00:00:00 2001
From: David Shea <dshea@redhat.com>
Date: Fri, 28 Feb 2014 12:00:52 -0800
Subject: [PATCH] Ignore illegal symbols in gobject introspection

See upstream bug:

https://bitbucket.org/logilab/astroid/issue/19/syntaxerror-when-examining-gi-modules

gobject introspection can result in symbols that are not valid in
python. Ignore them.
---
 brain/py2gi.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/brain/py2gi.py b/brain/py2gi.py
index 5001b7c..b001625 100644
--- a/brain/py2gi.py
+++ b/brain/py2gi.py
@@ -5,6 +5,7 @@ Helps with understanding everything imported from 'gi.repository'
 
 import inspect
 import sys
+import re
 
 from astroid import MANAGER, AstroidBuildingException
 from astroid.builder import AstroidBuilder
@@ -12,6 +13,7 @@ from astroid.builder import AstroidBuilder
 
 _inspected_modules = {}
 
+_identifier_re = r'^[A-Za-z_]\w*$'
 
 def _gi_build_stub(parent):
     """
@@ -26,6 +28,11 @@ def _gi_build_stub(parent):
         if not name or name.startswith("__"):
             # GLib.IConv has a parameter named "" :/
             continue
+
+        # Check if this is a valid name in python
+        if not re.match(_identifier_re, name):
+            continue
+
         try:
             obj = getattr(parent, name)
         except:
-- 
1.8.5.3