本文整理汇总了Python中errno.EFAULT属性的典型用法代码示例。如果您正苦于以下问题:Python errno.EFAULT属性的具体用法?Python errno.EFAULT怎么用?Python errno.EFAULT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.EFAULT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_add_minor_block_request
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def handle_add_minor_block_request(self, req):
""" For local miner to submit mined blocks through master """
try:
block = MinorBlock.deserialize(req.minor_block_data)
except Exception:
return AddMinorBlockResponse(error_code=errno.EBADMSG)
shard = self.shards.get(block.header.branch, None)
if not shard:
return AddMinorBlockResponse(error_code=errno.EBADMSG)
if block.header.hash_prev_minor_block != shard.state.header_tip.get_hash():
# Tip changed, don't bother creating a fork
Logger.info(
"[{}] dropped stale block {} mined locally".format(
block.header.branch.to_str(), block.header.height
)
)
return AddMinorBlockResponse(error_code=0)
success = await shard.add_block(block)
return AddMinorBlockResponse(error_code=0 if success else errno.EFAULT)
示例2: _bind_by_name
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def _bind_by_name(self, socket, name):
if not service_name_format.match(name):
raise err.Error(errno.EFAULT)
with self.lock:
if self.snl.get(name) is not None:
raise err.Error(errno.EADDRINUSE)
addr = wks_map.get(name)
if addr is None:
try:
addr = 16 + self.sap[16:32].index(None)
except ValueError:
raise err.Error(errno.EADDRNOTAVAIL)
socket.bind(addr)
self.sap[addr] = ServiceAccessPoint(addr, self)
self.sap[addr].insert_socket(socket)
self.snl[name] = addr
示例3: test_bind_by_addr
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def test_bind_by_addr(self, llc, raw, ldl, dlc):
llc.bind(raw, 16)
assert llc.getsockname(raw) == 16
for i, sock in enumerate([ldl, dlc]):
with pytest.raises(nfc.llcp.Error) as excinfo:
llc.bind(sock, 16)
assert excinfo.value.errno == errno.EACCES
llc.bind(ldl, 63)
assert llc.getsockname(ldl) == 63
with pytest.raises(nfc.llcp.Error) as excinfo:
llc.bind(dlc, 63)
assert excinfo.value.errno == errno.EADDRINUSE
with pytest.raises(nfc.llcp.Error) as excinfo:
llc.bind(dlc, 64)
assert excinfo.value.errno == errno.EFAULT
with pytest.raises(nfc.llcp.Error) as excinfo:
llc.bind(dlc, -1)
assert excinfo.value.errno == errno.EFAULT
llc.bind(dlc, 62)
assert llc.getsockname(dlc) == 62
示例4: test_bind_by_name
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def test_bind_by_name(self, llc, raw, ldl, dlc):
with pytest.raises(nfc.llcp.Error) as excinfo:
llc.bind(dlc, 'urn:nfc:snep')
assert excinfo.value.errno == errno.EFAULT
llc.bind(dlc, 'urn:nfc:sn:snep')
assert llc.getsockname(dlc) == 4
with pytest.raises(nfc.llcp.Error) as excinfo:
llc.bind(ldl, 'urn:nfc:sn:snep')
assert excinfo.value.errno == errno.EADDRINUSE
llc.bind(ldl, 'urn:nfc:xsn:nfcpy.org:service')
assert llc.getsockname(ldl) == 16
for sap in range(17, 32):
sock = llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT)
llc.bind(sock, 'urn:nfc:sn:use_sap-{}'.format(sap))
assert llc.getsockname(sock) == sap
with pytest.raises(nfc.llcp.Error) as excinfo:
llc.bind(raw, 'urn:nfc:sn:sap-32')
assert excinfo.value.errno == errno.EADDRNOTAVAIL
示例5: test_add_signal_handler_install_error
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def test_add_signal_handler_install_error(self, m_signal):
m_signal.NSIG = signal.NSIG
def set_wakeup_fd(fd):
if fd == -1:
raise ValueError()
m_signal.set_wakeup_fd = set_wakeup_fd
class Err(OSError):
errno = errno.EFAULT
m_signal.signal.side_effect = Err
self.assertRaises(
Err,
self.loop.add_signal_handler,
signal.SIGINT, lambda: True)
示例6: sys_read
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [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: sys_chroot
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def sys_chroot(self, path):
"""
An implementation of chroot that does perform some basic error checking,
but does not actually chroot.
:param path: Path to chroot
"""
if path not in self.current.memory:
return -errno.EFAULT
path_s = self.current.read_string(path)
if not os.path.exists(path_s):
return -errno.ENOENT
if not os.path.isdir(path_s):
return -errno.ENOTDIR
return -errno.EPERM
示例8: sys_recv
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def sys_recv(self, sockfd: int, buf: int, count: int, flags: int, trace_str="_recv") -> int:
if not self.current.memory.access_ok(slice(buf, buf + count), "w"):
logger.info("RECV: buf within invalid memory. Returning -errno.EFAULT")
return -errno.EFAULT
try:
sock = self._get_fdlike(sockfd)
except FdError:
return -errno.EBADF
if not isinstance(sock, Socket):
return -errno.ENOTSOCK
data = sock.read(count)
if len(data) == 0:
return 0
self.syscall_trace.append((trace_str, sockfd, data))
self.current.write_bytes(buf, data)
return len(data)
示例9: bind
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def bind(self, socket, addr_or_name=None):
if not isinstance(socket, tco.TransmissionControlObject):
raise err.Error(errno.ENOTSOCK)
if socket.addr is not None:
raise err.Error(errno.EINVAL)
if addr_or_name is None:
self._bind_by_none(socket)
elif isinstance(addr_or_name, int):
self._bind_by_addr(socket, addr_or_name)
elif isinstance(addr_or_name, (bytes, bytearray)):
self._bind_by_name(socket, bytes(addr_or_name))
elif isinstance(addr_or_name, str):
self._bind_by_name(socket, addr_or_name.encode('latin'))
else:
raise err.Error(errno.EFAULT)
示例10: _bind_by_addr
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def _bind_by_addr(self, socket, addr):
if addr < 0 or addr > 63:
raise err.Error(errno.EFAULT)
with self.lock:
if addr in range(32, 64) or isinstance(socket, tco.RawAccessPoint):
if self.sap[addr] is None:
socket.bind(addr)
self.sap[addr] = ServiceAccessPoint(addr, self)
self.sap[addr].insert_socket(socket)
else:
raise err.Error(errno.EADDRINUSE)
else:
raise err.Error(errno.EACCES)
示例11: snapshot
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def snapshot(browser, quit_program=False, chart_only=True, name=''):
global MAX_SCREENSHOTS_ON_ERROR
if config.has_option('logging', 'screenshot_on_error') and config.getboolean('logging', 'screenshot_on_error') and MAX_SCREENSHOTS_ON_ERROR > 0:
MAX_SCREENSHOTS_ON_ERROR -= 1
filename = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') + '.png'
if name:
filename = '{}_{}'.format(str(name), filename)
if not os.path.exists('log'):
os.mkdir('log')
filename = os.path.join('log', filename)
try:
element = find_element(browser, 'html')
location = element.location
size = element.size
browser.save_screenshot(filename)
offset_left, offset_right, offset_top, offset_bottom = [0, 0, 0, 0]
if config.has_option('logging', 'screenshot_offset_left'):
offset_left = config.getint('logging', 'screenshot_offset_right')
if config.has_option('logging', 'screenshot_offset_right'):
offset_right = config.getint('logging', 'screenshot_offset_top')
if config.has_option('logging', 'screenshot_offset_top'):
offset_top = config.getint('logging', 'screenshot_offset_left')
if config.has_option('logging', 'screenshot_offset_bottom'):
offset_bottom = config.getint('logging', 'screenshot_offset_bottom')
x = location['x'] + offset_left
y = location['y'] + offset_top
width = location['x'] + size['width'] + offset_right
height = location['y'] + size['height'] + offset_bottom
im = Image.open(filename)
if chart_only:
im = im.crop((int(x), int(y), int(width), int(height)))
im.save(filename)
log.error(str(filename))
except Exception as take_screenshot_error:
log.exception(take_screenshot_error)
if quit_program:
write_console_log(browser)
exit(errno.EFAULT)
示例12: sys_getcwd
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
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
示例13: __call__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def __call__(self, op, *args):
if not hasattr(self, op):
raise FuseOSError(errno.EFAULT)
return getattr(self, op)(*args)
示例14: nl_syserr2nlerr
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
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))
示例15: sys_write
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EFAULT [as 别名]
def sys_write(self, fd: int, buf, count) -> int:
""" write - send bytes through a file descriptor
The write system call writes up to count bytes from the buffer pointed
to by buf to the file descriptor fd. If count is zero, write returns 0
and optionally sets *tx_bytes to zero.
:param fd a valid file descriptor
:param buf a memory buffer
:param count number of bytes to send
:return: 0 Success
EBADF fd is not a valid file descriptor or is not open.
EFAULT buf or tx_bytes points to an invalid address.
"""
data: bytes = bytes()
cpu = self.current
if count != 0:
try:
write_fd = self._get_fdlike(fd)
except FdError as e:
logger.error(
f"sys_write: Not valid file descriptor ({fd}). Returning -{errorcode(e.err)}"
)
return -e.err
# TODO check count bytes from buf
if buf not in cpu.memory or buf + count not in cpu.memory:
logger.debug("sys_write: buf points to invalid address. Returning -errno.EFAULT")
return -errno.EFAULT
if fd > 2 and write_fd.is_full():
cpu.PC -= cpu.instruction.size
self.wait([], [fd], None)
raise RestartSyscall()
data_sym: MixedSymbolicBuffer = cpu.read_bytes(buf, count)
data = self._transform_write_data(data_sym)
write_fd.write(data)
for line in data.split(b"\n"):
line_str = line.decode(
"latin-1"
) # latin-1 encoding will happily decode any byte (0x00-0xff)
logger.debug(f"sys_write({fd}, 0x{buf:08x}, {count}) -> <{repr(line_str):48s}>")
self.syscall_trace.append(("_write", fd, data))
self.signal_transmit(fd)
return len(data)