当前位置: 首页>>代码示例>>Python>>正文


Python errno.ENOTSOCK属性代码示例

本文整理汇总了Python中errno.ENOTSOCK属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ENOTSOCK属性的具体用法?Python errno.ENOTSOCK怎么用?Python errno.ENOTSOCK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在errno的用法示例。


在下文中一共展示了errno.ENOTSOCK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sendto

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def sendto(self, socket, message, dest, flags):
        if not isinstance(socket, tco.TransmissionControlObject):
            raise err.Error(errno.ENOTSOCK)
        if isinstance(socket, tco.RawAccessPoint):
            if not isinstance(message, pdu.ProtocolDataUnit):
                raise TypeError("on a raw access point message must be a pdu")
            if not socket.is_bound:
                self.bind(socket)
            # FIXME: set socket send miu when activated
            socket.send_miu = self.cfg['send-miu']
            return socket.send(message, flags)
        if not isinstance(message, (bytes, bytearray)):
            raise TypeError("message data must be a bytes-like object")
        if isinstance(socket, tco.LogicalDataLink):
            if dest is None:
                raise err.Error(errno.EDESTADDRREQ)
            if not socket.is_bound:
                self.bind(socket)
            # FIXME: set socket send miu when activated
            socket.send_miu = self.cfg['send-miu']
            return socket.sendto(message, dest, flags)
        if isinstance(socket, tco.DataLinkConnection):
            return socket.send(message, flags) 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:25,代码来源:llc.py

示例2: test_listen

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def test_listen(self, llc, ldl, dlc, bind):
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.listen(object(), 0)
            assert excinfo.value.errno == errno.ENOTSOCK
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.listen(ldl, 0)
            assert excinfo.value.errno == errno.EOPNOTSUPP
            with pytest.raises(TypeError) as excinfo:
                llc.listen(dlc, 0.1)
            assert str(excinfo.value) == "backlog must be int type"
            with pytest.raises(ValueError) as excinfo:
                llc.listen(dlc, -1)
            assert str(excinfo.value) == "backlog can not be negative"
            if bind:
                llc.bind(dlc)
            llc.listen(dlc, 0)
            assert dlc.state.LISTEN is True 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:19,代码来源:test_llcp_llc.py

示例3: test_accept_connect

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def test_accept_connect(self, llc, ldl, dlc, peer_miu, send_miu):
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.accept(object())
            assert excinfo.value.errno == errno.ENOTSOCK
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.accept(ldl)
            assert excinfo.value.errno == errno.EOPNOTSUPP
            with pytest.raises(nfc.llcp.Error) as excinfo:
                llc.accept(dlc)
            assert excinfo.value.errno == errno.EINVAL
            connect_pdu = nfc.llcp.pdu.Connect(4, 32, peer_miu)
            threading.Timer(0.01, llc.dispatch, (connect_pdu,)).start()
            llc.bind(dlc, b'urn:nfc:sn:snep')
            llc.listen(dlc, 0)
            sock = llc.accept(dlc)
            assert isinstance(sock, nfc.llcp.tco.DataLinkConnection)
            assert llc.getsockopt(sock, nfc.llcp.SO_SNDMIU) == send_miu
            assert llc.getpeername(sock) == 32
            assert llc.getsockname(sock) == 4 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:21,代码来源:test_llcp_llc.py

示例4: send

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def send(self, sendbuf=None):
        '''Flush the send buffer.'''
        self.acquire_lock()
        try:
            if not self.sock:
                e = socket.error(
                    '[errno %d] Socket operation on non-socket' % errno.ENOTSOCK)
                e.errno = errno.ENOTSOCK
                raise e
            try:
                if sendbuf is None:
                    if self.sendbuf:
                        self.sock.sendall(self.sendbuf)
                    self.sendbuf = b''
                elif sendbuf:
                    self.sock.sendall(sendbuf)
            except socket.error as e:
                try:
                    self.sock.close()
                finally:
                    self.sock = None
                raise
                self.quit('Network error.', wait=False)
        finally:
            self.lock.release() 
开发者ID:gumblex,项目名称:tg-irc-relay,代码行数:27,代码来源:libirc.py

示例5: sys_recv

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [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) 
开发者ID:trailofbits,项目名称:manticore,代码行数:22,代码来源:linux.py

示例6: is_socket

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def is_socket(fd):
    """ Determine if the file descriptor is a socket.

        Return ``False`` if querying the socket type of `fd` raises an
        error; otherwise return ``True``.

        """
    result = False

    file_socket = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW)

    try:
        socket_type = file_socket.getsockopt(
            socket.SOL_SOCKET, socket.SO_TYPE)
    except socket.error, exc:
        exc_errno = exc.args[0]
        if exc_errno == errno.ENOTSOCK:
            # Socket operation on non-socket
            pass
        else:
            # Some other socket error
            result = True 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:daemon.py

示例7: _is_socket

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def _is_socket(cls, stream):
        """Check if the given stream is a socket."""
        try:
            fd = stream.fileno()
        except ValueError:
            # If it has no file descriptor, it's not a socket
            return False

        sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW)
        try:
            # This will raise a socket.error if it's not a socket
            sock.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
        except socket.error as ex:
            if ex.args[0] != errno.ENOTSOCK:
                # It must be a socket
                return True
        else:
            # If an exception wasn't raised, it's a socket
            return True 
开发者ID:jnrbsn,项目名称:daemonocle,代码行数:21,代码来源:core.py

示例8: _setupSocket

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def _setupSocket(self):
        if self._bindAddress is None: # Run as a normal FastCGI?
            isFCGI = True

            sock = socket.fromfd(FCGI_LISTENSOCK_FILENO, socket.AF_INET,
                                 socket.SOCK_STREAM)
            try:
                sock.getpeername()
            except socket.error, e:
                if e[0] == errno.ENOTSOCK:
                    # Not a socket, assume CGI context.
                    isFCGI = False
                elif e[0] != errno.ENOTCONN:
                    raise

            # FastCGI/CGI discrimination is broken on Mac OS X.
            # Set the environment variable FCGI_FORCE_CGI to "Y" or "y"
            # if you want to run your app as a simple CGI. (You can do
            # this with Apache's mod_env [not loaded by default in OS X
            # client, ha ha] and the SetEnv directive.)
            if not isFCGI or \
               os.environ.get('FCGI_FORCE_CGI', 'N').upper().startswith('Y'):
                req = self.cgirequest_class(self)
                req.run()
                sys.exit(0) 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:27,代码来源:fcgi.py

示例9: _getselectable

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def _getselectable(selectable_object):
    try:
        channel = selectable_object.getchannel()
    except:
        try:
            channel = selectable_object.fileno().getChannel()
        except:
            raise TypeError("Object '%s' is not watchable" % selectable_object,
                            errno.ENOTSOCK)
    
    if channel and not isinstance(channel, java.nio.channels.SelectableChannel):
        raise TypeError("Object '%s' is not watchable" % selectable_object,
                        errno.ENOTSOCK)
    return channel 
开发者ID:war-and-code,项目名称:jawfish,代码行数:16,代码来源:select.py

示例10: _zmq_catch_error

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def _zmq_catch_error(name):
    try:
        yield
    except zmq.ContextTerminated:
        logger.info("[{}] Context terminated.".format(name))
        raise DataFlowTerminated()
    except zmq.ZMQError as e:
        if e.errno == errno.ENOTSOCK:       # socket closed
            logger.info("[{}] Socket closed.".format(name))
            raise DataFlowTerminated()
        else:
            raise
    except Exception:
        raise 
开发者ID:tensorpack,项目名称:dataflow,代码行数:16,代码来源:parallel.py

示例11: setsockopt

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def setsockopt(self, socket, option, value):
        if not isinstance(socket, tco.TransmissionControlObject):
            raise err.Error(errno.ENOTSOCK)
        if option == nfc.llcp.SO_RCVMIU:
            value = min(value, self.cfg['recv-miu'])
        socket.setsockopt(option, value)
        return socket.getsockopt(option) 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:9,代码来源:llc.py

示例12: getsockopt

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def getsockopt(self, socket, option):
        if not isinstance(socket, tco.TransmissionControlObject):
            raise err.Error(errno.ENOTSOCK)
        if isinstance(socket, tco.LogicalDataLink):
            # FIXME: set socket send miu when activated
            socket.send_miu = self.cfg['send-miu']
        if isinstance(socket, tco.RawAccessPoint):
            # FIXME: set socket send miu when activated
            socket.send_miu = self.cfg['send-miu']
        return socket.getsockopt(option) 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:12,代码来源:llc.py

示例13: bind

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [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) 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:17,代码来源:llc.py

示例14: connect

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def connect(self, socket, dest):
        if not isinstance(socket, tco.TransmissionControlObject):
            raise err.Error(errno.ENOTSOCK)
        if not socket.is_bound:
            self.bind(socket)
        socket.connect(dest)
        log.debug("connected ({0} ===> {1})".format(socket.addr, socket.peer))
        if socket.send_miu > self.cfg['send-miu']:
            log.warning("reducing outbound miu to not exceed the link miu")
            socket.send_miu = self.cfg['send-miu'] 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:12,代码来源:llc.py

示例15: listen

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTSOCK [as 别名]
def listen(self, socket, backlog):
        if not isinstance(socket, tco.TransmissionControlObject):
            raise err.Error(errno.ENOTSOCK)
        if not isinstance(socket, tco.DataLinkConnection):
            raise err.Error(errno.EOPNOTSUPP)
        if not isinstance(backlog, int):
            raise TypeError("backlog must be int type")
        if backlog < 0:
            raise ValueError("backlog can not be negative")
        backlog = min(backlog, 16)
        if not socket.is_bound:
            self.bind(socket)
        socket.listen(backlog) 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:15,代码来源:llc.py


注:本文中的errno.ENOTSOCK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。