本文整理汇总了Python中errno.errorcode方法的典型用法代码示例。如果您正苦于以下问题:Python errno.errorcode方法的具体用法?Python errno.errorcode怎么用?Python errno.errorcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类errno
的用法示例。
在下文中一共展示了errno.errorcode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_connect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [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
示例2: _remove_watch_for_path
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def _remove_watch_for_path(self, path):
logging.debug('_remove_watch_for_path(%r)', path)
wd = self._directory_to_watch_descriptor[path]
if InotifyFileWatcher._libc.inotify_rm_watch(self._inotify_fd, wd) < 0:
# If the directory is deleted then the watch will removed automatically
# and inotify_rm_watch will fail. Just log the error.
logging.debug('inotify_rm_watch failed for %r: %d [%r]',
path,
ctypes.get_errno(),
errno.errorcode[ctypes.get_errno()])
parent_path = os.path.dirname(path)
if parent_path in self._directory_to_subdirs:
self._directory_to_subdirs[parent_path].remove(path)
# _directory_to_subdirs must be copied because it is mutated in the
# recursive call.
for subdir in frozenset(self._directory_to_subdirs[path]):
self._remove_watch_for_path(subdir)
del self._watch_to_directory[wd]
del self._directory_to_watch_descriptor[path]
del self._directory_to_subdirs[path]
示例3: _handle_connect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [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.
gen_log.warning("Connect error on fd %d: %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)
self._connecting = False
示例4: _handle_connect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [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.
#logging.warning("Connect error on fd %d: %s",
# self.socket.fileno(), errno.errorcode[err])
ht.logger.warning("Connect error on fd %d: %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)
self._connecting = False
示例5: sys_lseek
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def sys_lseek(self, fd: int, offset: int, whence: int) -> int:
"""
lseek - reposition read/write file offset
The lseek() function repositions the file offset of the open file description associated
with the file descriptor fd to the argument offset according to the directive whence
:param fd: a valid file descriptor
:param offset: the offset in bytes
:param whence: os.SEEK_SET: The file offset is set to offset bytes.
os.SEEK_CUR: The file offset is set to its current location plus offset bytes.
os.SEEK_END: The file offset is set to the size of the file plus offset bytes.
:return: offset from file beginning, or EBADF (fd is not a valid file descriptor or is not open)
"""
signed_offset = self._to_signed_dword(offset)
try:
return self._get_fdlike(fd).seek(signed_offset, whence)
except FdError as e:
logger.info(
f"sys_lseek: Not valid file descriptor on lseek. Fd not seekable. Returning -{errorcode(e.err)}"
)
return -e.err
示例6: sys_read
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def sys_read(self, fd: int, buf: int, count: int) -> int:
data: bytes = bytes()
if count != 0:
# TODO check count bytes from buf
if buf not in self.current.memory: # or not self.current.memory.isValid(buf+count):
logger.info("sys_read: buf points to invalid address. Returning -errno.EFAULT")
return -errno.EFAULT
try:
# Read the data and put it in memory
data = self._get_fdlike(fd).read(count)
except FdError as e:
logger.info(
f"sys_read: Not valid file descriptor ({fd}). Returning -{errorcode(e.err)}"
)
return -e.err
self.syscall_trace.append(("_read", fd, data))
self.current.write_bytes(buf, data)
return len(data)
示例7: connect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def connect(self, address):
"""
Try to make an actual connection.
:return: True if connected
"""
sock = self._connectors[address]
err = sock.connect()
self.poller.register(sock)
self._sock_by_fd[sock.fileno()] = sock
self._socks_waiting_to_connect.add(sock)
if err in (0, errno.EISCONN):
self.handle_connect(sock)
return True
elif err in (errno.ECONNREFUSED, errno.ENETUNREACH):
self.handle_conn_refused(sock)
elif err not in (errno.EINPROGRESS, errno.EWOULDBLOCK):
raise socket.error(err, errno.errorcode[err])
return False
##########################################################
示例8: _is_zero
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def _is_zero(self):
if sys.platform == 'darwin':
# Handle broken get_value for mac ==> only Lock will work
# as sem_get_value do not work properly
if pthread.sem_trywait(self.handle) < 0:
e = ctypes.get_errno()
if e == errno.EAGAIN:
return True
raise OSError(e, errno.errorcode[e])
else:
if pthread.sem_post(self.handle) < 0:
raiseFromErrno()
return False
else:
value = ctypes.pointer(ctypes.c_int(-1))
if pthread.sem_getvalue(self.handle, value) < 0:
raiseFromErrno()
return value.contents.value == 0
示例9: _remove_watch_for_path
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def _remove_watch_for_path(self, path):
# Must be called with _inotify_fd_lock held.
logging.debug('_remove_watch_for_path(%r)', path)
wd = self._directory_to_watch_descriptor[path]
if _libc.inotify_rm_watch(self._inotify_fd, wd) < 0:
# If the directory is deleted then the watch will removed automatically
# and inotify_rm_watch will fail. Just log the error.
logging.debug('inotify_rm_watch failed for %r: %d [%r]',
path,
ctypes.get_errno(),
errno.errorcode[ctypes.get_errno()])
parent_path = os.path.dirname(path)
if parent_path in self._directory_to_subdirs:
self._directory_to_subdirs[parent_path].remove(path)
# _directory_to_subdirs must be copied because it is mutated in the
# recursive call.
for subdir in frozenset(self._directory_to_subdirs[path]):
self._remove_watch_for_path(subdir)
del self._watch_to_directory[wd]
del self._directory_to_watch_descriptor[path]
del self._directory_to_subdirs[path]
示例10: test_log_run_ignore_output
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def test_log_run_ignore_output(self):
filename = self.make_temp_filename()
try:
os.remove(filename)
except OSError as e:
if e.errno != errno.ENOENT:
self.fail("Pre-test os.delete({0}) returned {1}".format(filename, errno.errorcode[e.errno]))
error = self._distro.log_run_ignore_output("touch {0}".format(filename))
self.assertEqual(error, 0)
try:
os.remove(filename)
except IOError as e:
if e.errno == errno.ENOENT:
self.fail("Test command did not properly execute")
else:
self.fail("Post-test os.delete({0}) returned {1}".format(filename, errno.errorcode[e.errno]))
示例11: _add_watch_for_path
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def _add_watch_for_path(self, path):
logging.debug('_add_watch_for_path(%r)', path)
for dirpath, directories, _ in itertools.chain(
[('', [path], None)],
os.walk(path, topdown=True, followlinks=True)):
for directory in directories:
directory_path = os.path.join(dirpath, directory)
# dirpath cannot be used as the parent directory path because it is the
# empty string for symlinks :-(
parent_path = os.path.dirname(directory_path)
watch_descriptor = InotifyFileWatcher._libc.inotify_add_watch(
self._inotify_fd,
ctypes.create_string_buffer(directory_path),
_INTERESTING_INOTIFY_EVENTS)
if watch_descriptor < 0:
if ctypes.get_errno() == errno.ENOSPC:
logging.warning(
'There are too many directories in your application for '
'changes in all of them to be monitored. You may have to '
'restart the development server to see some changes to your '
'files.')
return
error = OSError('could not add watch for %r' % directory_path)
error.errno = ctypes.get_errno()
error.strerror = errno.errorcode[ctypes.get_errno()]
error.filename = directory_path
raise error
if parent_path in self._directory_to_subdirs:
self._directory_to_subdirs[parent_path].add(directory_path)
self._watch_to_directory[watch_descriptor] = directory_path
self._directory_to_watch_descriptor[directory_path] = watch_descriptor
self._directory_to_subdirs[directory_path] = set()
示例12: start
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def start(self):
"""Start watching the directory for changes."""
self._class_setup()
self._inotify_fd = InotifyFileWatcher._libc.inotify_init()
if self._inotify_fd < 0:
error = OSError('failed call to inotify_init')
error.errno = ctypes.get_errno()
error.strerror = errno.errorcode[ctypes.get_errno()]
raise error
self._inotify_poll = select.poll()
self._inotify_poll.register(self._inotify_fd, select.POLLIN)
self._add_watch_for_path(self._directory)
示例13: make_output_socket
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def make_output_socket(self, remote_node_id: typing.Optional[int], remote_port: int) -> socket.socket:
if self.local_node_id is None:
raise pyuavcan.transport.OperationNotDefinedForAnonymousNodeError(
f'Anonymous UDP/IP nodes cannot emit transfers, they can only listen. '
f'The local IP address is {self._local}.'
)
bind_to = self._local.host_address
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setblocking(False)
try:
# Output sockets shall be bound, too, in order to ensure that outgoing packets have the correct
# source IP address specified. This is particularly important for localhost; an unbound socket
# there emits all packets from 127.0.0.1 which is certainly not what we need.
s.bind((str(bind_to), 0)) # Bind to an ephemeral port.
except OSError as ex:
if ex.errno == errno.EADDRNOTAVAIL:
raise pyuavcan.transport.InvalidMediaConfigurationError(
f'Bad IP configuration: cannot bind output socket to {bind_to} [{errno.errorcode[ex.errno]}]'
) from None
raise # pragma: no cover
# Specify the fixed remote end. The port is always fixed; the host is unicast or broadcast.
if remote_node_id is None:
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.connect((str(self._local.broadcast_address), remote_port))
elif 0 <= remote_node_id < self._max_nodes:
ip = IPv4Address(int(self._local.subnet_address) + remote_node_id)
assert ip in self._local
s.connect((str(ip), remote_port))
else:
raise ValueError(f'Cannot map the node-ID value {remote_node_id} to an IP address. '
f'The range of valid node-ID values is [0, {self._max_nodes})')
_logger.debug('%r: New output socket %r connected to remote node %r, remote port %r',
self, s, remote_node_id, remote_port)
return s
示例14: test_using_errorcode
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def test_using_errorcode(self):
# Every key value in errno.errorcode should be on the module.
for value in errno.errorcode.itervalues():
self.assertTrue(hasattr(errno, value), 'no %s attr in errno' % value)
示例15: test_attributes_in_errorcode
# 需要导入模块: import errno [as 别名]
# 或者: from errno import errorcode [as 别名]
def test_attributes_in_errorcode(self):
for attribute in errno.__dict__.iterkeys():
if attribute.isupper():
self.assertIn(getattr(errno, attribute), errno.errorcode,
'no %s attr in errno.errorcode' % attribute)