Python errno.errorcode() Examples
The following are 30
code examples of errno.errorcode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
errno
, or try the search function
.
Example #1
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 6 votes |
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
Example #2
Source File: test_commonActions.py From azure-linux-extensions with Apache License 2.0 | 6 votes |
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]))
Example #3
Source File: iostream.py From EventGhost with GNU General Public License v2.0 | 6 votes |
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
Example #4
Source File: iostream.py From tornado-zh with MIT License | 6 votes |
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
Example #5
Source File: inotify_file_watcher.py From browserscope with Apache License 2.0 | 6 votes |
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]
Example #6
Source File: iostream.py From viewfinder with Apache License 2.0 | 6 votes |
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
Example #7
Source File: iostream.py From viewfinder with Apache License 2.0 | 6 votes |
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
Example #8
Source File: semlock.py From loky with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #9
Source File: inotify_file_watcher.py From python-compat-runtime with Apache License 2.0 | 6 votes |
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]
Example #10
Source File: iostream.py From tornado-zh with MIT License | 6 votes |
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
Example #11
Source File: link.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
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 ##########################################################
Example #12
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #13
Source File: iostream.py From honeything with GNU General Public License v3.0 | 6 votes |
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
Example #14
Source File: test_pep3151.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_errno_mapping(self): # The OSError constructor maps errnos to subclasses # A sample test for the basic functionality e = OSError(EEXIST, "Bad file descriptor") self.assertIs(type(e), FileExistsError) # Exhaustive testing for errcode, exc in self._map.items(): e = OSError(errcode, "Some message") self.assertIs(type(e), exc) othercodes = set(errno.errorcode) - set(self._map) for errcode in othercodes: e = OSError(errcode, "Some message") self.assertIs(type(e), OSError)
Example #15
Source File: mitogen-fuse.py From mitogen with BSD 3-Clause "New" or "Revised" License | 5 votes |
def errno_wrap(modname, func, *args): try: return getattr(globals()[modname], func)(*args), None except (IOError, OSError): e = sys.exc_info()[1] if e.args[0] == errno.ENOENT: LOG.error('%r(**%r): %s', func, args, e) else: LOG.exception('While running %r(**%r)', func, args) return None, to_text(errno.errorcode[e.args[0]])
Example #16
Source File: test_errno.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_attributes_in_errorcode(self): for attribute in errno.__dict__.keys(): if attribute.isupper(): self.assertIn(getattr(errno, attribute), errno.errorcode, 'no %s attr in errno.errorcode' % attribute)
Example #17
Source File: test_errno.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_using_errorcode(self): # Every key value in errno.errorcode should be on the module. for value in errno.errorcode.values(): self.assertTrue(hasattr(errno, value), 'no %s attr in errno' % value)
Example #18
Source File: test_errno.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #19
Source File: network_manager.py From futuquant with Apache License 2.0 | 5 votes |
def _on_write(self, conn): if conn.status == ConnStatus.Closed: return elif conn.status == ConnStatus.Connecting: err = conn.sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) self._watch_write(conn, False) if err != 0: conn.handler.on_error(conn.conn_id, errno.errorcode[err]) else: conn.status = ConnStatus.Connected conn.handler.on_connected(conn.conn_id) return err = None size = 0 try: if len(conn.writebuf) > 0: size = conn.sock.send(conn.writebuf) except Exception as e: if not is_socket_exception_wouldblock(e): err = str(e) if size > 0: del conn.writebuf[:size] if len(conn.writebuf) == 0: self._watch_write(conn, False) if err: self.close(conn.conn_id) conn.handler.on_error(conn.conn_id, err)
Example #20
Source File: link.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def handle_recv(self, sock): conn_id = sock.conn_id if conn_id is None: # socket could be closed in one poll round before recv return # do not put it in a draining cycle to avoid other links starvation try: fragment = sock.recv(self.recv_block_size) except ssl.SSLError as exc: if exc.args[0] != ssl.SSL_ERROR_WANT_READ: raise # wait for next round, SSL context has not enough data do decrypt except socket.error as exc: # TODO catch SSL exceptions err = exc.args[0] if err in (errno.ECONNRESET, errno.ENOTCONN, errno.ESHUTDOWN, errno.ECONNABORTED, errno.EPIPE, errno.EBADF): self.log.error("recv %s error %s" % (conn_id, errno.errorcode[err])) self.handle_close(sock) elif err != errno.EWOULDBLOCK: raise else: if fragment: self.log.debug("recv %s len=%i" % (conn_id, len(fragment))) self.on_recv(conn_id, fragment) else: self.handle_close(sock) ##########################################################
Example #21
Source File: network_manager.py From py-futu-api with Apache License 2.0 | 5 votes |
def _on_write(self, conn): if conn.status == ConnStatus.Closed: return elif conn.status == ConnStatus.Connecting: err = conn.sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) self._watch_write(conn, False) if err != 0: conn.handler.on_error(conn.conn_id, errno.errorcode[err]) else: conn.status = ConnStatus.Connected conn.handler.on_connected(conn.conn_id) return err = None size = 0 try: if len(conn.writebuf) > 0: size = conn.sock.send(conn.writebuf) except Exception as e: if not is_socket_exception_wouldblock(e): err = str(e) if size > 0: del conn.writebuf[:size] if len(conn.writebuf) == 0: self._watch_write(conn, False) if err: self.close(conn.conn_id) conn.handler.on_error(conn.conn_id, err)
Example #22
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 5 votes |
def sys_fstat(self, fd, buf): """ Determines information about a file based on its file descriptor. :rtype: int :param fd: the file descriptor of the file that is being inquired. :param buf: a buffer where data about the file will be stored. :return: C{0} on success, EBADF when called with bad fd """ try: stat = self._get_fdlike(fd).stat() except FdError as e: logger.info(f"sys_fstat: invalid fd ({fd}), returning -{errorcode(e.err)}") return -e.err def add(width, val): fformat = {2: "H", 4: "L", 8: "Q"}[width] return struct.pack("<" + fformat, val) def to_timespec(ts): return struct.pack("<LL", int(ts), int(ts % 1 * 1e9)) bufstat = add(8, stat.st_dev) # dev_t st_dev; bufstat += add(4, 0) # __pad1 bufstat += add(4, stat.st_ino) # unsigned long st_ino; bufstat += add(4, stat.st_mode) # unsigned short st_mode; bufstat += add(4, stat.st_nlink) # unsigned short st_nlink; bufstat += add(4, stat.st_uid) # unsigned short st_uid; bufstat += add(4, stat.st_gid) # unsigned short st_gid; bufstat += add(4, stat.st_rdev) # unsigned long st_rdev; bufstat += add(4, stat.st_size) # unsigned long st_size; bufstat += add(4, stat.st_blksize) # unsigned long st_blksize; bufstat += add(4, stat.st_blocks) # unsigned long st_blocks; bufstat += to_timespec(stat.st_atime) # unsigned long st_atime; bufstat += to_timespec(stat.st_mtime) # unsigned long st_mtime; bufstat += to_timespec(stat.st_ctime) # unsigned long st_ctime; bufstat += add(4, 0) # unsigned long __unused4; bufstat += add(4, 0) # unsigned long __unused5; self.current.write_bytes(buf, bufstat) return 0
Example #23
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 5 votes |
def sys_dup2(self, fd: int, newfd: int) -> int: """ Duplicates an open fd to newfd. If newfd is open, it is first closed :param fd: the open file descriptor to duplicate. :param newfd: the file descriptor to alias the file described by fd. :return: newfd. """ try: f = self._get_fdlike(fd) except FdError as e: logger.info("sys_dup2: fd ({fd}) is not open. Returning -{errorcode(e.err)}") return -e.err soft_max, hard_max = self._rlimits[resource.RLIMIT_NOFILE] if newfd >= soft_max: logger.info( f"sys_dup2: newfd ({newfd}) is above max descriptor table size ({soft_max})" ) return -errno.EBADF if self._is_fd_open(newfd): self._close(newfd) self.fd_table.add_entry_at(f, fd) logger.debug("sys_dup2(%d,%d) -> %d", fd, newfd, newfd) return newfd
Example #24
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 5 votes |
def sys_dup(self, fd: int) -> int: """ Duplicates an open file descriptor :rtype: int :param fd: the open file descriptor to duplicate. :return: the new file descriptor. """ try: f = self._get_fdlike(fd) except FdError as e: logger.info(f"sys_dup: fd ({fd}) is not open. Returning -{errorcode(e.err)}") return -e.err return self._open(f)
Example #25
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 5 votes |
def sys_llseek( self, fd: int, offset_high: int, offset_low: int, resultp: int, whence: int ) -> int: """ _llseek - reposition read/write file offset The _llseek() system call repositions the offset of the open file description associated with the file descriptor fd to (offset_high<<32) | offset_low bytes relative to the beginning of the file, the current file offset, or the end of the file, depending on whether whence is os.SEEK_SET, os.SEEK_CUR, or os.SEEK_END, respectively. It returns the resulting file position in the argument result. This system call exists on various 32-bit platforms to support seeking to large file offsets. :param fd: a valid file descriptor :param offset_high: the high 32 bits of the byte offset :param offset_low: the low 32 bits of the byte offset :param resultp: a pointer to write the position into on success :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: 0 on success, negative on error """ signed_offset_high = self._to_signed_dword(offset_high) signed_offset_low = self._to_signed_dword(offset_low) signed_offset = (signed_offset_high << 32) | signed_offset_low try: pos = self._get_fdlike(fd).seek(signed_offset, whence) posbuf = struct.pack("q", pos) # `loff_t * resultp` in linux, which is `long long` self.current.write_bytes(resultp, posbuf) return 0 except FdError as e: logger.info( f"sys_llseek: Not valid file descriptor on llseek. Fd not seekable. Returning -{errorcode(e.err)}" ) return -e.err
Example #26
Source File: test_errno.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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)
Example #27
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 5 votes |
def errorcode(code: int) -> str: return f"errno.{errno.errorcode[code]}"
Example #28
Source File: evdev.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _IOR_len(type, nr): def f(fileno, buffer): request = _IOC(_IOC_READ, ord(type), nr, ctypes.sizeof(buffer)) if c.ioctl(fileno, request, ctypes.byref(buffer)) < 0: err = ctypes.c_int.in_dll(c, 'errno').value raise OSError(err, errno.errorcode[err]) return buffer return f
Example #29
Source File: evdev.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _IOR(type, nr, struct): request = _IOC(_IOC_READ, ord(type), nr, ctypes.sizeof(struct)) def f(fileno): buffer = struct() if c.ioctl(fileno, request, ctypes.byref(buffer)) < 0: err = ctypes.c_int.in_dll(c, 'errno').value raise OSError(err, errno.errorcode[err]) return buffer return f
Example #30
Source File: semlock.py From loky with BSD 3-Clause "New" or "Revised" License | 5 votes |
def release(self): if self.kind == RECURSIVE_MUTEX: assert self._is_mine(), ( "attempt to release recursive lock not owned by thread") if self.count > 1: self.count -= 1 return assert self.count == 1 else: if sys.platform == 'darwin': # Handle broken get_value for mac ==> only Lock will work # as sem_get_value do not work properly if self.maxvalue == 1: if pthread.sem_trywait(self.handle) < 0: e = ctypes.get_errno() if e != errno.EAGAIN: raise OSError(e, errno.errorcode[e]) else: if pthread.sem_post(self.handle) < 0: raiseFromErrno() else: raise ValueError( "semaphore or lock released too many times") else: import warnings warnings.warn("semaphore are broken on OSX, release might " "increase its maximal value", RuntimeWarning) else: value = self._get_value() if value >= self.maxvalue: raise ValueError( "semaphore or lock released too many times") if pthread.sem_post(self.handle) < 0: raiseFromErrno() self.count -= 1