From bdd78ffe8a2ea9f9dfe135bc9cffc51adf3d79e0 Mon Sep 17 00:00:00 2001 From: Michael Curran Date: Wed, 12 Jun 2019 08:38:48 +1000 Subject: [PATCH 1/6] Bracket some tuples in for loops, and remove L (long-type)suffix from numbers. --- source/NVDAObjects/__init__.py | 2 +- source/hwPortUtils.py | 2 +- source/logHandler.py | 2 +- source/winKernel.py | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/NVDAObjects/__init__.py b/source/NVDAObjects/__init__.py index 729a68cd353..63fe06ed9fc 100644 --- a/source/NVDAObjects/__init__.py +++ b/source/NVDAObjects/__init__.py @@ -1098,7 +1098,7 @@ def _get_basicText(self): newTime=time.time() oldTime=getattr(self,'_basicTextTime',0) if newTime-oldTime>0.5: - self._basicText=u" ".join([x for x in self.name, self.value, self.description if isinstance(x, basestring) and len(x) > 0 and not x.isspace()]) + self._basicText=u" ".join([x for x in (self.name, self.value, self.description) if isinstance(x, basestring) and len(x) > 0 and not x.isspace()]) if len(self._basicText)==0: self._basicText=u"" else: diff --git a/source/hwPortUtils.py b/source/hwPortUtils.py index f2c5e5f1769..6c70c8097f0 100644 --- a/source/hwPortUtils.py +++ b/source/hwPortUtils.py @@ -104,7 +104,7 @@ class dummy(ctypes.Structure): CR_SUCCESS = 0 MAX_DEVICE_ID_LEN = 200 -GUID_CLASS_COMPORT = GUID(0x86e0d1e0L, 0x8089, 0x11d0, +GUID_CLASS_COMPORT = GUID(0x86e0d1e0, 0x8089, 0x11d0, (ctypes.c_ubyte*8)(0x9c, 0xe4, 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73)) GUID_DEVINTERFACE_USB_DEVICE = GUID(0xA5DCBF10, 0x6530, 0x11D2, (0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED)) diff --git a/source/logHandler.py b/source/logHandler.py index b9384f1caa0..54d473b3481 100755 --- a/source/logHandler.py +++ b/source/logHandler.py @@ -93,7 +93,7 @@ def getCodePath(f): className=cls.__name__ if className: break - return ".".join([x for x in path,className,funcName if x]) + return ".".join([x for x in (path,className,funcName) if x]) # Function to strip the base path of our code from traceback text to improve readability. BASE_PATH = os.path.split(__file__)[0] + os.sep diff --git a/source/winKernel.py b/source/winKernel.py index 5484fbe5aba..b1e4b95cb4a 100644 --- a/source/winKernel.py +++ b/source/winKernel.py @@ -38,10 +38,10 @@ DATE_LONGDATE=0x00000002 TIME_NOSECONDS=0x00000002 # Wait return types -WAIT_ABANDONED = 0x00000080L -WAIT_IO_COMPLETION = 0x000000c0L -WAIT_OBJECT_0 = 0x00000000L -WAIT_TIMEOUT = 0x00000102L +WAIT_ABANDONED = 0x00000080 +WAIT_IO_COMPLETION = 0x000000c0 +WAIT_OBJECT_0 = 0x00000000 +WAIT_TIMEOUT = 0x00000102 WAIT_FAILED = 0xffffffff # Image file machine constants IMAGE_FILE_MACHINE_UNKNOWN = 0 From 8250a95593b6a12933c58ba3e4b1abbf05433380 Mon Sep 17 00:00:00 2001 From: Reef Turner Date: Tue, 28 May 2019 17:42:30 +0200 Subject: [PATCH 2/6] Python 3: 'ur' string prefixes no longer supported. Modified 'ur' strings to be just 'r' strings prefixes --- source/characterProcessing.py | 2 +- source/config/__init__.py | 4 ++-- source/mathPres/mathPlayer.py | 4 ++-- source/virtualBuffers/__init__.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/characterProcessing.py b/source/characterProcessing.py index b10d21d2572..6a55f61dc8d 100644 --- a/source/characterProcessing.py +++ b/source/characterProcessing.py @@ -509,7 +509,7 @@ def __init__(self, locale): # Simple symbols. # These are all handled in one named group. # Because the symbols are just text, we know which symbol matched just by looking at the matched text. - patterns.append(ur"(?P{multiChars}|{singleChars})".format( + patterns.append(r"(?P{multiChars}|{singleChars})".format( multiChars="|".join(re.escape(identifier) for identifier in multiChars), singleChars=characters )) diff --git a/source/config/__init__.py b/source/config/__init__.py index d8431c20db7..a90974ffbee 100644 --- a/source/config/__init__.py +++ b/source/config/__init__.py @@ -166,7 +166,7 @@ def initConfigPath(configPath=None): if not os.path.isdir(subdir): os.makedirs(subdir) -RUN_REGKEY = ur"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" +RUN_REGKEY = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" def getStartAfterLogon(): if (easeOfAccess.isSupported and easeOfAccess.canConfigTerminateOnDesktopSwitch @@ -234,7 +234,7 @@ def execElevated(path, params=None, wait=False,handleAlreadyElevated=False): #: The name of the registry key stored under HKEY_LOCAL_MACHINE where system wide NVDA settings are stored. #: Note that NVDA is a 32-bit application, so on X64 systems, this will evaluate to "SOFTWARE\WOW6432Node\nvda" -NVDA_REGKEY = ur"SOFTWARE\NVDA" +NVDA_REGKEY = r"SOFTWARE\NVDA" def getStartOnLogonScreen(): if easeOfAccess.isSupported and easeOfAccess.willAutoStart(winreg.HKEY_LOCAL_MACHINE): diff --git a/source/mathPres/mathPlayer.py b/source/mathPres/mathPlayer.py index e21627a4dd8..7b297f0520a 100644 --- a/source/mathPres/mathPlayer.py +++ b/source/mathPres/mathPlayer.py @@ -21,9 +21,9 @@ # Break. r" ?" # Pronunciation of characters. - ur"|(?P[^<]) ?" + r"|(?P[^<]) ?" # Specific pronunciation. - ur"| (?P[^ <]+) ?" + r"| (?P[^ <]+) ?" # Prosody. r"| ?" r"|(?P) ?" diff --git a/source/virtualBuffers/__init__.py b/source/virtualBuffers/__init__.py index 195110a9eca..2e39ccb6264 100644 --- a/source/virtualBuffers/__init__.py +++ b/source/virtualBuffers/__init__.py @@ -50,8 +50,8 @@ class VBufStorage_findMatch_word(unicode): FINDBYATTRIBS_ESCAPE_TABLE = { # Symbols that are escaped in the attributes string. - ord(u":"): ur"\\:", - ord(u";"): ur"\\;", + ord(u":"): r"\\:", + ord(u";"): r"\\;", ord(u"\\"): u"\\\\\\\\", } # Symbols that must be escaped for a regular expression. From f9ddb13188a52b3aeeed4c63850c625a5e12e022 Mon Sep 17 00:00:00 2001 From: Michael Curran Date: Wed, 12 Jun 2019 09:16:16 +1000 Subject: [PATCH 3/6] More syntax fixes. --- source/appModules/soffice.py | 2 +- source/baseObject.py | 2 +- source/config/__init__.py | 2 +- source/installer.py | 2 +- source/locationHelper.py | 3 ++- source/nvda.pyw | 2 +- source/speech/__init__.py | 2 +- source/test_traceback.py | 18 ++++++++++++++++++ source/watchdog.py | 10 +++++++--- 9 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 source/test_traceback.py diff --git a/source/appModules/soffice.py b/source/appModules/soffice.py index 4aa10c775ae..478a84c2ddc 100755 --- a/source/appModules/soffice.py +++ b/source/appModules/soffice.py @@ -220,7 +220,7 @@ def _get_states(self): # #8988: Cells in Libre Office do not have the selected state when a single cell is selected (i.e. has focus). # Since #8898, the negative selected state is announced for table cells with the selectable state. states.add(controlTypes.STATE_SELECTED) - if self.IA2Attributes.get('Formula'): + if self.IA2Attributes.get('Formula'): # #860: Recent versions of Calc expose has formula state via IAccessible 2. states.add(controlTypes.STATE_HASFORMULA) return states diff --git a/source/baseObject.py b/source/baseObject.py index 3b338f73742..fd447a90b91 100755 --- a/source/baseObject.py +++ b/source/baseObject.py @@ -69,7 +69,7 @@ def __init__(self,name,bases,dict): s=dict.get('_set_%s'%x,None) d=dict.get('_del_%s'%x,None) if x in dict: - methodsString=",".join([str(i) for i in g,s,d if i]) + methodsString=",".join([str(i) for i in (g,s,d) if i]) raise TypeError("%s is already a class attribute, cannot create descriptor with methods %s"%(x,methodsString)) if not g: # There's a setter or deleter, but no getter. diff --git a/source/config/__init__.py b/source/config/__init__.py index a90974ffbee..2b74e16c28f 100644 --- a/source/config/__init__.py +++ b/source/config/__init__.py @@ -76,7 +76,7 @@ def saveOnExit(): def isInstalledCopy(): """Checks to see if this running copy of NVDA is installed on the system""" try: - k=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NVDA") + k=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NVDA") instDir=winreg.QueryValueEx(k,"UninstallDirectory")[0] except WindowsError: return False diff --git a/source/installer.py b/source/installer.py index 31741c6959c..cd53ddb85b6 100644 --- a/source/installer.py +++ b/source/installer.py @@ -74,7 +74,7 @@ def getStartMenuFolder(noDefault=False): def getInstallPath(noDefault=False): try: - k=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NVDA") + k=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NVDA") return winreg.QueryValueEx(k,"UninstallDirectory")[0] except WindowsError: return defaultInstallPath if not noDefault else None diff --git a/source/locationHelper.py b/source/locationHelper.py index 92575c50765..7f76bc61f49 100644 --- a/source/locationHelper.py +++ b/source/locationHelper.py @@ -6,7 +6,8 @@ """Classes and helper functions for working with rectangles and coordinates.""" -from collections import namedtuple, Sequence +from collections import namedtuple +from collections.abc import Sequence import windowUtils import winUser from ctypes.wintypes import RECT, POINT, DWORD diff --git a/source/nvda.pyw b/source/nvda.pyw index 6fd8b66c7f2..538bfc5ccbc 100755 --- a/source/nvda.pyw +++ b/source/nvda.pyw @@ -179,7 +179,7 @@ isSecureDesktop = desktopName == "Winlogon" if isSecureDesktop: import winreg try: - k = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, ur"SOFTWARE\NVDA") + k = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\NVDA") if not winreg.QueryValueEx(k, u"serviceDebug")[0]: globalVars.appArgs.secure = True except WindowsError: diff --git a/source/speech/__init__.py b/source/speech/__init__.py index 6493809cd68..b3162c54cc1 100755 --- a/source/speech/__init__.py +++ b/source/speech/__init__.py @@ -1736,7 +1736,7 @@ def getTableInfoSpeech(tableInfo,oldTableInfo,extraDetail=False): textList.append(_("row %s")%rowNumber) return " ".join(textList) -re_last_pause=re.compile(ur"^(.*(?<=[^\s.!?])[.!?][\"'”’)]?(?:\s+|$))(.*$)",re.DOTALL|re.UNICODE) +re_last_pause=re.compile(r"^(.*(?<=[^\s.!?])[.!?][\"'”’)]?(?:\s+|$))(.*$)",re.DOTALL|re.UNICODE) def speakWithoutPauses(speechSequence,detectBreaks=True): """ diff --git a/source/test_traceback.py b/source/test_traceback.py new file mode 100644 index 00000000000..d7e2b321a5c --- /dev/null +++ b/source/test_traceback.py @@ -0,0 +1,18 @@ +import sys + +def ding(): + raise ValueError("ding") + +def dong(): + try: + ding() + except ValueError as e: + return e + +def dang(): + e=dong() + raise e + + +dang() + diff --git a/source/watchdog.py b/source/watchdog.py index 9c80c90b19a..e39a2457111 100644 --- a/source/watchdog.py +++ b/source/watchdog.py @@ -291,7 +291,11 @@ def execute(self, func, args, kwargs, pumpMessages=True): exc = self._exc_info if exc: - raise exc[0], exc[1], exc[2] + # The execution of the function in the other thread cuased an exception. + # Re-raise it here. + # Note that in Python3, the traceback (stack) is now part of the exception, + # So the logged traceback will correctly show the stack for both this thread and the other thread. + raise e return self._result def run(self): @@ -301,8 +305,8 @@ def run(self): self._executeEvent.clear() try: self._result = self._func(*self._args, **self._kwargs) - except: - self._exc_info = sys.exc_info() + except Exception as e: + self._exc_info = e ctypes.windll.kernel32.SetEvent(self._executionDoneEvent) ctypes.windll.kernel32.CloseHandle(self._executionDoneEvent) From f34b29467fe13530d6dbef978740c164908d8562 Mon Sep 17 00:00:00 2001 From: Michael Curran Date: Wed, 12 Jun 2019 15:27:45 +1000 Subject: [PATCH 4/6] Address review comments. --- source/NVDAObjects/__init__.py | 2 +- source/baseObject.py | 2 +- source/logHandler.py | 2 +- source/test_traceback.py | 18 ------------------ source/watchdog.py | 4 ++-- 5 files changed, 5 insertions(+), 23 deletions(-) delete mode 100644 source/test_traceback.py diff --git a/source/NVDAObjects/__init__.py b/source/NVDAObjects/__init__.py index 63fe06ed9fc..e2a454380c3 100644 --- a/source/NVDAObjects/__init__.py +++ b/source/NVDAObjects/__init__.py @@ -1098,7 +1098,7 @@ def _get_basicText(self): newTime=time.time() oldTime=getattr(self,'_basicTextTime',0) if newTime-oldTime>0.5: - self._basicText=u" ".join([x for x in (self.name, self.value, self.description) if isinstance(x, basestring) and len(x) > 0 and not x.isspace()]) + self._basicText=u" ".join(x for x in (self.name, self.value, self.description) if isinstance(x, basestring) and len(x) > 0 and not x.isspace()) if len(self._basicText)==0: self._basicText=u"" else: diff --git a/source/baseObject.py b/source/baseObject.py index fd447a90b91..865ff75cd17 100755 --- a/source/baseObject.py +++ b/source/baseObject.py @@ -69,7 +69,7 @@ def __init__(self,name,bases,dict): s=dict.get('_set_%s'%x,None) d=dict.get('_del_%s'%x,None) if x in dict: - methodsString=",".join([str(i) for i in (g,s,d) if i]) + methodsString=",".join(str(i) for i in (g,s,d) if i) raise TypeError("%s is already a class attribute, cannot create descriptor with methods %s"%(x,methodsString)) if not g: # There's a setter or deleter, but no getter. diff --git a/source/logHandler.py b/source/logHandler.py index 54d473b3481..15f5e15cefe 100755 --- a/source/logHandler.py +++ b/source/logHandler.py @@ -93,7 +93,7 @@ def getCodePath(f): className=cls.__name__ if className: break - return ".".join([x for x in (path,className,funcName) if x]) + return ".".join(x for x in (path,className,funcName) if x) # Function to strip the base path of our code from traceback text to improve readability. BASE_PATH = os.path.split(__file__)[0] + os.sep diff --git a/source/test_traceback.py b/source/test_traceback.py deleted file mode 100644 index d7e2b321a5c..00000000000 --- a/source/test_traceback.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -def ding(): - raise ValueError("ding") - -def dong(): - try: - ding() - except ValueError as e: - return e - -def dang(): - e=dong() - raise e - - -dang() - diff --git a/source/watchdog.py b/source/watchdog.py index e39a2457111..b554799cf8e 100644 --- a/source/watchdog.py +++ b/source/watchdog.py @@ -291,11 +291,11 @@ def execute(self, func, args, kwargs, pumpMessages=True): exc = self._exc_info if exc: - # The execution of the function in the other thread cuased an exception. + # The execution of the function in the other thread caused an exception. # Re-raise it here. # Note that in Python3, the traceback (stack) is now part of the exception, # So the logged traceback will correctly show the stack for both this thread and the other thread. - raise e + raise exc return self._result def run(self): From 28e3c6a21241037c8c255c0ca40e607941af050f Mon Sep 17 00:00:00 2001 From: Michael Curran Date: Wed, 12 Jun 2019 15:42:07 +1000 Subject: [PATCH 5/6] setup.py: exclude win32api which stops py2exe from trying to include pywintypes37.dll. --- source/setup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/setup.py b/source/setup.py index ed11c4c88b4..37d3e4dad3e 100755 --- a/source/setup.py +++ b/source/setup.py @@ -190,7 +190,15 @@ def getRecursiveDataFiles(dest,source,excludes=()): options = {"py2exe": { "bundle_files": 3, "excludes": ["tkinter", - "serial.loopback_connection", "serial.rfc2217", "serial.serialcli", "serial.serialjava", "serial.serialposix", "serial.socket_connection"], + "serial.loopback_connection", + "serial.rfc2217", + "serial.serialcli", + "serial.serialjava", + "serial.serialposix", + "serial.socket_connection", + # Py2exe seems to implicitly include this, but we don't need it. + "win32api", + ], "packages": ["NVDAObjects","virtualBuffers","appModules","comInterfaces","brailleDisplayDrivers","synthDrivers"], "includes": [ "nvdaBuiltin", From bf4f8b1a15a05f664e0bf1d80ae4613c72f5718c Mon Sep 17 00:00:00 2001 From: Michael Curran Date: Wed, 12 Jun 2019 17:28:39 +1000 Subject: [PATCH 6/6] setup.py: exclude netbios and winxptheme pywin32 modules as they are not needed. --- source/setup.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/setup.py b/source/setup.py index 37d3e4dad3e..a1108d985eb 100755 --- a/source/setup.py +++ b/source/setup.py @@ -196,8 +196,12 @@ def getRecursiveDataFiles(dest,source,excludes=()): "serial.serialjava", "serial.serialposix", "serial.socket_connection", - # Py2exe seems to implicitly include this, but we don't need it. - "win32api", + # netbios (from pywin32) is optionally used by Python3's uuid module. + # This is not needed. + "netbios", + # winxptheme is optionally used by wx.lib.agw.aui. + # We don't need this. + "winxptheme", ], "packages": ["NVDAObjects","virtualBuffers","appModules","comInterfaces","brailleDisplayDrivers","synthDrivers"], "includes": [