本文整理汇总了Python中flask.Request.data方法的典型用法代码示例。如果您正苦于以下问题:Python Request.data方法的具体用法?Python Request.data怎么用?Python Request.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.Request
的用法示例。
在下文中一共展示了Request.data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import data [as 别名]
def __call__(self, addr):
'''Since an instance of HttpServer is passed to the Service
class (with appropriate request_handler established during
initialization), this __call__ method is what's actually
invoked by diesel.
'''
data = None
while True:
try:
h = HttpParser()
body = []
while True:
if data:
used = h.execute(data, len(data))
if h.is_headers_complete():
body.append(h.recv_body())
if h.is_message_complete():
data = data[used:]
break
data = receive()
env = h.get_wsgi_environ()
if 'HTTP_CONTENT_LENGTH' in env:
env['CONTENT_LENGTH'] = env.pop("HTTP_CONTENT_LENGTH")
if 'HTTP_CONTENT_TYPE' in env:
env['CONTENT_TYPE'] = env.pop("HTTP_CONTENT_TYPE")
env.update({
'wsgi.version' : (1,0),
'wsgi.url_scheme' : 'http', # XXX incomplete
'wsgi.input' : cStringIO.StringIO(''.join(body)),
'wsgi.errors' : FileLikeErrorLogger(hlog),
'wsgi.multithread' : False,
'wsgi.multiprocess' : False,
'wsgi.run_once' : False,
'REMOTE_ADDR' : addr[0],
'SERVER_NAME' : HOSTNAME,
'SERVER_PORT': str(self.port),
})
req = Request(env)
if req.headers.get('Connection', '').lower() == 'upgrade':
req.data = data
resp = self.request_handler(req)
if 'Server' not in resp.headers:
resp.headers.add('Server', SERVER_TAG)
if 'Date' not in resp.headers:
resp.headers.add('Date', utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC"))
assert resp, "HTTP request handler _must_ return a response"
self.send_response(resp, version=h.get_version())
if (not h.should_keep_alive()) or \
resp.headers.get('Connection', '').lower() == "close" or \
resp.headers.get('Content-Length') == None:
return
# Switching Protocols
if resp.status_code == 101 and hasattr(resp, 'new_protocol'):
resp.new_protocol(req)
break
except ConnectionClosed:
break
示例2: __call__
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import data [as 别名]
def __call__(self, addr):
"""Since an instance of HttpServer is passed to the Service
class (with appropriate request_handler established during
initialization), this __call__ method is what's actually
invoked by diesel.
"""
data = None
while True:
try:
h = HttpParser()
body = []
while True:
if data:
used = h.execute(data, len(data))
if h.is_headers_complete():
body.append(h.recv_body())
if h.is_message_complete():
data = data[used:]
break
data = receive()
env = h.get_wsgi_environ()
if "HTTP_CONTENT_LENGTH" in env:
env["CONTENT_LENGTH"] = env.pop("HTTP_CONTENT_LENGTH")
if "HTTP_CONTENT_TYPE" in env:
env["CONTENT_TYPE"] = env.pop("HTTP_CONTENT_TYPE")
env.update(
{
"wsgi.version": (1, 0),
"wsgi.url_scheme": "http", # XXX incomplete
"wsgi.input": cStringIO.StringIO("".join(body)),
"wsgi.errors": FileLikeErrorLogger(hlog),
"wsgi.multithread": False,
"wsgi.multiprocess": False,
"wsgi.run_once": False,
"REMOTE_ADDR": addr[0],
"SERVER_NAME": HOSTNAME,
"SERVER_PORT": str(self.port),
}
)
req = Request(env)
if req.headers.get("Connection", "").lower() == "upgrade":
req.data = data
resp = self.request_handler(req)
if "Server" not in resp.headers:
resp.headers.add("Server", SERVER_TAG)
if "Date" not in resp.headers:
resp.headers.add("Date", utcnow().strftime("%a, %d %b %Y %H:%M:%S UTC"))
assert resp, "HTTP request handler _must_ return a response"
self.send_response(resp, version=h.get_version())
if (
(not h.should_keep_alive())
or resp.headers.get("Connection", "").lower() == "close"
or resp.headers.get("Content-Length") == None
):
return
except ConnectionClosed:
break