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


Python errno.ENOPROTOOPT属性代码示例

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


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

示例1: test_ignore_other_errors

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def test_ignore_other_errors(self):
    inet4_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
    inet6_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
    self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
    self.mox.StubOutWithMock(socket, 'getaddrinfo')
    socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
                       socket.AI_PASSIVE).AndReturn(
                           [(None, None, None, None, ('127.0.0.1', 0, 'baz')),
                            (None, None, None, None, ('::1', 0, 'baz'))])
    wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0), None).AndReturn(
        inet4_server)
    inet4_server.start()
    inet4_server.port = 123
    wsgi_server._SingleAddressWsgiServer(('::1', 123), None).AndReturn(
        inet6_server)
    inet6_server.start().AndRaise(
        wsgi_server.BindError('message', (errno.ENOPROTOOPT, 'no protocol')))
    self.mox.ReplayAll()
    self.server.start()
    self.mox.VerifyAll()
    self.assertItemsEqual([inet4_server],
                          self.server._servers) 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:wsgi_server_test.py

示例2: _testOption

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def _testOption(self, level, option, values):
        for flag, func in [
            (self.test_udp,        self._testUDPOption),
            (self.test_tcp_server, self._testTCPServerOption),
            (self.test_tcp_client, self._testTCPClientOption),
        ]:
            if flag:
                func(level, option, values)
            else:
                try:
                    func(level, option, values)
                except socket.error, se:
                    self.failUnlessEqual(se[0], errno.ENOPROTOOPT, "Wrong errno from unsupported option exception: %d" % se[0])
                except Exception, x:
                    self.fail("Wrong exception raised from unsupported option: %s" % str(x))
                else:
                    self.fail("Setting unsupported option should have raised an exception") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:19,代码来源:test_socket.py

示例3: getsockopt

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def getsockopt(self, level, optname, buflen=None):
        # Pseudo options for interrogating the status of this socket
        if level == SOL_SOCKET:
            if optname == SO_ACCEPTCONN:
                if self.socket_type == SERVER_SOCKET:
                    return 1
                elif self.type == SOCK_STREAM:
                    return 0
                else:
                    raise error(errno.ENOPROTOOPT, "Protocol not available")
            if optname == SO_TYPE:
                return self.type
            if optname == SO_ERROR:
                last_error = self._last_error
                self._last_error = 0
                return last_error

        # Normal options
        try:
            option, _ = _socket_options[self.proto][(level, optname)]
        except KeyError:
            raise error(errno.ENOPROTOOPT, "Protocol not available")
        log.debug("Shadow option settings %s", self.options, extra={"sock": self})
        return self.options.get(option, 0) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:26,代码来源:_socket.py

示例4: _testOption

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def _testOption(self, level, option, values):
        for flag, func in [
            (self.test_udp,        self._testUDPOption),
            (self.test_tcp_client, self._testTCPClientOption),
            (self.test_tcp_server, self._testTCPServerOption),
        ]:
            if flag:
                func(level, option, values)
            else:
                try:
                    func(level, option, values)
                except socket.error, se:
                    self.failUnlessEqual(se[0], errno.ENOPROTOOPT, "Wrong errno from unsupported option exception: %d" % se[0])
                except Exception, x:
                    self.fail("Wrong exception raised from unsupported option: %s" % str(x))
                else:
                    self.fail("Setting unsupported option should have raised an exception") 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:19,代码来源:test_socket.py

示例5: _init_sock

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def _init_sock(self):
        if self.unix_socket:
            # try remove the sock file it already exists
            _sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            try:
                _sock.connect(self.unix_socket)
            except (socket.error, OSError) as err:
                if err.args[0] == errno.ECONNREFUSED:
                    os.unlink(self.unix_socket)
        else:
            _sock = socket.socket(self.socket_family, socket.SOCK_STREAM)

        _sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if hasattr(socket, "SO_REUSEPORT"):
            try:
                _sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
            except socket.error as err:
                if err[0] in (errno.ENOPROTOOPT, errno.EINVAL):
                    pass
                else:
                    raise
        _sock.settimeout(None)
        self.sock = _sock 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:25,代码来源:socket.py

示例6: _init_sock

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def _init_sock(self):
        if self.unix_socket:
            # try remove the sock file it already exists
            _sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            try:
                _sock.connect(self.unix_socket)
            except (socket.error, OSError) as err:
                if err.args[0] == errno.ECONNREFUSED:
                    os.unlink(self.unix_socket)
        else:
            _sock = socket.socket(self.socket_family, socket.SOCK_STREAM)

        _sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if hasattr(socket, "SO_REUSEPORT"):
            try:
                _sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
            except socket.error as err:
                if err[0] in (errno.ENOPROTOOPT, errno.EINVAL):
                    pass
                else:
                    raise
        _sock.settimeout(None)
        self.raw_sock = _sock 
开发者ID:Thriftpy,项目名称:thriftpy2,代码行数:25,代码来源:socket.py

示例7: bind_unix_socket

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def bind_unix_socket(
        file: str, mode: int = 0o600, backlog: int = _DEFAULT_BACKLOG
    ) -> socket.socket:
        """Creates a listening unix socket.

        If a socket with the given name already exists, it will be deleted.
        If any other file with that name exists, an exception will be
        raised.

        Returns a socket object (not a list of socket objects like
        `bind_sockets`)
        """
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        set_close_exec(sock.fileno())
        try:
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        except socket.error as e:
            if errno_from_exception(e) != errno.ENOPROTOOPT:
                # Hurd doesn't support SO_REUSEADDR
                raise
        sock.setblocking(False)
        try:
            st = os.stat(file)
        except OSError as err:
            if errno_from_exception(err) != errno.ENOENT:
                raise
        else:
            if stat.S_ISSOCK(st.st_mode):
                os.remove(file)
            else:
                raise ValueError("File %s exists and is not a socket", file)
        sock.bind(file)
        os.chmod(file, mode)
        sock.listen(backlog)
        return sock 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:37,代码来源:netutil.py

示例8: _handle_connect

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def _handle_connect(self) -> None:
        try:
            err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        except socket.error as e:
            # Hurd doesn't allow SO_ERROR for loopback sockets because all
            # errors for such sockets are reported synchronously.
            if errno_from_exception(e) == errno.ENOPROTOOPT:
                err = 0
        if err != 0:
            self.error = socket.error(err, os.strerror(err))
            # IOLoop implementations may vary: some of them return
            # an error state before the socket becomes writable, so
            # in that case a connection failure would be handled by the
            # error path in _handle_events instead of here.
            if self._connect_future is None:
                gen_log.warning(
                    "Connect error on fd %s: %s",
                    self.socket.fileno(),
                    errno.errorcode[err],
                )
            self.close()
            return
        if self._connect_future is not None:
            future = self._connect_future
            self._connect_future = None
            future_set_result_unless_cancelled(future, self)
        self._connecting = False 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:29,代码来源:iostream.py

示例9: createInternetSocket

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def createInternetSocket(self):
        skt = Port.createInternetSocket(self)
        if self.listenMultiple:
            skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            if hasattr(socket, "SO_REUSEPORT"):
                try:
                    skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
                except socket.error as le:
                    # RHEL6 defines SO_REUSEPORT but it doesn't work
                    if le.errno == ENOPROTOOPT:
                        pass
                    else:
                        raise
        return skt 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:udp.py

示例10: bind_unix_socket

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def bind_unix_socket(file, mode=0o600, backlog=_DEFAULT_BACKLOG):
        """Creates a listening unix socket.

        If a socket with the given name already exists, it will be deleted.
        If any other file with that name exists, an exception will be
        raised.

        Returns a socket object (not a list of socket objects like
        `bind_sockets`)
        """
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        set_close_exec(sock.fileno())
        try:
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        except socket.error as e:
            if errno_from_exception(e) != errno.ENOPROTOOPT:
                # Hurd doesn't support SO_REUSEADDR
                raise
        sock.setblocking(0)
        try:
            st = os.stat(file)
        except OSError as err:
            if errno_from_exception(err) != errno.ENOENT:
                raise
        else:
            if stat.S_ISSOCK(st.st_mode):
                os.remove(file)
            else:
                raise ValueError("File %s exists and is not a socket", file)
        sock.bind(file)
        os.chmod(file, mode)
        sock.listen(backlog)
        return sock 
开发者ID:tp4a,项目名称:teleport,代码行数:35,代码来源:netutil.py

示例11: _handle_connect

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def _handle_connect(self):
        try:
            err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        except socket.error as e:
            # Hurd doesn't allow SO_ERROR for loopback sockets because all
            # errors for such sockets are reported synchronously.
            if errno_from_exception(e) == errno.ENOPROTOOPT:
                err = 0
        if err != 0:
            self.error = socket.error(err, os.strerror(err))
            # IOLoop implementations may vary: some of them return
            # an error state before the socket becomes writable, so
            # in that case a connection failure would be handled by the
            # error path in _handle_events instead of here.
            if self._connect_future is None:
                gen_log.warning("Connect error on fd %s: %s",
                                self.socket.fileno(), errno.errorcode[err])
            self.close()
            return
        if self._connect_callback is not None:
            callback = self._connect_callback
            self._connect_callback = None
            self._run_callback(callback)
        if self._connect_future is not None:
            future = self._connect_future
            self._connect_future = None
            future.set_result(self)
        self._connecting = False 
开发者ID:tp4a,项目名称:teleport,代码行数:30,代码来源:iostream.py

示例12: _is_listening

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def _is_listening(self):
        import errno
        import socket
        try:
            is_listening = self._s.getsockopt(socket.SOL_SOCKET, socket.SO_ACCEPTCONN)
        except socket.error as se:
            # OSX and BSDs do not support ENOPROTOOPT. Linux and Windows seem to
            if se.errno == errno.ENOPROTOOPT:
                raise RuntimeError("OS does not support SO_ACCEPTCONN, cannot determine socket state. Please supply an"
                                   "explicit client value (True for client, False for server)")
            else:
                raise
        return True if is_listening != 0 else False 
开发者ID:tintinweb,项目名称:scapy-ssl_tls,代码行数:15,代码来源:ssl_tls.py

示例13: run

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def run(self):
		self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
		if hasattr(socket, "SO_REUSEPORT"):
			try:
				self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
			except socket.error as le:
				# RHEL6 defines SO_REUSEPORT but it doesn't work
				if le.errno == ENOPROTOOPT:
					pass
				else:
					raise

		addr = socket.inet_aton(SSDP_ADDR)
		interface = socket.inet_aton('0.0.0.0')
		cmd = socket.IP_ADD_MEMBERSHIP
		self.sock.setsockopt(socket.IPPROTO_IP, cmd, addr + interface)
		self.sock.bind(('0.0.0.0', SSDP_PORT))
		self.sock.settimeout(1)

		while True:
			try:
				data, addr = self.sock.recvfrom(1024)
				self.datagram_received(data, addr)
			except socket.timeout:
				continue
		self.shutdown() 
开发者ID:OpenViX,项目名称:HRTunerProxy,代码行数:29,代码来源:ssdp.py

示例14: nl_syserr2nlerr

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

示例15: getsockopt

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOPROTOOPT [as 别名]
def getsockopt(self, level, option):
        if (level, option) in self.options:
            result = getattr(self.jsocket, "get%s" % self.options[ (level, option) ])()
            if option == SO_LINGER:
                if result == -1:
                    enabled, linger_time = 0, 0
                else:
                    enabled, linger_time = 1, result
                return struct.pack('ii', enabled, linger_time)
            return result
        else:
            raise error(errno.ENOPROTOOPT, "Socket option '%s' (level '%s') not supported on socket(%s)" % (_constant_to_name(option), _constant_to_name(level), str(self.jsocket))) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:14,代码来源:socket.py


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