changeset 39611:f3900f4c63d4

py3: prevent the win32 ctype _fields_ from being transformed to bytes Otherwise, any hg invocation dies with TypeError: '_fields_' must be a sequence of (name, C type) pairs # skip-blame just a r prefix
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 13 Sep 2018 00:42:25 -0400
parents 11ed2eadf937
children 053aa673947f
files mercurial/win32.py
diffstat 1 files changed, 66 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/win32.py	Thu Sep 13 17:32:20 2018 -0400
+++ b/mercurial/win32.py	Thu Sep 13 00:42:25 2018 -0400
@@ -56,20 +56,20 @@
     _LPARAM = ctypes.c_longlong
 
 class _FILETIME(ctypes.Structure):
-    _fields_ = [('dwLowDateTime', _DWORD),
-                ('dwHighDateTime', _DWORD)]
+    _fields_ = [(r'dwLowDateTime', _DWORD),
+                (r'dwHighDateTime', _DWORD)]
 
 class _BY_HANDLE_FILE_INFORMATION(ctypes.Structure):
-    _fields_ = [('dwFileAttributes', _DWORD),
-                ('ftCreationTime', _FILETIME),
-                ('ftLastAccessTime', _FILETIME),
-                ('ftLastWriteTime', _FILETIME),
-                ('dwVolumeSerialNumber', _DWORD),
-                ('nFileSizeHigh', _DWORD),
-                ('nFileSizeLow', _DWORD),
-                ('nNumberOfLinks', _DWORD),
-                ('nFileIndexHigh', _DWORD),
-                ('nFileIndexLow', _DWORD)]
+    _fields_ = [(r'dwFileAttributes', _DWORD),
+                (r'ftCreationTime', _FILETIME),
+                (r'ftLastAccessTime', _FILETIME),
+                (r'ftLastWriteTime', _FILETIME),
+                (r'dwVolumeSerialNumber', _DWORD),
+                (r'nFileSizeHigh', _DWORD),
+                (r'nFileSizeLow', _DWORD),
+                (r'nNumberOfLinks', _DWORD),
+                (r'nFileIndexHigh', _DWORD),
+                (r'nFileIndexLow', _DWORD)]
 
 # CreateFile
 _FILE_SHARE_READ = 0x00000001
@@ -91,50 +91,50 @@
 _STILL_ACTIVE = 259
 
 class _STARTUPINFO(ctypes.Structure):
-    _fields_ = [('cb', _DWORD),
-                ('lpReserved', _LPSTR),
-                ('lpDesktop', _LPSTR),
-                ('lpTitle', _LPSTR),
-                ('dwX', _DWORD),
-                ('dwY', _DWORD),
-                ('dwXSize', _DWORD),
-                ('dwYSize', _DWORD),
-                ('dwXCountChars', _DWORD),
-                ('dwYCountChars', _DWORD),
-                ('dwFillAttribute', _DWORD),
-                ('dwFlags', _DWORD),
-                ('wShowWindow', _WORD),
-                ('cbReserved2', _WORD),
-                ('lpReserved2', ctypes.c_char_p),
-                ('hStdInput', _HANDLE),
-                ('hStdOutput', _HANDLE),
-                ('hStdError', _HANDLE)]
+    _fields_ = [(r'cb', _DWORD),
+                (r'lpReserved', _LPSTR),
+                (r'lpDesktop', _LPSTR),
+                (r'lpTitle', _LPSTR),
+                (r'dwX', _DWORD),
+                (r'dwY', _DWORD),
+                (r'dwXSize', _DWORD),
+                (r'dwYSize', _DWORD),
+                (r'dwXCountChars', _DWORD),
+                (r'dwYCountChars', _DWORD),
+                (r'dwFillAttribute', _DWORD),
+                (r'dwFlags', _DWORD),
+                (r'wShowWindow', _WORD),
+                (r'cbReserved2', _WORD),
+                (r'lpReserved2', ctypes.c_char_p),
+                (r'hStdInput', _HANDLE),
+                (r'hStdOutput', _HANDLE),
+                (r'hStdError', _HANDLE)]
 
 class _PROCESS_INFORMATION(ctypes.Structure):
-    _fields_ = [('hProcess', _HANDLE),
-                ('hThread', _HANDLE),
-                ('dwProcessId', _DWORD),
-                ('dwThreadId', _DWORD)]
+    _fields_ = [(r'hProcess', _HANDLE),
+                (r'hThread', _HANDLE),
+                (r'dwProcessId', _DWORD),
+                (r'dwThreadId', _DWORD)]
 
 _CREATE_NO_WINDOW = 0x08000000
 _SW_HIDE = 0
 
 class _COORD(ctypes.Structure):
-    _fields_ = [('X', ctypes.c_short),
-                ('Y', ctypes.c_short)]
+    _fields_ = [(r'X', ctypes.c_short),
+                (r'Y', ctypes.c_short)]
 
 class _SMALL_RECT(ctypes.Structure):
-    _fields_ = [('Left', ctypes.c_short),
-                ('Top', ctypes.c_short),
-                ('Right', ctypes.c_short),
-                ('Bottom', ctypes.c_short)]
+    _fields_ = [(r'Left', ctypes.c_short),
+                (r'Top', ctypes.c_short),
+                (r'Right', ctypes.c_short),
+                (r'Bottom', ctypes.c_short)]
 
 class _CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
-    _fields_ = [('dwSize', _COORD),
-                ('dwCursorPosition', _COORD),
-                ('wAttributes', _WORD),
-                ('srWindow', _SMALL_RECT),
-                ('dwMaximumWindowSize', _COORD)]
+    _fields_ = [(r'dwSize', _COORD),
+                (r'dwCursorPosition', _COORD),
+                (r'wAttributes', _WORD),
+                (r'srWindow', _SMALL_RECT),
+                (r'dwMaximumWindowSize', _COORD)]
 
 _STD_OUTPUT_HANDLE = _DWORD(-11).value
 _STD_ERROR_HANDLE = _DWORD(-12).value
@@ -149,40 +149,40 @@
 # These structs are only complete enough to achieve what we need.
 class CERT_CHAIN_CONTEXT(ctypes.Structure):
     _fields_ = (
-        ("cbSize", _DWORD),
+        (r"cbSize", _DWORD),
 
         # CERT_TRUST_STATUS struct
-        ("dwErrorStatus", _DWORD),
-        ("dwInfoStatus", _DWORD),
+        (r"dwErrorStatus", _DWORD),
+        (r"dwInfoStatus", _DWORD),
 
-        ("cChain", _DWORD),
-        ("rgpChain", ctypes.c_void_p),
-        ("cLowerQualityChainContext", _DWORD),
-        ("rgpLowerQualityChainContext", ctypes.c_void_p),
-        ("fHasRevocationFreshnessTime", _BOOL),
-        ("dwRevocationFreshnessTime", _DWORD),
+        (r"cChain", _DWORD),
+        (r"rgpChain", ctypes.c_void_p),
+        (r"cLowerQualityChainContext", _DWORD),
+        (r"rgpLowerQualityChainContext", ctypes.c_void_p),
+        (r"fHasRevocationFreshnessTime", _BOOL),
+        (r"dwRevocationFreshnessTime", _DWORD),
     )
 
 class CERT_USAGE_MATCH(ctypes.Structure):
     _fields_ = (
-        ("dwType", _DWORD),
+        (r"dwType", _DWORD),
 
          # CERT_ENHKEY_USAGE struct
-        ("cUsageIdentifier", _DWORD),
-        ("rgpszUsageIdentifier", ctypes.c_void_p), # LPSTR *
+        (r"cUsageIdentifier", _DWORD),
+        (r"rgpszUsageIdentifier", ctypes.c_void_p), # LPSTR *
     )
 
 class CERT_CHAIN_PARA(ctypes.Structure):
     _fields_ = (
-        ("cbSize", _DWORD),
-        ("RequestedUsage", CERT_USAGE_MATCH),
-        ("RequestedIssuancePolicy", CERT_USAGE_MATCH),
-        ("dwUrlRetrievalTimeout", _DWORD),
-        ("fCheckRevocationFreshnessTime", _BOOL),
-        ("dwRevocationFreshnessTime", _DWORD),
-        ("pftCacheResync", ctypes.c_void_p), # LPFILETIME
-        ("pStrongSignPara", ctypes.c_void_p), # PCCERT_STRONG_SIGN_PARA
-        ("dwStrongSignFlags", _DWORD),
+        (r"cbSize", _DWORD),
+        (r"RequestedUsage", CERT_USAGE_MATCH),
+        (r"RequestedIssuancePolicy", CERT_USAGE_MATCH),
+        (r"dwUrlRetrievalTimeout", _DWORD),
+        (r"fCheckRevocationFreshnessTime", _BOOL),
+        (r"dwRevocationFreshnessTime", _DWORD),
+        (r"pftCacheResync", ctypes.c_void_p), # LPFILETIME
+        (r"pStrongSignPara", ctypes.c_void_p), # PCCERT_STRONG_SIGN_PARA
+        (r"dwStrongSignFlags", _DWORD),
     )
 
 # types of parameters of C functions used (required by pypy)