Python errno.ERANGE Examples
The following are 13
code examples of errno.ERANGE().
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: fuse.py From ff4d with BSD 3-Clause "New" or "Revised" License | 6 votes |
def getxattr(self, path, name, value, size, *args): ret = self.operations('getxattr', path.decode(self.encoding), name.decode(self.encoding), *args) retsize = len(ret) # allow size queries if not value: return retsize # do not truncate if retsize > size: return -errno.ERANGE # Does not add trailing 0 buf = ctypes.create_string_buffer(ret, retsize) ctypes.memmove(value, buf, retsize) return retsize
Example #2
Source File: fuse.py From ff4d with BSD 3-Clause "New" or "Revised" License | 6 votes |
def listxattr(self, path, namebuf, size): attrs = self.operations('listxattr', path.decode(self.encoding)) or '' ret = '\x00'.join(attrs).encode(self.encoding) if len(ret) > 0: ret += '\x00'.encode(self.encoding) retsize = len(ret) # allow size queries if not namebuf: return retsize # do not truncate if retsize > size: return -errno.ERANGE buf = ctypes.create_string_buffer(ret, retsize) ctypes.memmove(namebuf, buf, retsize) return retsize
Example #3
Source File: path.py From eddy with GNU General Public License v3.0 | 5 votes |
def isPathValid(path): """ Returns True if the given path is valid, False otherwise. :type path: str :rtype: bool """ try: if not path or not isinstance(path, str): return False path = expandPath(path) path = os.path.splitdrive(path)[1] root = os.path.sep if __WIN32: root = os.environ.get('HOMEDRIVE', 'C:') root = '{0}{1}'.format(root.rstrip(os.path.sep), os.path.sep) assert os.path.isdir(root) for part in path.split(os.path.sep): try: os.lstat(os.path.join(root, part)) except OSError as exc: if hasattr(exc, 'winerror'): if exc.winerror == 123: return False if exc.errno in {errno.ENAMETOOLONG, errno.ERANGE}: return False except TypeError: return False else: return True
Example #4
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 5 votes |
def sys_getcwd(self, buf, size) -> int: """ getcwd - Get the current working directory :param int buf: Pointer to dest array :param size: size in bytes of the array pointed to by the buf :return: buf (Success), or 0 """ try: current_dir = os.getcwd() length = len(current_dir) + 1 if size > 0 and size < length: logger.info( "GETCWD: size is greater than 0, but is smaller than the length " "of the path + 1. Returning -errno.ERANGE" ) return -errno.ERANGE if not self.current.memory.access_ok(slice(buf, buf + length), "w"): logger.info("GETCWD: buf within invalid memory. Returning -errno.EFAULT") return -errno.EFAULT self.current.write_string(buf, current_dir) logger.debug(f"getcwd(0x{buf:08x}, {size}) -> <{current_dir}> (Size {length})") return length except OSError as e: return -e.errno
Example #5
Source File: ytfs.py From ytfs with MIT License | 5 votes |
def listxattr_FIX(self, path, namebuf, size): attrs = self.operations('listxattr', path.decode(self.encoding)) or '' ret = '\x00'.join(attrs).encode(self.encoding) + '\x00'.encode('ascii') # <= fixed here retsize = len(ret) # allow size queries if not namebuf: return retsize # do not truncate if retsize > size: return -errno.ERANGE buf = create_string_buffer(ret, retsize) memmove(namebuf, buf, retsize) return retsize
Example #6
Source File: error.py From libnl with GNU Lesser General Public License v2.1 | 5 votes |
def nl_syserr2nlerr(error_): """https://github.com/thom311/libnl/blob/libnl3_2_25/lib/error.c#L84.""" error_ = abs(error_) legend = { errno.EBADF: libnl.errno_.NLE_BAD_SOCK, errno.EADDRINUSE: libnl.errno_.NLE_EXIST, errno.EEXIST: libnl.errno_.NLE_EXIST, errno.EADDRNOTAVAIL: libnl.errno_.NLE_NOADDR, errno.ESRCH: libnl.errno_.NLE_OBJ_NOTFOUND, errno.ENOENT: libnl.errno_.NLE_OBJ_NOTFOUND, errno.EINTR: libnl.errno_.NLE_INTR, errno.EAGAIN: libnl.errno_.NLE_AGAIN, errno.ENOTSOCK: libnl.errno_.NLE_BAD_SOCK, errno.ENOPROTOOPT: libnl.errno_.NLE_INVAL, errno.EFAULT: libnl.errno_.NLE_INVAL, errno.EACCES: libnl.errno_.NLE_NOACCESS, errno.EINVAL: libnl.errno_.NLE_INVAL, errno.ENOBUFS: libnl.errno_.NLE_NOMEM, errno.ENOMEM: libnl.errno_.NLE_NOMEM, errno.EAFNOSUPPORT: libnl.errno_.NLE_AF_NOSUPPORT, errno.EPROTONOSUPPORT: libnl.errno_.NLE_PROTO_MISMATCH, errno.EOPNOTSUPP: libnl.errno_.NLE_OPNOTSUPP, errno.EPERM: libnl.errno_.NLE_PERM, errno.EBUSY: libnl.errno_.NLE_BUSY, errno.ERANGE: libnl.errno_.NLE_RANGE, errno.ENODEV: libnl.errno_.NLE_NODEV, } return int(legend.get(error_, libnl.errno_.NLE_FAILURE))
Example #7
Source File: questions.py From python-inquirer with MIT License | 5 votes |
def is_pathname_valid(pathname): """ `True` if the passed pathname is a valid pathname for the current OS; `False` otherwise. """ try: if not isinstance(pathname, str) or not pathname: return False _, pathname = os.path.splitdrive(pathname) root_dirname = os.environ.get('HOMEDRIVE', 'C:') \ if sys.platform == 'win32' else os.path.sep assert os.path.isdir(root_dirname) root_dirname = root_dirname.rstrip(os.path.sep) + os.path.sep for pathname_part in pathname.split(os.path.sep): try: os.lstat(root_dirname + pathname_part) except OSError as exc: if hasattr(exc, 'winerror'): if exc.winerror == ERROR_INVALID_NAME: return False elif exc.errno in {errno.ENAMETOOLONG, errno.ERANGE}: return False except (ValueError, TypeError): return False else: return True
Example #8
Source File: test_posix.py From ironpython2 with Apache License 2.0 | 4 votes |
def test_getcwd_long_pathnames(self): dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef' curdir = os.getcwd() base_path = os.path.abspath(test_support.TESTFN) + '.getcwd' try: os.mkdir(base_path) os.chdir(base_path) except: self.skipTest("cannot create directory for testing") try: def _create_and_do_getcwd(dirname, current_path_length = 0): try: os.mkdir(dirname) except: self.skipTest("mkdir cannot create directory sufficiently " "deep for getcwd test") os.chdir(dirname) try: os.getcwd() if current_path_length < 4099: _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) except OSError as e: expected_errno = errno.ENAMETOOLONG # The following platforms have quirky getcwd() # behaviour -- see issue 9185 and 15765 for # more information. quirky_platform = ( 'sunos' in sys.platform or 'netbsd' in sys.platform or 'openbsd' in sys.platform ) if quirky_platform: expected_errno = errno.ERANGE if 'darwin' in sys.platform: # macOS 10.15 may return errno.ENOENT instead self.assertIn(e.errno, (errno.ENOENT, errno.ENAMETOOLONG)) else: self.assertEqual(e.errno, expected_errno) finally: os.chdir('..') os.rmdir(dirname) _create_and_do_getcwd(dirname) finally: os.chdir(curdir) shutil.rmtree(base_path)
Example #9
Source File: test_posix.py From BinderFilter with MIT License | 4 votes |
def test_getcwd_long_pathnames(self): if hasattr(posix, 'getcwd'): dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef' curdir = os.getcwd() base_path = os.path.abspath(test_support.TESTFN) + '.getcwd' try: os.mkdir(base_path) os.chdir(base_path) except: # Just returning nothing instead of the SkipTest exception, # because the test results in Error in that case. # Is that ok? # raise unittest.SkipTest, "cannot create directory for testing" return try: def _create_and_do_getcwd(dirname, current_path_length = 0): try: os.mkdir(dirname) except: raise unittest.SkipTest, "mkdir cannot create directory sufficiently deep for getcwd test" os.chdir(dirname) try: os.getcwd() if current_path_length < 4099: _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) except OSError as e: expected_errno = errno.ENAMETOOLONG # The following platforms have quirky getcwd() # behaviour -- see issue 9185 and 15765 for # more information. quirky_platform = ( 'sunos' in sys.platform or 'netbsd' in sys.platform or 'openbsd' in sys.platform ) if quirky_platform: expected_errno = errno.ERANGE self.assertEqual(e.errno, expected_errno) finally: os.chdir('..') os.rmdir(dirname) _create_and_do_getcwd(dirname) finally: os.chdir(curdir) shutil.rmtree(base_path)
Example #10
Source File: test_posix.py From oss-ftp with MIT License | 4 votes |
def test_getcwd_long_pathnames(self): dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef' curdir = os.getcwd() base_path = os.path.abspath(test_support.TESTFN) + '.getcwd' try: os.mkdir(base_path) os.chdir(base_path) except: self.skipTest("cannot create directory for testing") try: def _create_and_do_getcwd(dirname, current_path_length = 0): try: os.mkdir(dirname) except: self.skipTest("mkdir cannot create directory sufficiently " "deep for getcwd test") os.chdir(dirname) try: os.getcwd() if current_path_length < 4099: _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) except OSError as e: expected_errno = errno.ENAMETOOLONG # The following platforms have quirky getcwd() # behaviour -- see issue 9185 and 15765 for # more information. quirky_platform = ( 'sunos' in sys.platform or 'netbsd' in sys.platform or 'openbsd' in sys.platform ) if quirky_platform: expected_errno = errno.ERANGE self.assertEqual(e.errno, expected_errno) finally: os.chdir('..') os.rmdir(dirname) _create_and_do_getcwd(dirname) finally: os.chdir(curdir) shutil.rmtree(base_path)
Example #11
Source File: test_posix.py From gcblue with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_getcwd_long_pathnames(self): dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef' curdir = os.getcwd() base_path = os.path.abspath(test_support.TESTFN) + '.getcwd' try: os.mkdir(base_path) os.chdir(base_path) except: self.skipTest("cannot create directory for testing") try: def _create_and_do_getcwd(dirname, current_path_length = 0): try: os.mkdir(dirname) except: self.skipTest("mkdir cannot create directory sufficiently " "deep for getcwd test") os.chdir(dirname) try: os.getcwd() if current_path_length < 4099: _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) except OSError as e: expected_errno = errno.ENAMETOOLONG # The following platforms have quirky getcwd() # behaviour -- see issue 9185 and 15765 for # more information. quirky_platform = ( 'sunos' in sys.platform or 'netbsd' in sys.platform or 'openbsd' in sys.platform ) if quirky_platform: expected_errno = errno.ERANGE self.assertEqual(e.errno, expected_errno) finally: os.chdir('..') os.rmdir(dirname) _create_and_do_getcwd(dirname) finally: os.chdir(curdir) shutil.rmtree(base_path)
Example #12
Source File: test_posix.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def test_getcwd_long_pathnames(self): if hasattr(posix, 'getcwd'): dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef' curdir = os.getcwd() base_path = os.path.abspath(test_support.TESTFN) + '.getcwd' try: os.mkdir(base_path) os.chdir(base_path) except: # Just returning nothing instead of the SkipTest exception, # because the test results in Error in that case. # Is that ok? # raise unittest.SkipTest, "cannot create directory for testing" return try: def _create_and_do_getcwd(dirname, current_path_length = 0): try: os.mkdir(dirname) except: raise unittest.SkipTest, "mkdir cannot create directory sufficiently deep for getcwd test" os.chdir(dirname) try: os.getcwd() if current_path_length < 4099: _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) except OSError as e: expected_errno = errno.ENAMETOOLONG if 'sunos' in sys.platform or 'openbsd' in sys.platform: expected_errno = errno.ERANGE # Issue 9185 self.assertEqual(e.errno, expected_errno) finally: os.chdir('..') os.rmdir(dirname) _create_and_do_getcwd(dirname) finally: os.chdir(curdir) shutil.rmtree(base_path)
Example #13
Source File: test_posix.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
def test_getcwd_long_pathnames(self): if hasattr(posix, 'getcwd'): dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef' curdir = os.getcwd() base_path = os.path.abspath(test_support.TESTFN) + '.getcwd' try: os.mkdir(base_path) os.chdir(base_path) except: # Just returning nothing instead of the SkipTest exception, # because the test results in Error in that case. # Is that ok? # raise unittest.SkipTest, "cannot create directory for testing" return try: def _create_and_do_getcwd(dirname, current_path_length = 0): try: os.mkdir(dirname) except: raise unittest.SkipTest, "mkdir cannot create directory sufficiently deep for getcwd test" os.chdir(dirname) try: os.getcwd() if current_path_length < 4099: _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) except OSError as e: expected_errno = errno.ENAMETOOLONG if 'sunos' in sys.platform or 'openbsd' in sys.platform: expected_errno = errno.ERANGE # Issue 9185 self.assertEqual(e.errno, expected_errno) finally: os.chdir('..') os.rmdir(dirname) _create_and_do_getcwd(dirname) finally: os.chdir(curdir) shutil.rmtree(base_path)