本文整理汇总了Python中errno.ENXIO属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ENXIO属性的具体用法?Python errno.ENXIO怎么用?Python errno.ENXIO使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.ENXIO属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transmitPacket
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def transmitPacket(self, sock, srcMac, destMac, ipHeaderLength, ipPacket):
ipHeader = ipPacket[:ipHeaderLength]
udpHeader = ipPacket[ipHeaderLength:ipHeaderLength+8]
data = ipPacket[ipHeaderLength+8:]
dontFragment = ipPacket[6]
if type(dontFragment) == str:
dontFragment = ord(dontFragment)
dontFragment = (dontFragment & 0x40) >> 6
udpHeader = self.computeUDPChecksum(ipHeader, udpHeader, data)
for boundary in range(0, len(data), self.udpMaxLength):
dataFragment = data[boundary:boundary+self.udpMaxLength]
totalLength = len(ipHeader) + len(udpHeader) + len(dataFragment)
moreFragments = boundary+self.udpMaxLength < len(data)
flagsOffset = boundary & 0x1fff
if moreFragments:
flagsOffset |= 0x2000
elif dontFragment:
flagsOffset |= 0x4000
ipHeader = ipHeader[:2]+struct.pack('!H', totalLength)+ipHeader[4:6]+struct.pack('!H', flagsOffset)+ipHeader[8:]
ipPacket = self.computeIPChecksum(ipHeader + udpHeader + dataFragment, ipHeaderLength)
try:
if srcMac != binascii.unhexlify('00:00:00:00:00:00'.replace(':', '')):
etherPacket = destMac + srcMac + self.etherType + ipPacket
sock.send(etherPacket)
else:
sock.send(ipPacket)
except Exception as e:
if e.errno == errno.ENXIO:
raise
else:
self.logger.info('Error sending packet: %s' % str(e))
示例2: if_indextoname
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def if_indextoname(ifindex):
libc.if_indextoname.argtypes = [ctypes.c_uint32, ctypes.c_char_p]
libc.if_indextoname.restype = ctypes.c_char_p
ifname = ctypes.create_string_buffer(16)
ifname = libc.if_indextoname(ifindex, ifname)
if not ifname:
err = errno.ENXIO
raise OSError(err, os.strerror(err))
return ifname
示例3: pty_make_controlling_tty
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def pty_make_controlling_tty(tty_fd):
'''This makes the pseudo-terminal the controlling tty. This should be
more portable than the pty.fork() function. Specifically, this should
work on Solaris. '''
child_name = os.ttyname(tty_fd)
# Disconnect from controlling tty, if any. Raises OSError of ENXIO
# if there was no controlling tty to begin with, such as when
# executed by a cron(1) job.
try:
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
os.close(fd)
except OSError as err:
if err.errno != errno.ENXIO:
raise
os.setsid()
# Verify we are disconnected from controlling tty by attempting to open
# it again. We expect that OSError of ENXIO should always be raised.
try:
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
os.close(fd)
raise PtyProcessError("OSError of errno.ENXIO should be raised.")
except OSError as err:
if err.errno != errno.ENXIO:
raise
# Verify we can open child pty.
fd = os.open(child_name, os.O_RDWR)
os.close(fd)
# Verify we now have a controlling tty.
fd = os.open("/dev/tty", os.O_WRONLY)
os.close(fd)
示例4: pty_make_controlling_tty
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def pty_make_controlling_tty(tty_fd):
'''This makes the pseudo-terminal the controlling tty. This should be
more portable than the pty.fork() function. Specifically, this should
work on Solaris. '''
child_name = os.ttyname(tty_fd)
# Disconnect from controlling tty, if any. Raises OSError of ENXIO
# if there was no controlling tty to begin with, such as when
# executed by a cron(1) job.
try:
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
os.close(fd)
except OSError as err:
if err.errno != errno.ENXIO:
raise
os.setsid()
# Verify we are disconnected from controlling tty by attempting to open
# it again. We expect that OSError of ENXIO should always be raised.
try:
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
os.close(fd)
raise ExceptionPexpect("OSError of errno.ENXIO should be raised.")
except OSError as err:
if err.errno != errno.ENXIO:
raise
# Verify we can open child pty.
fd = os.open(child_name, os.O_RDWR)
os.close(fd)
# Verify we now have a controlling tty.
fd = os.open("/dev/tty", os.O_WRONLY)
os.close(fd)
示例5: get_private_keys
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def get_private_keys():
"""Find SSH keys in standard folder."""
key_formats = [RSAKey, ECDSAKey, Ed25519Key]
ssh_folder = os.path.expanduser('~/.ssh')
available_private_keys = []
if os.path.isdir(ssh_folder):
for key in os.listdir(ssh_folder):
key_file = os.path.join(ssh_folder, key)
if not os.path.isfile(key_file):
continue
for key_format in key_formats:
try:
parsed_key = key_format.from_private_key_file(key_file)
key_details = {
'filename': key,
'format': parsed_key.get_name(),
'bits': parsed_key.get_bits(),
'fingerprint': parsed_key.get_fingerprint().hex()
}
available_private_keys.append(key_details)
except (SSHException, UnicodeDecodeError, IsADirectoryError, IndexError):
continue
except OSError as e:
if e.errno == errno.ENXIO:
# when key_file is a (ControlPath) socket
continue
else:
raise
return available_private_keys
示例6: __pty_make_controlling_tty
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def __pty_make_controlling_tty(self, tty_fd):
'''This makes the pseudo-terminal the controlling tty. This should be
more portable than the pty.fork() function. Specifically, this should
work on Solaris. '''
child_name = os.ttyname(tty_fd)
# Disconnect from controlling tty, if any. Raises OSError of ENXIO
# if there was no controlling tty to begin with, such as when
# executed by a cron(1) job.
try:
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
os.close(fd)
except OSError as err:
if err.errno != errno.ENXIO:
raise
os.setsid()
# Verify we are disconnected from controlling tty by attempting to open
# it again. We expect that OSError of ENXIO should always be raised.
try:
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
os.close(fd)
raise ExceptionPexpect("OSError of errno.ENXIO should be raised.")
except OSError as err:
if err.errno != errno.ENXIO:
raise
# Verify we can open child pty.
fd = os.open(child_name, os.O_RDWR)
os.close(fd)
# Verify we now have a controlling tty.
fd = os.open("/dev/tty", os.O_WRONLY)
os.close(fd)
示例7: open
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def open(self, flags):
if self._fd is None:
if not os.path.exists(self.path):
raise Exception('Input pipe does not exist: %s' % self._path)
if not stat.S_ISFIFO(os.stat(self.path).st_mode):
raise Exception('Input pipe must be a fifo object: %s' % self._path)
try:
self._fd = os.open(self.path, flags)
except OSError as e:
if e.errno != errno.ENXIO:
raise e
示例8: test_max_reached
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def test_max_reached(self, openpty):
openpty.side_effect = OSError(errno.ENXIO)
e = self.assertRaises(mitogen.core.StreamError,
lambda: self.func())
msg = mitogen.parent.OPENPTY_MSG % (openpty.side_effect,)
self.assertEquals(e.args[0], msg)
示例9: _connect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENXIO [as 别名]
def _connect(self) -> None:
"""
Connnect to the peer node.
:return: None
"""
if self._connection_attempts == 1:
with open(self.log_file, "r") as f:
logger.debug("Couldn't connect to libp2p p2p process, logs:")
logger.debug(f.read())
raise Exception("Couldn't connect to libp2p p2p process")
# TOFIX(LR) use proper exception
self._connection_attempts -= 1
logger.debug(
"Attempt opening pipes {}, {}...".format(
self.libp2p_to_aea_path, self.aea_to_libp2p_path
)
)
self._libp2p_to_aea = os.open(
self.libp2p_to_aea_path, os.O_RDONLY | os.O_NONBLOCK
)
try:
self._aea_to_libp2p = os.open(
self.aea_to_libp2p_path, os.O_WRONLY | os.O_NONBLOCK
)
except OSError as e:
if e.errno == errno.ENXIO:
await asyncio.sleep(2)
await self._connect()
return
else:
raise e
# setup reader
assert (
self._libp2p_to_aea != -1
and self._aea_to_libp2p != -1
and self._loop is not None
), "Incomplete initialization."
self._stream_reader = asyncio.StreamReader(loop=self._loop)
self._reader_protocol = asyncio.StreamReaderProtocol(
self._stream_reader, loop=self._loop
)
self._fileobj = os.fdopen(self._libp2p_to_aea, "r")
await self._loop.connect_read_pipe(lambda: self._reader_protocol, self._fileobj)
logger.info("Successfully connected to libp2p node!")
self.multiaddrs = self.get_libp2p_node_multiaddrs()
logger.info("My libp2p addresses: {}".format(self.multiaddrs))