Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
e4d3d769
Commit
e4d3d769
authored
Jan 21, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add win32util
parent
f4f32d67
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
+95
-0
gevent/win32util.py
gevent/win32util.py
+95
-0
No files found.
gevent/win32util.py
0 → 100644
View file @
e4d3d769
# Copyright (c) 2001-2007 Twisted Matrix Laboratories.
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""Error formatting function for Windows.
The code is taken from twisted.python.win32 module.
"""
import
os
class
_ErrorFormatter
(
object
):
"""
Formatter for Windows error messages.
@ivar winError: A callable which takes one integer error number argument
and returns an L{exceptions.WindowsError} instance for that error (like
L{ctypes.WinError}).
@ivar formatMessage: A callable which takes one integer error number
argument and returns a C{str} giving the message for that error (like
L{win32api.FormatMessage}).
@ivar errorTab: A mapping from integer error numbers to C{str} messages
which correspond to those erorrs (like L{socket.errorTab}).
"""
def
__init__
(
self
,
WinError
,
FormatMessage
,
errorTab
):
self
.
winError
=
WinError
self
.
formatMessage
=
FormatMessage
self
.
errorTab
=
errorTab
def
fromEnvironment
(
cls
):
"""
Get as many of the platform-specific error translation objects as
possible and return an instance of C{cls} created with them.
"""
try
:
from
ctypes
import
WinError
except
ImportError
:
WinError
=
None
try
:
from
win32api
import
FormatMessage
except
ImportError
:
FormatMessage
=
None
try
:
from
socket
import
errorTab
except
ImportError
:
errorTab
=
None
return
cls
(
WinError
,
FormatMessage
,
errorTab
)
fromEnvironment
=
classmethod
(
fromEnvironment
)
def
formatError
(
self
,
errorcode
):
"""
Returns the string associated with a Windows error message, such as the
ones found in socket.error.
Attempts direct lookup against the win32 API via ctypes and then
pywin32 if available), then in the error table in the socket module,
then finally defaulting to C{os.strerror}.
@param errorcode: the Windows error code
@type errorcode: C{int}
@return: The error message string
@rtype: C{str}
"""
if
self
.
winError
is
not
None
:
return
self
.
winError
(
errorcode
)[
1
]
if
self
.
formatMessage
is
not
None
:
return
self
.
formatMessage
(
errorcode
)
if
self
.
errorTab
is
not
None
:
result
=
self
.
errorTab
.
get
(
errorcode
)
if
result
is
not
None
:
return
result
return
os
.
strerror
(
errorcode
)
formatError
=
_ErrorFormatter
.
fromEnvironment
().
formatError
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment