mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix translation of pywintypes.error on py3
This commit is contained in:
parent
11fa71adf6
commit
4a7d673585
@ -14,6 +14,7 @@ from calibre.constants import (
|
|||||||
__appname__, fcntl, filesystem_encoding, islinux, isosx, iswindows, plugins
|
__appname__, fcntl, filesystem_encoding, islinux, isosx, iswindows, plugins
|
||||||
)
|
)
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
|
from calibre.utils.shared_file import raise_winerror
|
||||||
|
|
||||||
speedup = plugins['speedup'][0]
|
speedup = plugins['speedup'][0]
|
||||||
if iswindows:
|
if iswindows:
|
||||||
@ -61,7 +62,7 @@ def windows_open(path):
|
|||||||
None, # No template file
|
None, # No template file
|
||||||
)
|
)
|
||||||
except pywintypes.error as err:
|
except pywintypes.error as err:
|
||||||
raise WindowsError(err[0], err[2], path)
|
raise_winerror(err)
|
||||||
fd = msvcrt.open_osfhandle(h.Detach(), 0)
|
fd = msvcrt.open_osfhandle(h.Detach(), 0)
|
||||||
return os.fdopen(fd, 'r+b')
|
return os.fdopen(fd, 'r+b')
|
||||||
|
|
||||||
|
@ -70,12 +70,14 @@ if iswindows:
|
|||||||
os.O_CREAT | os.O_TRUNC : CREATE_ALWAYS
|
os.O_CREAT | os.O_TRUNC : CREATE_ALWAYS
|
||||||
}
|
}
|
||||||
|
|
||||||
def raise_winerror(pywinerr):
|
def raise_winerror(pywinerr, path=None):
|
||||||
reraise(
|
reraise(
|
||||||
WindowsError,
|
WindowsError, WindowsError(
|
||||||
WindowsError(pywinerr.winerror,
|
pywinerr.winerror,
|
||||||
(pywinerr.funcname or '') + ': ' + (pywinerr.strerror or '')),
|
(pywinerr.funcname or '') + ': ' + (pywinerr.strerror or ''), path
|
||||||
sys.exc_info()[2])
|
),
|
||||||
|
sys.exc_info()[2]
|
||||||
|
)
|
||||||
|
|
||||||
def os_open(path, flags, mode=0o777, share_flags=FILE_SHARE_VALID_FLAGS):
|
def os_open(path, flags, mode=0o777, share_flags=FILE_SHARE_VALID_FLAGS):
|
||||||
'''
|
'''
|
||||||
@ -114,7 +116,7 @@ if iswindows:
|
|||||||
h = win32file.CreateFileW(
|
h = win32file.CreateFileW(
|
||||||
path, access_flags, share_flags, None, create_flags, attrib_flags, None)
|
path, access_flags, share_flags, None, create_flags, attrib_flags, None)
|
||||||
except pywintypes.error as e:
|
except pywintypes.error as e:
|
||||||
raise_winerror(e)
|
raise_winerror(e, path)
|
||||||
ans = msvcrt.open_osfhandle(h.Detach(), flags | os.O_NOINHERIT)
|
ans = msvcrt.open_osfhandle(h.Detach(), flags | os.O_NOINHERIT)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
@ -191,6 +191,10 @@ def find_tests():
|
|||||||
return unittest.defaultTestLoader.loadTestsFromTestCase(IPCLockTest)
|
return unittest.defaultTestLoader.loadTestsFromTestCase(IPCLockTest)
|
||||||
|
|
||||||
|
|
||||||
|
def run_tests():
|
||||||
|
from calibre.utils.run_tests import run_tests
|
||||||
|
run_tests(find_tests)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
suite = find_tests()
|
run_tests()
|
||||||
unittest.TextTestRunner(verbosity=4).run(suite)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user