def test_stdlib_and_errno(): write = standard_c_lib.write write.argtypes = [c_int, c_char_p, c_size_t] write.restype = c_size_t # clear errno first set_errno(0) assert get_errno() == 0 write(-345, "abc", 3) assert get_errno() != 0 set_errno(0) assert get_errno() == 0
def test_stdlib_and_errno(): py.test.skip("this is expected on top of pypy, we need to fix ctypes in a way that is now in 2.6 in order to make this reliable") write = standard_c_lib.write write.argtypes = [c_int, c_char_p, c_size_t] write.restype = c_size_t # clear errno first set_errno(0) assert get_errno() == 0 write(-345, "abc", 3) assert get_errno() != 0 set_errno(0) assert get_errno() == 0
def test_stdlib_and_errno(): py.test.skip("this is expected on top of pypy, we need to fix ctypes in a way that is now in 2.6 in order to make this reliable") write = standard_c_lib.write write.argtypes = [c_int, c_char_p, c_size_t] write.restype = c_size_t # clear errno first set_errno(0) assert get_errno() == 0 write(-345, "abc", 3) assert get_errno() != 0 set_errno(0) assert get_errno() == 0
def getrusage(who): ru = _struct_rusage() ret = _getrusage(who, byref(ru)) if ret == -1: errno = get_errno() if errno == EINVAL: raise ValueError("invalid who parameter") raise error(errno) return struct_rusage(( float(ru.ru_utime), float(ru.ru_stime), ru.ru_maxrss, ru.ru_ixrss, ru.ru_idrss, ru.ru_isrss, ru.ru_minflt, ru.ru_majflt, ru.ru_nswap, ru.ru_inblock, ru.ru_oublock, ru.ru_msgsnd, ru.ru_msgrcv, ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw, ))
def getrusage(who): ru = _struct_rusage() ret = _getrusage(who, byref(ru)) if ret == -1: errno = get_errno() if errno == EINVAL: raise ValueError("invalid who parameter") raise error(errno) return struct_rusage(( float(ru.ru_utime), float(ru.ru_stime), ru.ru_maxrss, ru.ru_ixrss, ru.ru_idrss, ru.ru_isrss, ru.ru_minflt, ru.ru_majflt, ru.ru_nswap, ru.ru_inblock, ru.ru_oublock, ru.ru_msgsnd, ru.ru_msgrcv, ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw, ))
def bindtextdomain(domain, dir): """bindtextdomain(domain, dir) -> string Bind the C library's domain to dir.""" dirname = _bindtextdomain(domain, dir) if not dirname: errno = get_errno() raise OSError(errno) return dirname
def bindtextdomain(domain, dir): """bindtextdomain(domain, dir) -> string Bind the C library's domain to dir.""" dirname = _bindtextdomain(domain, dir) if not dirname: errno = get_errno() raise OSError(errno) return dirname
def getrusage(who): ru = _struct_rusage() ret = _getrusage(who, byref(ru)) if ret == -1: errno = get_errno() if errno == EINVAL: raise ValueError("invalid who parameter") raise ResourceError(errno) return struct_rusage(ru)
def getrlimit(resource): if not (0 <= resource < RLIM_NLIMITS): return ValueError("invalid resource specified") rlim = rlimit() ret = _getrlimit(resource, byref(rlim)) if ret == -1: errno = get_errno() raise ResourceError(errno) return (rlim.rlim_cur, rlim.rlim_max)
def getrlimit(resource): if not(0 <= resource < RLIM_NLIMITS): return ValueError("invalid resource specified") rlim = rlimit() ret = _getrlimit(resource, byref(rlim)) if ret == -1: errno = get_errno() raise error(errno) return (rlim.rlim_cur, rlim.rlim_max)
def setrlimit(resource, rlim): if not (0 <= resource < RLIM_NLIMITS): return ValueError("invalid resource specified") rlim = rlimit(rlim[0], rlim[1]) ret = _setrlimit(resource, byref(rlim)) if ret == -1: errno = get_errno() if errno == EINVAL: return ValueError("current limit exceeds maximum limit") elif errno == EPERM: return ValueError("not allowed to raise maximum limit") else: raise ResourceError(errno)
def setrlimit(resource, rlim): if not(0 <= resource < RLIM_NLIMITS): return ValueError("invalid resource specified") rlimit_check_bounds(*rlim) rlim = rlimit(rlim[0], rlim[1]) ret = _setrlimit(resource, byref(rlim)) if ret == -1: errno = get_errno() if errno == EINVAL: return ValueError("current limit exceeds maximum limit") elif errno == EPERM: return ValueError("not allowed to raise maximum limit") else: raise error(errno)
def locking(fd, mode, nbytes): '''lock or unlock a number of bytes in a file.''' rv = _locking(fd, mode, nbytes) if rv != 0: e = get_errno() raise IOError(e, errno.errorcode[e])
def locking(fd, mode, nbytes): """lock or unlock a number of bytes in a file.""" rv = _locking(fd, mode, nbytes) if rv != 0: e = get_errno() raise IOError(e, errno.errorcode[e])