Python OpenSSL.SSL 模块,ConnectionType() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用OpenSSL.SSL.ConnectionType()

项目:download-manager    作者:thispc    | 项目源码 | 文件源码
def __init__(self, sock, wsgi_app, environ):
        self.socket = sock
        self.wsgi_app = wsgi_app

        # Copy the class environ into self.
        self.environ = self.environ.copy()
        self.environ.update(environ)

        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            self.rfile = SSL_fileobject(sock, "rb", self.rbufsize)
            self.rfile.ssl_timeout = timeout
            self.wfile = SSL_fileobject(sock, "wb", -1)
            self.wfile.ssl_timeout = timeout
        else:
            self.rfile = CP_fileobject(sock, "rb", self.rbufsize)
            self.wfile = CP_fileobject(sock, "wb", -1)

        # Wrap wsgi.input but not HTTPConnection.rfile itself.
        # We're also not setting maxlen yet; we'll do that separately
        # for headers and body for each iteration of self.communicate
        # (if maxlen is 0 the wrapper doesn't check length).
        self.environ["wsgi.input"] = SizeCheckWrapper(self.rfile, 0)
项目:birdnet    作者:cyysu    | 项目源码 | 文件源码
def __init__(self, sock, wsgi_app, environ):
        self.socket = sock
        self.wsgi_app = wsgi_app

        # Copy the class environ into self.
        self.environ = self.environ.copy()
        self.environ.update(environ)

        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            self.rfile = SSL_fileobject(sock, "rb", self.rbufsize)
            self.rfile.ssl_timeout = timeout
            self.wfile = SSL_fileobject(sock, "wb", -1)
            self.wfile.ssl_timeout = timeout
        else:
            self.rfile = CP_fileobject(sock, "rb", self.rbufsize)
            self.wfile = CP_fileobject(sock, "wb", -1)

        # Wrap wsgi.input but not HTTPConnection.rfile itself.
        # We're also not setting maxlen yet; we'll do that separately
        # for headers and body for each iteration of self.communicate
        # (if maxlen is 0 the wrapper doesn't check length).
        self.environ["wsgi.input"] = SizeCheckWrapper(self.rfile, 0)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def test_type(self):
        """
        L{Connection} and L{ConnectionType} refer to the same type object and
        can be used to create instances of that type.
        """
        self.assertIdentical(Connection, ConnectionType)
        ctx = Context(TLSv1_METHOD)
        self.assertConsistentType(Connection, 'Connection', ctx, None)
项目:SalesforceXyTools    作者:exiahuang    | 项目源码 | 文件源码
def makefile(self, sock, mode='r', bufsize=-1):
        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            f = SSL_fileobject(sock, mode, bufsize)
            f.ssl_timeout = timeout
            return f
        else:
            return wsgiserver.CP_fileobject(sock, mode, bufsize)
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def makefile(self, sock, mode='r', bufsize=-1):
        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            f = SSL_fileobject(sock, mode, bufsize)
            f.ssl_timeout = timeout
            return f
        else:
            return wsgiserver.CP_fileobject(sock, mode, bufsize)
项目:download-manager    作者:thispc    | 项目源码 | 文件源码
def stop(self, timeout=5):
        # Must shut down threads here so the code that calls
        # this method can know when all threads are stopped.
        for worker in self._threads:
            self._queue.put(_SHUTDOWNREQUEST)

        # Don't join currentThread (when stop is called inside a request).
        current = threading.currentThread()
        while self._threads:
            worker = self._threads.pop()
            if worker is not current and worker.isAlive():
                try:
                    if timeout is None or timeout < 0:
                        worker.join()
                    else:
                        worker.join(timeout)
                        if worker.isAlive():
                            # We exhausted the timeout.
                            # Forcibly shut down the socket.
                            c = worker.conn
                            if c and not c.rfile.closed:
                                if SSL and isinstance(c.socket, SSL.ConnectionType):
                                    # pyOpenSSL.socket.shutdown takes no args
                                    c.socket.shutdown()
                                else:
                                    c.socket.shutdown(socket.SHUT_RD)
                            worker.join()
                except (AssertionError,
                        # Ignore repeated Ctrl-C.
                        # See http://www.cherrypy.org/ticket/691.
                        KeyboardInterrupt), exc1:
                    pass
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def test_type(self):
        """
        L{Connection} and L{ConnectionType} refer to the same type object and
        can be used to create instances of that type.
        """
        self.assertIdentical(Connection, ConnectionType)
        ctx = Context(TLSv1_METHOD)
        self.assertConsistentType(Connection, 'Connection', ctx, None)
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def makefile(self, sock, mode='r', bufsize=-1):
        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            f = SSL_fileobject(sock, mode, bufsize)
            f.ssl_timeout = timeout
            return f
        else:
            return wsgiserver.CP_fileobject(sock, mode, bufsize)
项目:CloudPrint    作者:William-An    | 项目源码 | 文件源码
def makefile(self, sock, mode='r', bufsize=-1):
        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            f = SSL_fileobject(sock, mode, bufsize)
            f.ssl_timeout = timeout
            return f
        else:
            return wsgiserver.CP_fileobject(sock, mode, bufsize)
项目:py-script    作者:xiaoxiamin    | 项目源码 | 文件源码
def makefile(self, sock, mode='r', bufsize=-1):
        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            f = SSL_fileobject(sock, mode, bufsize)
            f.ssl_timeout = timeout
            return f
        else:
            return wsgiserver.CP_fileobject(sock, mode, bufsize)
项目:py-script    作者:xiaoxiamin    | 项目源码 | 文件源码
def makefile(self, sock, mode='r', bufsize=-1):
        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            f = SSL_fileobject(sock, mode, bufsize)
            f.ssl_timeout = timeout
            return f
        else:
            return wsgiserver.CP_fileobject(sock, mode, bufsize)
项目:lantern-detection    作者:gongxijun    | 项目源码 | 文件源码
def __init__(self, sock, addr, server):
        self.socket = sock
        self.addr = addr
        self.server = server

        # Copy the class environ into self.
        self.environ = self.environ.copy()

        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            self.rfile = SSL_fileobject(sock, "r", self.rbufsize)
            self.rfile.ssl_timeout = timeout
            self.sendall = _ssl_wrap_method(sock.sendall)
            self.environ["wsgi.url_scheme"] = "https"
            self.environ["HTTPS"] = "on"
            sslenv = getattr(server, "ssl_environ", None)
            if sslenv:
                self.environ.update(sslenv)
        else:
            self.rfile = sock.makefile("r", self.rbufsize)
            self.sendall = sock.sendall

        self.environ.update({"wsgi.input": self.rfile,
                             "SERVER_NAME": self.server.server_name,
                             })

        if isinstance(self.server.bind_addr, basestring):
            # AF_UNIX. This isn't really allowed by WSGI, which doesn't
            # address unix domain sockets. But it's better than nothing.
            self.environ["SERVER_PORT"] = ""
        else:
            self.environ["SERVER_PORT"] = str(self.server.bind_addr[1])
            # optional values
            # Until we do DNS lookups, omit REMOTE_HOST
            self.environ["REMOTE_ADDR"] = self.addr[0]
            self.environ["REMOTE_PORT"] = str(self.addr[1])
项目:lantern-detection    作者:gongxijun    | 项目源码 | 文件源码
def __init__(self, sock, addr, server):
        self.socket = sock
        self.addr = addr
        self.server = server

        # Copy the class environ into self.
        self.environ = self.environ.copy()

        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            self.rfile = SSL_fileobject(sock, "r", self.rbufsize)
            self.rfile.ssl_timeout = timeout
            self.sendall = _ssl_wrap_method(sock.sendall)
            self.environ["wsgi.url_scheme"] = "https"
            self.environ["HTTPS"] = "on"
            sslenv = getattr(server, "ssl_environ", None)
            if sslenv:
                self.environ.update(sslenv)
        else:
            self.rfile = sock.makefile("r", self.rbufsize)
            self.sendall = sock.sendall

        self.environ.update({"wsgi.input": self.rfile,
                             "SERVER_NAME": self.server.server_name,
                             })

        if isinstance(self.server.bind_addr, basestring):
            # AF_UNIX. This isn't really allowed by WSGI, which doesn't
            # address unix domain sockets. But it's better than nothing.
            self.environ["SERVER_PORT"] = ""
        else:
            self.environ["SERVER_PORT"] = str(self.server.bind_addr[1])
            # optional values
            # Until we do DNS lookups, omit REMOTE_HOST
            self.environ["REMOTE_ADDR"] = self.addr[0]
            self.environ["REMOTE_PORT"] = str(self.addr[1])
项目:cosa-nostra    作者:joxeankoret    | 项目源码 | 文件源码
def makefile(self, sock, mode='r', bufsize=-1):
        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            f = SSL_fileobject(sock, mode, bufsize)
            f.ssl_timeout = timeout
            return f
        else:
            return wsgiserver.CP_fileobject(sock, mode, bufsize)
项目:birdnet    作者:cyysu    | 项目源码 | 文件源码
def stop(self, timeout=5):
        # Must shut down threads here so the code that calls
        # this method can know when all threads are stopped.
        for worker in self._threads:
            self._queue.put(_SHUTDOWNREQUEST)

        # Don't join currentThread (when stop is called inside a request).
        current = threading.currentThread()
        while self._threads:
            worker = self._threads.pop()
            if worker is not current and worker.isAlive():
                try:
                    if timeout is None or timeout < 0:
                        worker.join()
                    else:
                        worker.join(timeout)
                        if worker.isAlive():
                            # We exhausted the timeout.
                            # Forcibly shut down the socket.
                            c = worker.conn
                            if c and not c.rfile.closed:
                                if SSL and isinstance(c.socket, SSL.ConnectionType):
                                    # pyOpenSSL.socket.shutdown takes no args
                                    c.socket.shutdown()
                                else:
                                    c.socket.shutdown(socket.SHUT_RD)
                            worker.join()
                except (AssertionError,
                        # Ignore repeated Ctrl-C.
                        # See http://www.cherrypy.org/ticket/691.
                        KeyboardInterrupt), exc1:
                    pass
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def test_type(self):
        """
        L{Connection} and L{ConnectionType} refer to the same type object and
        can be used to create instances of that type.
        """
        self.assertIdentical(Connection, ConnectionType)
        ctx = Context(TLSv1_METHOD)
        self.assertConsistentType(Connection, 'Connection', ctx, None)
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def makefile(self, sock, mode='r', bufsize=-1):
        if SSL and isinstance(sock, SSL.ConnectionType):
            timeout = sock.gettimeout()
            f = SSL_fileobject(sock, mode, bufsize)
            f.ssl_timeout = timeout
            return f
        else:
            return wsgiserver.CP_fileobject(sock, mode, bufsize)