本文整理汇总了Python中werkzeug.http方法的典型用法代码示例。如果您正苦于以下问题:Python werkzeug.http方法的具体用法?Python werkzeug.http怎么用?Python werkzeug.http使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug
的用法示例。
在下文中一共展示了werkzeug.http方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deserialize
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import http [as 别名]
def deserialize(expected_content_types=None):
if expected_content_types is None:
expected_content_types = ("application/json", )
mime_type, options = werkzeug.http.parse_options_header(
pecan.request.headers.get('Content-Type'))
if mime_type not in expected_content_types:
abort(415)
try:
params = json.load(pecan.request.body_file)
except Exception as e:
details = rest_exceptions.UnableToDecodeBody(e,
pecan.request.body_file)
LOG.warning(details.jsonify())
abort(400, details)
return params
示例2: get_current_user
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import http [as 别名]
def get_current_user(request):
auth = werkzeug.http.parse_authorization_header(
request.headers.get("Authorization"))
if auth is None:
api.abort(401)
return auth.username
示例3: abort
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import http [as 别名]
def abort(status_code, detail=''):
"""Like pecan.abort, but make sure detail is a string."""
if status_code == 404 and not detail:
raise RuntimeError("http code 404 must have 'detail' set")
if isinstance(detail, voluptuous.Invalid):
detail = {
'cause': 'Invalid input',
'reason': six.text_type(detail),
'detail': [six.text_type(path) for path in detail.path],
}
elif isinstance(detail, Exception):
detail = detail.jsonify()
LOG.debug("Aborting request. Code [%s]. Details [%s]", status_code, detail)
return pecan.abort(status_code, detail)
示例4: set_resp_location_hdr
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import http [as 别名]
def set_resp_location_hdr(location):
location = '%s%s' % (pecan.request.script_name, location)
# NOTE(sileht): according the pep-3333 the headers must be
# str in py2 and py3 even this is not the same thing in both
# version
# see: http://legacy.python.org/dev/peps/pep-3333/#unicode-issues
if six.PY2 and isinstance(location, six.text_type):
location = location.encode('utf-8')
location = urllib_parse.quote(location)
pecan.response.headers['Location'] = location
示例5: __init__
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import http [as 别名]
def __init__(self, valid_methods=None, description=None):
"""Takes an optional list of valid http methods
starting with werkzeug 0.3 the list will be mandatory."""
HTTPException.__init__(self, description)
self.valid_methods = valid_methods
示例6: _get_basic_authenticator
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import http [as 别名]
def _get_basic_authenticator(req):
auth = werkzeug.http.parse_authorization_header(
req.headers.get("Authorization"))
return auth
示例7: test_old_imports
# 需要导入模块: import werkzeug [as 别名]
# 或者: from werkzeug import http [as 别名]
def test_old_imports(self):
from werkzeug.utils import Headers, MultiDict, CombinedMultiDict, \
Headers, EnvironHeaders
from werkzeug.http import Accept, MIMEAccept, CharsetAccept, \
LanguageAccept, ETags, HeaderSet, WWWAuthenticate, \
Authorization