[pywin32-checkins] /hgroot/pywin32/pywin32: Validate syntax for constants created u...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-08 15:58:48
|
changeset 9c79bdb51505 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=9c79bdb51505 summary: Validate syntax for constants created using repr diffstat: com/win32com/client/genpy.py | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diffs (20 lines): diff -r 702451ba44f2 -r 9c79bdb51505 com/win32com/client/genpy.py --- a/com/win32com/client/genpy.py Tue Aug 07 04:32:52 2012 -0400 +++ b/com/win32com/client/genpy.py Wed Aug 08 11:58:06 2012 -0400 @@ -214,6 +214,16 @@ use = hex(val) else: use = repr(val) + # Make sure the repr of the value is valid python syntax + # still could cause an error on import if it contains a module or type name + # not available in the global namespace + try: + compile(use, '<makepy>', 'eval') + except SyntaxError: + # At least add the repr as a string, so it can be investigated further + # Sanitize it, in case the repr contains its own quotes. (??? line breaks too ???) + use = use.replace('"',"'") + use = '"' + use + '"' + ' # This VARIANT type cannot be converted automatically' print >> stream, "\t%-30s=%-10s # from enum %s" % \ (build.MakePublicAttributeName(name, True), use, enumName) num += 1 |