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

Python handlers.SimpleHandler类代码示例

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

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



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

示例1: close

 def close(self):
     try:
         self.request_handler.log_request(
             self.status.split(' ',1)[0], self.bytes_sent
         )
     finally:
         SimpleHandler.close(self)
开发者ID:grumpycoders,项目名称:Igor,代码行数:7,代码来源:simple_server.py


示例2: finish_response

    def finish_response(self):
        """
        Completes the response and performs the following tasks:

        - Remove the `'ws4py.socket'` and `'ws4py.websocket'`
          environ keys.
        - Attach the returned websocket, if any, to the WSGI server
          using its ``link_websocket_to_server`` method.
        """
        # force execution of the result iterator until first actual content
        rest = iter(self.result)
        first = list(itertools.islice(rest, 1))
        self.result = itertools.chain(first, rest)
        # now it's safe to look if environ was modified
        ws = None
        if self.environ:
            self.environ.pop('ws4py.socket', None)
            ws = self.environ.pop('ws4py.websocket', None)

        try:
            SimpleHandler.finish_response(self)
        except:
            if ws:
                ws.close(1011, reason='Something broke')
            raise
        else:
            if ws:
                self.request_handler.server.link_websocket_to_server(ws)
开发者ID:bozzzzo,项目名称:quark,代码行数:28,代码来源:quark_ws4py_fixup.py


示例3: close

    def close(self):
        # M:
        # S.split([sep [,maxsplit]]) -> list of strings
        # >>> status
        # '200 OK'
        # >>> status.split(' ', 0)
        # ['200 OK']
        # >>> status.split(' ', 1)
        # ['200', 'OK']
        # >>> status.split(' ', 2)
        # ['200', 'OK']


        # In WSGIRequestHandler.handle
        # handler.request_handler = self

        # WSGIRequestHandler.log_request 
        # -> BaseHTTPRequestHandler.log_request
        # -> BaseHTTPRequestHandler.log_message
        # -> sys.stderr.write


        # SimpleHandler.close
        # -> BaseHandler.close

        try:
            self.request_handler.log_request(
                self.status.split(' ',1)[0], self.bytes_sent
            )
        finally:
            SimpleHandler.close(self)
开发者ID:492852238,项目名称:SourceLearning,代码行数:31,代码来源:simple_server.py


示例4: testPartialWrite

    def testPartialWrite(self):
        written = bytearray()

        class PartialWriter:
            def write(self, b):
                partial = b[:7]
                written.extend(partial)
                return len(partial)

            def flush(self):
                pass

        environ = {"SERVER_PROTOCOL": "HTTP/1.0"}
        h = SimpleHandler(BytesIO(), PartialWriter(), sys.stderr, environ)
        msg = "should not do partial writes"
        with self.assertWarnsRegex(DeprecationWarning, msg):
            h.run(hello_app)
        self.assertEqual(
            b"HTTP/1.0 200 OK\r\n"
            b"Content-Type: text/plain\r\n"
            b"Date: Mon, 05 Jun 2006 18:49:54 GMT\r\n"
            b"Content-Length: 13\r\n"
            b"\r\n"
            b"Hello, world!",
            written,
        )
开发者ID:CabbageHead-360,项目名称:cpython,代码行数:26,代码来源:test_wsgiref.py


示例5: setup_environ

 def setup_environ(self):
     """
     Setup the environ dictionary and add the
     `'ws4py.socket'` key. Its associated value
     is the real socket underlying socket.
     """
     SimpleHandler.setup_environ(self)
     self.environ['ws4py.socket'] = self.environ['wsgi.input']._sock
开发者ID:Anderson-Juhasc,项目名称:bitex,代码行数:8,代码来源:wsgirefserver.py


示例6: setup_environ

 def setup_environ(self):
     """
     Setup the environ dictionary and add the
     `'ws4py.socket'` key. Its associated value
     is the real socket underlying socket.
     """
     SimpleHandler.setup_environ(self)
     self.environ['ws4py.socket'] = get_connection(self.environ['wsgi.input'])
     self.http_version = self.environ['SERVER_PROTOCOL'].rsplit('/')[-1]
开发者ID:bozzzzo,项目名称:quark,代码行数:9,代码来源:quark_ws4py_fixup.py


示例7: handle

	def handle(self):
		self.raw_requestline = self.rfile.readline()
		if not self.parse_request(): # An error code has been sent, just exit
			return

		handler = SimpleHandler(
			self.rfile, self.wfile, self.get_stderr(), self.get_environ()
		)
		handler.request_handler = self	  # backpointer for logging
		handler.run(self.server.get_app())
开发者ID:noname22,项目名称:Flog,代码行数:10,代码来源:WebServer.py


示例8: finish_response

    def finish_response(self):
        """
        Completes the response and performs the following tasks:

        - Remove the `'ws4py.socket'` and `'ws4py.websocket'`
          environ keys.
        - Attach the returned websocket, if any, to the WSGI server
          using its ``link_websocket_to_server`` method.
        """
        ws = None
        if self.environ:
            self.environ.pop('ws4py.socket', None)
            ws = self.environ.pop('ws4py.websocket', None)

        try:
            SimpleHandler.finish_response(self)
        except:
            if ws:
                ws.close(1011, reason='Something broke')
            raise
        else:
            if ws:
                self.request_handler.server.link_websocket_to_server(ws)
开发者ID:Anderson-Juhasc,项目名称:bitex,代码行数:23,代码来源:wsgirefserver.py


示例9: cleanup_headers

 def cleanup_headers(self):
     SimpleHandler.cleanup_headers(self)
     self.headers['Connection'] = 'Close'
开发者ID:fxfitz,项目名称:pytest-httpbin,代码行数:3,代码来源:serve.py


示例10: wsgi_server

def wsgi_server(application, conn):
    '''WSGI handler based on the Python wsgiref SimpleHandler.

    A WSGI application should return a iterable op StringTypes.
    Any encoding must be handled by the WSGI application itself.
    '''

    # TODO - this wsgi handler executes the application and renders a page in
    # memory completely before returning it as a response to the client.
    # Thus, it does not "stream" the result back to the client. It should be
    # possible though. The SimpleHandler accepts file-like stream objects. So,
    # it should be just a matter of connecting 0MQ requests/response streams
    # to the SimpleHandler requests and response streams. However, the Python
    # API for Mongrel2 doesn't seem to support file-like stream objects for
    # requests and responses. Unless I have missed something.

    # setup connection handler
    # sender_id is automatically generated
    # so that each handler instance is uniquely identified

    while True:
        debug("WAITING FOR REQUEST")

        # receive a request
        req = conn.recv()
        if DEBUG:
            debug("REQUEST HEADERS: %r\n" % req.headers)
            debug("REQUEST BODY: %r\n" % req.body)

        if req.is_disconnect():
            print("DISCONNECT")
            continue  # effectively ignore the disconnect from the client

        # json parsing gives us unicode instead of ascii.
        headers = dict((key.encode('ascii'), value.encode('ascii'))
                       for (key, value) in req.headers.items())

        env = {}

        add_request_metavariables(env, headers)
        add_http_variables(env, headers)

        debug("ENVIRON: %r\n" % env)

        # SimpleHandler needs file-like stream objects for
        # requests, errors and reponses
        reqIO = StringIO(req.body)
        errIO = StringIO()
        respIO = StringIO()

        # execute the application
        simple_handler = SimpleHandler(reqIO, respIO, errIO, env,
                                       multithread=False,
                                       multiprocess=False)
        simple_handler.run(application)

        response = respIO.getvalue()
        errors = errIO.getvalue()

        # return the response
        debug("RESPONSE: %r\n" % response)
        if errors:
            debug("ERRORS: %r" % errors)

        conn.reply(req, response)

        # Check if we should close the connection.

        respIO.seek(0)

        protocol = respIO.readline()[:8]
        msg = httplib.HTTPMessage(respIO, 0)
        http_1p1 = protocol == 'HTTP/1.1'

        conn_close = http_1p1 and msg.getheader("Connection") == "close"
        keep_alive = http_1p1 or msg.getheader("Connection") == "Keep-Alive"
        if conn_close or not keep_alive:
            debug("EXPLICITLY CLOSING CONNECTION")
            conn.reply(req, "")
开发者ID:passy,项目名称:mongrel2_wsgi,代码行数:79,代码来源:server.py


示例11: __init__

 def __init__(self, stdin, stdout, stderr):
     base_environ = dict(os.environ.items())
     base_environ['SERVER_PROTOCOL'] = 'HTTP/1.0'
     SimpleHandler.__init__(self, stdin, stdout, stderr, base_environ,
                            multithread=False, multiprocess=True)
开发者ID:saebyn,项目名称:trapeze-wsgi,代码行数:5,代码来源:TrapezeWSGI.py


示例12: handle_wsgi_request

	def handle_wsgi_request(stdin, stdout, stderr, environ):
		handler = SimpleHandler(stdin.buffer, stdout.buffer, stderr, environ.vars, environ.server.multithread, environ.server.multiprocess)
		handler.run_once = not environ.server.multiconnection
		handler.server_software = environ.server.software
		handler.run(app)
开发者ID:LEW21,项目名称:reserve,代码行数:5,代码来源:wsgi.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python headers.Headers类代码示例发布时间:2022-05-26
下一篇:
Python handlers.BaseCGIHandler类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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