本文整理汇总了Python中wheezy.http.HTTPResponse.write方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.write方法的具体用法?Python HTTPResponse.write怎么用?Python HTTPResponse.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wheezy.http.HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def post(self):
try:
form = self.request.form
code = form["code"][0]
except:
return bad_request_with_detail("No data posted, or data in incorrect format")
params = {"grant_type": "authorization_code", "redirect_uri": config.SPOTIFY_CALLBACK_URL, "code": code}
token_response = requests.post(config.SPOTIFY_TOKEN_ENDPOINT, data=params, headers=auth_header, verify=True)
response = HTTPResponse()
response.content_type = "application/json"
response.status_code = token_response.status_code
if token_response.status_code == 200:
json_response = token_response.json()
refresh_token = json_response["refresh_token"]
encrypted_token = crypt.encrypt(refresh_token)
json_response["refresh_token"] = encrypted_token
response_body = json.dumps(json_response)
response.write(response_body)
else:
response.write_bytes(token_response.content)
return response
示例2: upload
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def upload(request):
#print 'form:', request.form
#print 'uploaded:', request.files
response = HTTPResponse()
# check data integrity:
if request.files.get('data') and request.form.get('crc'):
storage = request.files.get('data')[0] # raw object
crc = request.form.get('crc')[0] # crc for compressed content
if str(zlib.crc32(storage.value)) == crc: # check integrity
# return file save result
content = zlib.decompress(storage.value)
# write to file here
savefile = storage.filename if storage.filename else (datetime.now().strftime('%Y%m%d%H%M%S') + str(random.randint(0,100)) + '.html')
fout = open(os.path.join(conf.get('upload_dir'), savefile), 'w')
fout.write(content)
fout.close()
response.write(conf.get('upload_url_prefix') + savefile)
else:
return bad_request()
else:
# bad request
return bad_request()
return response
示例3: get
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def get(self):
fortunes = db_session.query(Fortune).all()
fortunes.append(Fortune(id=0, message="Additional fortune added at request time."))
fortunes.sort(key=attrgetter("message"))
template = template_engine.get_template("fortune.html")
template_html = template.render({"fortunes": fortunes})
response = HTTPResponse()
response.write(template_html)
return response
示例4: get
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def get(self):
fortunes = db_session.query(Fortune).all()
fortunes.append(Fortune(id=0, message="Additional fortune added at request time."))
fortunes.sort(key=attrgetter("message"))
engine = Engine(loader=FileLoader(["views"]), extensions=[CoreExtension()])
template = engine.get_template("fortune.html")
for f in fortunes:
f.message = bleach.clean(f.message)
template_html = template.render({"fortunes": fortunes})
response = HTTPResponse()
response.write(template_html)
return response
示例5: post
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def post(self):
"""
Handle HTTP POST.
"""
method = self.get_method()
body = self.get_body()
# TODO handle method exception.
result = method(**body)
payload = self.encoder.encode(result)
response = HTTPResponse(content_type="application/json")
response.status_code = 200
response.write(payload)
return response
示例6: get
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def get(self):
con = session()
repo = Repository(con)
CONTENT_TYPE_XML='text/xml'
CONTENT_TYPE_XML_RSP=CONTENT_TYPE_XML+'; charset=utf-8'
if DEBUG:
base_url = 'http://192.168.72.100:8080'
else:
base_url = 'http://shoboi.net'
feed = feedgenerator.Atom1Feed(
title = 'しょぼいろだ。',
link = 'http://shobi.net/',
feed_url = 'http://shoboi.net/atom',
description = u'エロも笑いも虹も惨事もしょぼいろだで共有してね',
author_name=u'しょぼい。',
language = u"ja",
pubdate = datetime.utcnow()
)
upimages = repo.list_upimages()
for idx, i in enumerate(upimages):
feed.add_item(
title = i.title or 'タイトルなし',
link = '%s/detail/%s' % (base_url, i.id),
description = """<![CDATA[
<a href="%s/detail/%s">
<img src="%s/img/%s">
</a>
]]>""" % (base_url, i.id, base_url, i.thumb),
author_name = i.author or '名無し',
pubdate = datetime.now()
)
if idx >= 4: # 5件まで
break;
response = HTTPResponse()
content_type = ('Content-Type', CONTENT_TYPE_XML_RSP)
response.headers[0] = content_type
response.write(feed.writeString('utf-8'))
response.cache_dependency = ('d_atom', )
return response
示例7: wrap_request
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def wrap_request(self, request, *args, **kwargs):
'''
Prepares data and pass control to `restea.Resource` object
:returns: :class: `wheezy.http.HTTPResponse`
'''
data_format, kwargs = self._get_format_name(kwargs)
formatter = formats.get_formatter(data_format)
resource = self._resource_class(
WheezyRequestWrapper(request), formatter
)
res, status_code, content_type = resource.dispatch(*args, **kwargs)
response = HTTPResponse(
content_type=content_type,
)
response.write(res)
response.status_code = status_code
return response
示例8: get
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def get(self):
response = HTTPResponse()
response.write('Hello World!')
return response
示例9: get
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def get(self):
response = HTTPResponse()
response.headers = [(CONTENT_TYPE, CONTENT_TYPE_PLAIN)]
response.write(response_cached())
return response
示例10: requestJson
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def requestJson():
response = HTTPResponse()
response.write(responseJson())
return response
示例11: get
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def get(self):
response = HTTPResponse()
response.write('Hello World! It is %s.' %
datetime.now().time().strftime('%H:%M:%S'))
return response
示例12: welcome
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def welcome(request):
response = HTTPResponse()
response.write('Server is up!')
return response
示例13: plaintext
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def plaintext(request):
response = HTTPResponse()
response.headers = [("Content-Type", "text/plain; charset=UTF-8")]
response.write("Hello, world!")
return response
示例14: request_html
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def request_html(request):
response = HTTPResponse()
response.headers = [(CONTENT_TYPE, CONTENT_TYPE_HTML)]
response.write(response_html())
return response
示例15: request_json
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write [as 别名]
def request_json(request):
response = HTTPResponse()
response.headers = [(CONTENT_TYPE, CONTENT_TYPE_JSON)]
response.write(response_json())
return response