[pywin32-checkins] /hgrepo/p/py/pywin32/pywin32: avoid syntax errors if 'helpstring...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2011-04-23 13:20:15
|
changeset 6859167bf2ab in /hgrepo/p/py/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgrepo/p/py/pywin32/pywin32?cmd=changeset;node=6859167bf2ab summary: avoid syntax errors if 'helpstring's had strange quoting/slashes (bug 3199631) diffstat: CHANGES.txt | 3 +++ com/TestSources/PyCOMTest/PyCOMTest.idl | 5 ++++- com/win32com/client/build.py | 13 +++++++------ com/win32com/client/genpy.py | 8 ++++---- 4 files changed, 18 insertions(+), 11 deletions(-) diffs (110 lines): diff -r 76aee4e897f0 -r 6859167bf2ab CHANGES.txt --- a/CHANGES.txt Sat Apr 23 22:51:20 2011 +1000 +++ b/CHANGES.txt Sat Apr 23 23:19:08 2011 +1000 @@ -13,6 +13,9 @@ raised) and unsigned integers now allow for values with the high-bit set to be passed correctly. +* makepy may have generated syntax errors if 'helpstring' elements in typelibs + had strange quoting or slashes (bug 3199631) + * Fixed that in some cases win32file.GetOpenFileName and GetSaveFileName could have returned trailing garbage after an embedded NULL character. (bug 3277647) diff -r 76aee4e897f0 -r 6859167bf2ab com/TestSources/PyCOMTest/PyCOMTest.idl --- a/com/TestSources/PyCOMTest/PyCOMTest.idl Sat Apr 23 22:51:20 2011 +1000 +++ b/com/TestSources/PyCOMTest/PyCOMTest.idl Sat Apr 23 23:19:08 2011 +1000 @@ -169,13 +169,16 @@ object, uuid(a0d9ceb0-5605-11d0-ae5f-cadd4c000000), dual, - helpstring("PyCOMTest Interface"), + helpstring("PyCOMTest Interface - with some fancy \tbackslash\chars\\"), pointer_default(unique) ] interface IPyCOMTest : IDispatch { import "oaidl.idl"; // Test simple alias. HCON is long. + [ + helpstring("docstring for Start - with some fancy \tslash chars\\") + ] HRESULT Start([out, retval] HCON * pnID); // Nested alaas - CONNECTID is HCON. HRESULT Stop([in] CONNECTID nID); diff -r 76aee4e897f0 -r 6859167bf2ab com/win32com/client/build.py --- a/com/win32com/client/build.py Sat Apr 23 22:51:20 2011 +1000 +++ b/com/win32com/client/build.py Sat Apr 23 23:19:08 2011 +1000 @@ -25,10 +25,11 @@ import winerror import datetime -# A string ending with a quote can not be safely triple-quoted. -def _safeQuotedString(s): - if s[-1]=='"': s = s[:-1]+'\\"' - return '"""%s"""' % s +# A string ending with a quote can not be safely triple-quoted. (Indeed, we +# consider all things suspect (eg, \n chars, \t chars etc) - so just use +# repr! +def _makeDocString(s, encoding="mbcs"): + return repr(s.encode("mbcs")) error = "PythonCOM.Client.Build error" class NotSupportedException(Exception): pass # Raised when we cant support a param type. @@ -318,7 +319,7 @@ s = linePrefix + 'def ' + name + '(self' + BuildCallList(fdesc, names, defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg) + '):' ret.append(s) if doc and doc[1]: - ret.append(linePrefix + '\t' + _safeQuotedString(doc[1])) + ret.append(linePrefix + '\t' + _makeDocString(doc[1])) # print "fdesc is ", fdesc @@ -374,7 +375,7 @@ else: linePrefix = "" ret.append(linePrefix + 'def ' + name + '(' + argPrefix + ', *args):') - if doc and doc[1]: ret.append(linePrefix + '\t' + _safeQuotedString(doc[1])) + if doc and doc[1]: ret.append(linePrefix + '\t' + _makeDocString(doc[1])) if fdesc: invoketype = fdesc[4] else: diff -r 76aee4e897f0 -r 6859167bf2ab com/win32com/client/genpy.py --- a/com/win32com/client/genpy.py Sat Apr 23 22:51:20 2011 +1000 +++ b/com/win32com/client/genpy.py Sat Apr 23 23:19:08 2011 +1000 @@ -288,7 +288,7 @@ doc = self.doc stream = generator.file print >> stream, 'class ' + self.python_name + '(DispatchBaseClass):' - if doc[1]: print >> stream, '\t' + build._safeQuotedString(doc[1]) + if doc[1]: print >> stream, '\t' + build._makeDocString(doc[1]) try: progId = pythoncom.ProgIDFromCLSID(self.clsid) print >> stream, "\t# This class is creatable by the name '%s'" % (progId) @@ -307,7 +307,7 @@ doc = self.doc stream = generator.file print >> stream, 'class ' + self.python_name + ':' - if doc[1]: print >> stream, '\t' + build._safeQuotedString(doc[1]) + if doc[1]: print >> stream, '\t' + build._makeDocString(doc[1]) try: progId = pythoncom.ProgIDFromCLSID(self.clsid) print >> stream, "\t# This class is creatable by the name '%s'" % (progId) @@ -355,7 +355,7 @@ methName = MakeEventMethodName(entry.names[0]) print >> stream, '#\tdef ' + methName + '(self' + build.BuildCallList(fdesc, entry.names, "defaultNamedOptArg", "defaultNamedNotOptArg","defaultUnnamedArg", "pythoncom.Missing", is_comment = True) + '):' if entry.doc and entry.doc[1]: - print >> stream, '#\t\t' + build._safeQuotedString(entry.doc[1]) + print >> stream, '#\t\t' + build._makeDocString(entry.doc[1]) print >> stream self.bWritten = 1 @@ -828,7 +828,7 @@ print >> self.file, "# From type library '%s'" % (os.path.split(self.sourceFilename)[1],) print >> self.file, '# On %s' % time.ctime(time.time()) - print >> self.file, '"""' + docDesc + '"""' + print >> self.file, build._makeDocString(docDesc) print >> self.file, 'makepy_version =', repr(makepy_version) print >> self.file, 'python_version = 0x%x' % (sys.hexversion,) |