• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python socketserver.BaseServer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中socketserver.BaseServer的典型用法代码示例。如果您正苦于以下问题:Python BaseServer类的具体用法?Python BaseServer怎么用?Python BaseServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: handle_error

  def handle_error( self, request, client_address ):
    # Override default behaviour of error handler in ThreadingMixIn
    # the default handler prints and error message to stdout and stderr.
    # Instead, this re-raises the exception so that it can be caught and 
    # dealt with sensibly!

    print("handle_error!");
    exc_type, exc_value, exc_traceback = sys.exc_info();
    #if exc_type == SSL.Error and exc_value[0][0][2]=='http request':
    print(exc_type);
    print(exc_value);
    print(exc_traceback);
    print("OpenSLL error detected!");

      # We would like to send back a BadRequest to the web-client indicating
      # that they made an http request to this https server (like apache does).
      # But this response message must be sent via http (not https), but this 
      # server's __init__ function sets up an SSL server, so this seems
      # difficult to to.
      # It might be possible to make a mixed server than can serve both types
      # of requests, but this is left for later.

    # Fall back to original error handler.
    # Print: exc_type, exc_value, exc_traceback.
    BaseServer.handle_error( self, request, client_address );
开发者ID:WimbledonLabs,项目名称:sous-vide-cooker,代码行数:25,代码来源:SnakeCharmer.py


示例2: __init__

	def __init__(self, server_address, RequestHandlerClass, maxthreads=100, pemfile=None, rest_handlers=None, userpass=None):
		try:
			if pemfile: #HTTPS server
				BaseServer.__init__(self, server_address, RequestHandlerClass)
				ctx = SSL.Context(SSL.SSLv23_METHOD)
				ctx.use_privatekey_file(pemfile)
				ctx.use_certificate_file(pemfile)
				self.socket = SSL.Connection(ctx, socket.socket(self.address_family, self.socket_type))
				self.server_bind()
				self.server_activate()
				self.httpstyle = "HTTPS"
			else: #HTTP server
				BaseHTTPServer.__init__(self, server_address, RequestHandlerClass)
				self.httpstyle = "HTTP"
		except socket.error as e:
			if e.errno == 98:
				logging.log(logging.ERROR, "Cannot start HTTP server, address already in use")
				return
			else:
				raise
		self.lock = thread.allocate_lock()
		self.maxthreads = maxthreads
		self.threads = 0
		self.rest_handlers = rest_handlers
		self.userpass = userpass
开发者ID:saggim,项目名称:SleekPubsub,代码行数:25,代码来源:httpd.py


示例3: __init__

 def __init__(self, server_address, HandlerClass):
     BaseServer.__init__(self, server_address, HandlerClass)
     ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
     ctx.load_cert_chain(certfile=CERT, keyfile=KEY)
     self.socket = ctx.wrap_socket(socket.socket(self.address_family, self.socket_type), server_side=True)
     self.server_bind()
     self.server_activate()
开发者ID:Sud0h4c,项目名称:pentest,代码行数:7,代码来源:simple_https_server.py


示例4: __init__

 def __init__(self, server_address, RequestHandlerClass, bind_and_activate=True):
     BaseServer.__init__(self, server_address, RequestHandlerClass)
     self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
                                   "./server.key", "./server.crt", True, ssl.CERT_REQUIRED,
                                   ssl.PROTOCOL_TLSv1, "./trusted.crt")
     
     if bind_and_activate:
         self.server_bind()
         self.server_activate()
开发者ID:matematik7,项目名称:CChatServer,代码行数:9,代码来源:server.py


示例5: __init__

 def __init__(self, server_address, HandlerClass):
     BaseServer.__init__(self, server_address, HandlerClass)
     self.socket = ssl.SSLSocket(
         sock=socket.socket(self.address_family, self.socket_type),
         ssl_version=ssl.PROTOCOL_TLSv1,
         certfile='server.pem',
         server_side=True)
     self.server_bind()
     self.server_activate()
开发者ID:notbryant,项目名称:eyebrows,代码行数:9,代码来源:eyebrows.py


示例6: __init__

 def __init__(self, server_address, multicast_group, RequestHandlerClass, bind_and_activate=True, multicast_ttl = 1):
     BaseServer.__init__(self, server_address, RequestHandlerClass)
     self.socket = socket.socket(self.address_family,
                                 self.socket_type,
                                 self.protocol_type)
     self.multicast_group = multicast_group
     self.multicast_ttl = multicast_ttl
     if bind_and_activate:
         self.server_bind()
         self.server_activate()
开发者ID:rasp-home,项目名称:rasp-home-backend,代码行数:10,代码来源:zeroconf_server.py


示例7: __init__

    def __init__(self,address,handler):
        BaseServer.__init__(self,address,handler)

        self.socket = ssl.SSLSocket(
            sock=socket.socket(self.address_family,self.socket_type),
            ssl_version=ssl.PROTOCOL_TLSv1,
            certfile=os.path.join(os.path.dirname(__file__), 'test.pem'),
            server_side=True)
        self.server_bind()
        self.server_activate()
开发者ID:dragon788,项目名称:zorro,代码行数:10,代码来源:test_https.py


示例8: __init__

    def __init__(self, server_address, HandlerClass):
        BaseServer.__init__(self, server_address, HandlerClass)
        ctx = SSL.Context(SSL.SSLv23_METHOD)

        fpem = MongoServer.pem
        ctx.use_privatekey_file(fpem)
        ctx.use_certificate_file(fpem)
        
        self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
                                                        self.socket_type))
        self.server_bind()
        self.server_activate()
开发者ID:edosoft,项目名称:sleepy.mongoose,代码行数:12,代码来源:httpd.py


示例9: __init__

 def __init__(self, address, handler):
     """
     Initialise the secure handlers for the SSL server if required.s
     """
     BaseServer.__init__(self, address, handler)
     local_data = AppLocation.get_directory(AppLocation.DataDir)
     self.socket = ssl.SSLSocket(
         sock=socket.socket(self.address_family, self.socket_type),
         certfile=os.path.join(local_data, 'remotes', 'openlp.crt'),
         keyfile=os.path.join(local_data, 'remotes', 'openlp.key'),
         server_side=True)
     self.server_bind()
     self.server_activate()
开发者ID:imkernel,项目名称:openlp,代码行数:13,代码来源:httpserver.py


示例10: __init__

 def __init__(self, server_address, HandlerClass):
     BaseServer.__init__(self, server_address, HandlerClass)
     ctx = SSL.Context(SSL.SSLv23_METHOD)
     # server.pem's location (containing the server private key and
     # the server certificate).
     fpem_priv = 'newreq.pem'  # server
     fpem_cli = 'newcert.pem'  # cli
     ctx.use_privatekey_file(fpem_priv)
     ctx.use_certificate_file(fpem_cli)
     self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
                                                     self.socket_type))
     self.server_bind()
     self.server_activate()
开发者ID:1872892142,项目名称:social-engineer-toolkit,代码行数:13,代码来源:PoC_SSL.py


示例11: __init__

 def __init__(self, server_address, HandlerClass):
     BaseServer.__init__(self, server_address, HandlerClass)
     
     ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
     
     fpem = '../cacert.crt'
     ctx.load_verify_locations(fpem)
     ctx.verify_mode = ssl.CERT_NONE
     
     self.socket = ssl.SSLSocket(ctx, socket.socket(self.address_family,
                                                    self.socket_type),
                                 certfile = fpem)
     self.server_bind()
     self.server_activate()
开发者ID:ejamesc,项目名称:openbox,代码行数:14,代码来源:httpstest.py


示例12: __init__

 def __init__ (self, address, handler):
       BaseServer.__init__ (self, address, handler)
       print (os.getcwd())
       CERTFILE = os.path.abspath (os.path.join ('..', 'certs', 'wget-cert.pem'))
       print (CERTFILE)
       fop = open (CERTFILE)
       print (fop.readline())
       self.socket = ssl.wrap_socket (
             sock = socket.socket (self.address_family, self.socket_type),
             ssl_version = ssl.PROTOCOL_TLSv1,
             certfile = CERTFILE,
             server_side = True
             )
       self.server_bind ()
       self.server_activate ()
开发者ID:Devil399,项目名称:wget,代码行数:15,代码来源:http_server.py


示例13: __init__

 def __init__ (self, address, handler):
     import ssl
     BaseServer.__init__ (self, address, handler)
     # step one up because test suite change directory away from $srcdir (don't do that !!!)
     CERTFILE = os.path.abspath(os.path.join('..', os.getenv('srcdir', '.'), 'certs', 'wget-cert.pem'))
     fop = open (CERTFILE)
     print (fop.readline())
     self.socket = ssl.wrap_socket (
         sock = socket.socket (self.address_family, self.socket_type),
         ssl_version = ssl.PROTOCOL_TLSv1,
         certfile = CERTFILE,
         server_side = True
     )
     self.server_bind()
     self.server_activate()
开发者ID:andrewhead,项目名称:StackSkim,代码行数:15,代码来源:http_server.py


示例14: __init__

 def __init__(self, server_address, HandlerClass):
     BaseServer.__init__(self, server_address, HandlerClass)
     # SSLv2 and SSLv3 supported
     ctx = SSL.Context(SSL.SSLv23_METHOD)
     # pem files defined before
     fpem_priv = 'newreq.pem'
     fpem_cli = 'newcert.pem'
     # establish private key
     ctx.use_privatekey_file(fpem_priv)
     # establish public/client certificate
     ctx.use_certificate_file(fpem_cli)
     # setup the ssl socket
     self.socket = SSL.Connection(ctx, socket.socket(
         self.address_family, self.socket_type))
     # bind to interface
     self.server_bind()
     # activate the interface
     self.server_activate()
开发者ID:onlydole,项目名称:social-engineer-toolkit,代码行数:18,代码来源:harvester.py


示例15: __init__

    	def __init__(self, server_address, HandlerClass, options):
            BaseServer.__init__(self, server_address, HandlerClass)
            pwd = os.path.dirname(os.path.realpath(__file__))
            keys = os.path.join(pwd,options.key)
            certs = os.path.join(pwd,options.cert)
            self.options = options

            self.daemon_threads = True
            self.protocol_version = 'HTTP/1.1'
            if options.clientverify:
            	self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
                    keyfile=keys, certfile=certs, server_side=True, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/etc/ssl/certs/ca-certificates.crt')
            else:
                self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
                    keyfile=keys, certfile=certs, server_side=True)

            self.server_bind()
            self.server_activate()
开发者ID:chenglongwei,项目名称:trafficserver,代码行数:18,代码来源:uWServer.py


示例16: __init__

    def __init__(self, address, handler):
        global logger
        try:
            BaseServer.__init__(self, address, handler)
            self.socket = ssl.SSLSocket(
                sock=socket.socket(self.address_family, self.socket_type),
                ssl_version=ssl.PROTOCOL_TLSv1,
                certfile=settings.ServerParams["Certificate"],
                server_side=True)
            self.server_bind()
            self.server_activate()
            #   create http logger
            logger = logging.getLogger('HTTP')
            logger.setLevel(settings.SystemParams["LogLevel"])
            logger.addHandler(log.ch)

            logger.info('HTTPS server started. Press ^C to stop')
        except Exception as err:
            Logger.error('Error during HTTPS server starting')
开发者ID:appdevel,项目名称:webserver,代码行数:19,代码来源:httpserver.py


示例17: __init__

 def __init__(self, address, handler):
     import ssl
     BaseServer.__init__(self, address, handler)
     # step one up because test suite change directory away from $srcdir
     # (don't do that !!!)
     CERTFILE = os.path.abspath(os.path.join('..',
                                             os.getenv('srcdir', '.'),
                                             'certs',
                                             'server-cert.pem'))
     KEYFILE = os.path.abspath(os.path.join('..',
                                            os.getenv('srcdir', '.'),
                                            'certs',
                                            'server-key.pem'))
     self.socket = ssl.wrap_socket(
         sock=socket.socket(self.address_family, self.socket_type),
         certfile=CERTFILE,
         keyfile=KEYFILE,
         server_side=True
     )
     self.server_bind()
     self.server_activate()
开发者ID:mirror,项目名称:wget,代码行数:21,代码来源:http_server.py


示例18: __init__

  def __init__(self, server_address, HandlerClass):

    BaseServer.__init__(self, server_address, HandlerClass);


    fpem = SnakeCharmer_config.fpem;

    http_socket = socket.socket( self.address_family, self.socket_type);

    print( fpem );
    self.socket = ssl.wrap_socket( 
      http_socket,
      server_side=True,
      certfile=fpem,
      cert_reqs=ssl.CERT_NONE,
      ssl_version=ssl.PROTOCOL_SSLv23,
      do_handshake_on_connect=False
    );

    self.server_bind();
    self.server_activate();
开发者ID:WimbledonLabs,项目名称:sous-vide-cooker,代码行数:21,代码来源:SnakeCharmer.py


示例19: __init__

 def __init__(self, server_address, RequestHandlerClass):
     BaseServer.__init__(self, server_address, RequestHandlerClass)
     self.server_bind()
开发者ID:524777134,项目名称:cpython,代码行数:3,代码来源:test_wsgiref.py


示例20: __init__

    def __init__(self, ip, port, keyFile=DEFAULTKEYFILE, certFile=DEFAULTCERTFILE, logRequests=True):
        self.logRequests = logRequests
        class VerifyingRequestHandler(SimpleXMLRPCRequestHandler):

            def setup(myself):
                myself.connection = myself.request
                myself.rfile = socket.socket.makefile(myself.request, "rb", myself.rbufsize)
                myself.wfile = socket.socket.makefile(myself.request, "wb", myself.wbufsize)

            def address_string(myself):
                "getting 'FQDN' from host seems to stall on some ip addresses, so... just (quickly!) return raw host address"
                host, port = myself.client_address
                #return socket.getfqdn(host)
                return host

            def do_POST(myself):
                """Handles the HTTPS POST request.
                It was copied out from SimpleXMLRPCServer.py and modified to shutdown the socket cleanly.
                """
                try:
                    # get arguments
                    data = myself.rfile.read(int(myself.headers["content-length"]))
                    # In previous versions of SimpleXMLRPCServer, _dispatch
                    # could be overridden in this class, instead of in
                    # SimpleXMLRPCDispatcher. To maintain backwards compatibility,
                    # check to see if a subclass implements _dispatch and dispatch
                    # using that method if present.
                    response = myself.server._marshaled_dispatch(data, getattr(myself, '_dispatch', None))
                except Exception as info: # This should only happen if the module is buggy
                    print ("ERROR do_POST: ", info)
                    print ("Traceback follows:", traceback.print_exc())

                    # internal error, report as HTTP server error
                    myself.send_response(500)
                    myself.end_headers()
                else:
                    # got a valid XML RPC response
                    myself.send_response(200)
                    myself.send_header("Content-type", "text/xml")
                    myself.send_header("Content-length", str(len(response)))
                    myself.end_headers()
                    myself.wfile.write(response)

                    # shut down the connection
                    myself.wfile.flush()
                    myself.connection.shutdown() # Modified here!

            def do_GET(myself):
                """Handles the HTTP GET request.

                Interpret all HTTP GET requests as requests for server
                documentation.
                """
                # Check that the path is legal
                if not myself.is_rpc_path_valid():
                    myself.report_404()
                    return

                response = myself.server.generate_html_documentation()
                myself.send_response(200)
                myself.send_header("Content-type", "text/html")
                myself.send_header("Content-length", str(len(response)))
                myself.end_headers()
                myself.wfile.write(response)

                # shut down the connection
                myself.wfile.flush()
                myself.connection.shutdown() # Modified here!

            def report_404(myself):
                # Report a 404 error
                myself.send_response(404)
                response = 'No such page'
                myself.send_header("Content-type", "text/plain")
                myself.send_header("Content-length", str(len(response)))
                myself.end_headers()
                myself.wfile.write(response)
                # shut down the connection
                myself.wfile.flush()
                myself.connection.shutdown() # Modified here!

            def parse_request(myself):
                if SimpleXMLRPCRequestHandler.parse_request(myself):
                    basic, foo, encoded = myself.headers.get('Authorization').partition(' ')
                    username, foo, password = b64decode(encoded).decode('UTF-8').partition(':')
                    if username == 'admin':
                        return True
                    else:
                        myself.send_error(401, 'Authentication failed')
                        return False
        SimpleXMLRPCDispatcher.__init__(self, False, None)
        BaseServer.__init__(self, (ip, port), VerifyingRequestHandler)

        # SSL socket stuff
        ctx = SSL.Context(SSL.SSLv23_METHOD)
        ctx.use_privatekey_file(keyFile)
        ctx.use_certificate_file(certFile)
        self.socket = SSL.Connection(ctx, socket.socket(self.address_family, self.socket_type))
        self.server_bind()
        self.server_activate()
#.........这里部分代码省略.........
开发者ID:etopian,项目名称:python3-xmlrpc-ssl-basic-auth,代码行数:101,代码来源:sslserver.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python socketserver.TCPServer类代码示例发布时间:2022-05-27
下一篇:
Python server.SocketIOServer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap