當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。