本文整理汇总了Python中os.strerror方法的典型用法代码示例。如果您正苦于以下问题:Python os.strerror方法的具体用法?Python os.strerror怎么用?Python os.strerror使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.strerror方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _extract_error
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def _extract_error():
"""
Extracts the last OS error message into a python unicode string
:return:
A unicode string error message
"""
error_num = errno()
try:
error_string = os.strerror(error_num)
except (ValueError):
return str_cls(error_num)
if isinstance(error_string, str_cls):
return error_string
return _try_decode(error_string)
示例2: _handle_connect
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def _handle_connect(self):
err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
if err != 0:
self.error = socket.error(err, os.strerror(err))
# IOLoop implementations may vary: some of them return
# an error state before the socket becomes writable, so
# in that case a connection failure would be handled by the
# error path in _handle_events instead of here.
if self._connect_future is None:
gen_log.warning("Connect error on fd %s: %s",
self.socket.fileno(), errno.errorcode[err])
self.close()
return
if self._connect_callback is not None:
callback = self._connect_callback
self._connect_callback = None
self._run_callback(callback)
if self._connect_future is not None:
future = self._connect_future
self._connect_future = None
future.set_result(self)
self._connecting = False
示例3: test_connection_refused
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def test_connection_refused(self):
cleanup_func, port = refusing_port()
self.addCleanup(cleanup_func)
with ExpectLog(gen_log, ".*", required=False):
self.http_client.fetch("http://127.0.0.1:%d/" % port, self.stop)
response = self.wait()
self.assertEqual(599, response.code)
if sys.platform != 'cygwin':
# cygwin returns EPERM instead of ECONNREFUSED here
contains_errno = str(errno.ECONNREFUSED) in str(response.error)
if not contains_errno and hasattr(errno, "WSAECONNREFUSED"):
contains_errno = str(errno.WSAECONNREFUSED) in str(response.error)
self.assertTrue(contains_errno, response.error)
# This is usually "Connection refused".
# On windows, strerror is broken and returns "Unknown error".
expected_message = os.strerror(errno.ECONNREFUSED)
self.assertTrue(expected_message in str(response.error),
response.error)
示例4: _add_fd_to_loop
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def _add_fd_to_loop(self, fd, cb, fd_events, userdata=None):
if cb is None:
self.logger.info(
"Cannot add fd '{}' to pomp loop without "
"a valid callback function".format(fd)
)
return None
self.fd_userdata[fd] = userdata
userdata = ctypes.cast(
ctypes.pointer(ctypes.py_object(userdata)), ctypes.c_void_p
)
self.c_fd_userdata[fd] = userdata
self.pomp_fd_callbacks[fd] = od.pomp_fd_event_cb_t(cb)
res = od.pomp_loop_add(
self.pomp_loop,
ctypes.c_int32(fd),
od.uint32_t(int(fd_events)),
self.pomp_fd_callbacks[fd],
userdata
)
if res != 0:
raise RuntimeError(
"Cannot add fd '{}' to pomp loop: {} ({})".format(
fd, os.strerror(-res), res)
)
示例5: unref
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def unref(self):
"""
This function decrements the reference counter of the underlying buffer(s)
"""
try:
res = od.vbuf_unref(self._buf)
if res != 0:
self.logger.error("vbuf_unref unpacked frame error: {} {} {}".format(
self._media_id,
os.strerror(-res),
ctypes.addressof(self._buf.contents)
))
finally:
if self._yuv_packed_buffer:
res = od.vbuf_unref(self._yuv_packed_buffer)
if res != 0:
self.logger.error("vbuf_unref packed frame error: {} {} {}".format(
self._media_id,
os.strerror(-res),
ctypes.addressof(self._buf.contents)
))
示例6: _make_gevent_unix_socket
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def _make_gevent_unix_socket(self, socket_file):
# the socket file must not exist prior to bind()
if os.path.exists(socket_file):
# avoid nuking regular files and symbolic links (could be a mistype or security issue)
if os.path.isfile(socket_file) or os.path.islink(socket_file):
raise OSError(errno.EEXIST, os.strerror(errno.EEXIST), socket_file)
os.remove(socket_file)
unix_sock = WSGIServer.get_listener(socket_file, family=socket.AF_UNIX)
self.unix_socket_file = socket_file
# ensure current user and group have r/w permissions, no permissions for other users
# this way the socket can be shared in a semi-secure manner
# between the user running calibre-web and the user running the fronting webserver
os.chmod(socket_file, 0o660)
return unix_sock
示例7: _instantiate_image
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def _instantiate_image(self, filename):
"""Instanciate the exiv2 image.
Args:
filename -- str(path to an image file)
"""
# This method is meant to be overridden in unit tests to easily replace
# the internal image reference by a mock.
if not os.path.exists(filename) or not os.path.isfile(filename):
raise IOError(ENOENT, os.strerror(ENOENT), filename)
# Remember the reference timestamps before doing any access to the file
stat = os.stat(filename)
self._atime = stat.st_atime
self._mtime = stat.st_mtime
return libexiv2python._Image(filename)
示例8: _create_file_from_fd
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def _create_file_from_fd(pfd):
"""Validates file description and creates a file-like object"""
# -1 is returned on error: http://man7.org/linux/man-pages/man2/open.2.html#RETURN_VALUE
if pfd == -1:
INVALID_ARG_ERRNO = 22
errno = ctypes.get_errno()
if errno == INVALID_ARG_ERRNO:
raise UnableToOpenPerfEvents('Invalid perf event file descriptor: {}, {}. '
'For cgroup based perf counters it may indicate there is '
'no enough hardware counters for measure all metrics!'
'If traceback shows problem in perf_uncore '
'it could be problem with PERF_FORMAT_GROUP in'
'perf_event_attr structure for perf_event_open syscall.'
'Older kernel cannot handle with extended format group.'
'Kernel cannot be 3.10.0-862.el7.x86_64 or lower.'
''.format(errno, os.strerror(errno)))
else:
raise UnableToOpenPerfEvents('Invalid perf event file descriptor: {}, {}.'
.format(errno, os.strerror(errno)))
return os.fdopen(pfd, 'rb')
示例9: _migrate_page_call
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def _migrate_page_call(pid, max_node, old_nodes, new_node) -> int:
"""Wrapper on migrate_pages function using libc syscall"""
pid = int(pid)
max = ctypes.c_ulong(max_node + 1)
old = ctypes.pointer(ctypes.c_ulong(old_nodes))
new = ctypes.pointer(ctypes.c_ulong(new_node))
# Example memory_migrate(256, pid, 5, 13 -> b'1101', 2 -> b'0010')
result = LIBC.syscall(NR_MIGRATE_PAGES, pid, max, old, new)
if result == -1:
errno = ctypes.get_errno()
raise UnableToMigratePages('Unable to migrate pages: {}, {}.'
.format(errno, os.strerror(errno)))
log.log(TRACE, 'Number of not moved pages (return from migrate_pages syscall): %d', result)
return result
示例10: monotonicTime
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def monotonicTime(self, asSeconds = True):
t = timespec()
if self.clock_gettime(rmMonotonicTime.CLOCK_MONOTONIC_RAW , ctypes.pointer(t)) != 0:
errno_ = ctypes.get_errno()
if self.fallback:
log.info("Monotonic Clock Error ! Reverting to time.time() fallback")
return self.monotonicFallback(asSeconds)
else:
raise OSError(errno_, os.strerror(errno_))
if asSeconds:
return t.tv_sec
return t.tv_sec + t.tv_nsec * 1e-9
#-----------------------------------------------------------------------------------------------
#
#
#
示例11: timeout
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
def decorator(func):
def _handle_timeout(signum, frame):
raise TimeoutError(error_message)
def wrapper(*args, **kwargs):
signal.signal(signal.SIGALRM, _handle_timeout)
signal.alarm(seconds)
try:
result = func(*args, **kwargs)
finally:
signal.alarm(0)
return result
return wraps(func)(wrapper)
return decorator
示例12: _check_errno
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def _check_errno(result, func, arguments):
assert func.restype in [c_int, c_void_p]
if (func.restype == c_int and result == -1) or (
func.restype == c_void_p and c_void_p(result).value == c_void_p(-1).value
):
errno = _ctypes.get_errno()
try:
func_name = func.__name__
except AttributeError:
func_name = "__unknown__"
msg = (
func_name
+ "("
+ ", ".join(map(str, arguments))
+ ") failed: "
+ _os.strerror(errno)
)
raise OSError(errno, msg)
return result
# off_t is a signed integer type required for mmap.
# In my tests it is equal to long on both 32bit and 64bit x86 Linux.
示例13: setUp
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def setUp(self, *args, **kwargs):
try:
container.execute_in_namespace(lambda: 0)
except OSError as e:
self.skipTest("Namespaces not supported: {}".format(os.strerror(e.errno)))
dir_modes = kwargs.pop(
"dir_modes",
{
"/": containerexecutor.DIR_READ_ONLY,
"/home": containerexecutor.DIR_HIDDEN,
"/tmp": containerexecutor.DIR_HIDDEN,
},
)
self.runexecutor = RunExecutor(
use_namespaces=True, dir_modes=dir_modes, *args, **kwargs
)
示例14: mocked_select_module
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def mocked_select_module(self):
"""Mocks the select.select() call to raise EINTR for first call"""
old_select = select.select
class MockSelect:
def __init__(self):
self.called = 0
def __call__(self, *args):
self.called += 1
if self.called == 1:
# raise the exception on first call
raise select.error(errno.EINTR, os.strerror(errno.EINTR))
else:
# Return real select value for consecutive calls
return old_select(*args)
select.select = MockSelect()
try:
yield select.select
finally:
select.select = old_select
示例15: test_connection_refused
# 需要导入模块: import os [as 别名]
# 或者: from os import strerror [as 别名]
def test_connection_refused(self):
cleanup_func, port = refusing_port()
self.addCleanup(cleanup_func)
with ExpectLog(gen_log, ".*", required=False):
with self.assertRaises(socket.error) as cm:
self.fetch("http://127.0.0.1:%d/" % port, raise_error=True)
if sys.platform != "cygwin":
# cygwin returns EPERM instead of ECONNREFUSED here
contains_errno = str(errno.ECONNREFUSED) in str(cm.exception)
if not contains_errno and hasattr(errno, "WSAECONNREFUSED"):
contains_errno = str(errno.WSAECONNREFUSED) in str( # type: ignore
cm.exception
)
self.assertTrue(contains_errno, cm.exception)
# This is usually "Connection refused".
# On windows, strerror is broken and returns "Unknown error".
expected_message = os.strerror(errno.ECONNREFUSED)
self.assertTrue(expected_message in str(cm.exception), cm.exception)