我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用werkzeug.http()。
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
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
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
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, Exception): detail = detail.jsonify() return pecan.abort(status_code, detail)
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
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: abort(400, "Unable to decode body: " + six.text_type(e)) return params
def get_header_option(name, params): type, options = werkzeug.http.parse_options_header( pecan.request.headers.get('Accept')) return strtobool('Accept header' if name in options else name, options.get(name, params.get(name, 'false')))