本文整理匯總了Python中werkzeug.http.parse_options_header方法的典型用法代碼示例。如果您正苦於以下問題:Python http.parse_options_header方法的具體用法?Python http.parse_options_header怎麽用?Python http.parse_options_header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.http
的用法示例。
在下文中一共展示了http.parse_options_header方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_link_header
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def parse_link_header(link_header):
href, options = parse_options_header(link_header)
assert href.startswith('<')
assert href.endswith('>')
assert list(options.keys()) == ['rel']
return href[1:-1], options['rel']
示例2: register
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def register(self, identity: Identity, public_key: PKey) -> None:
logger = self.logger.getChild('register')
title = get_key_fingerprint(public_key)
data = json.dumps({
'title': title,
'key': format_openssh_pubkey(public_key)
})
try:
request(identity, self.list_url, 'POST', data=data.encode())
except urllib.error.HTTPError as e:
if e.code != 422:
raise
content_type = e.headers.get('Content-Type')
mimetype, options = parse_options_header(content_type)
if mimetype != 'application/json':
raise
charset = options.get('charset', 'utf-8')
content_body = e.read().decode(charset)
logger.debug('response body:\n%s', content_body)
response = json.loads(content_body)
for error in response.get('errors', []):
if not isinstance(error, dict):
continue
elif error.get('field') != 'key':
continue
message = error.get('message', '').strip().lower()
if message != 'key is already in use':
continue
raise DuplicatePublicKeyError(message)
raise
示例3: parse_from_environ
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def parse_from_environ(self, environ):
"""Parses the information from the environment as form data.
:param environ: the WSGI environment to be used for parsing.
:return: A tuple in the form ``(stream, form, files)``.
"""
content_type = environ.get('CONTENT_TYPE', '')
content_length = get_content_length(environ)
mimetype, options = parse_options_header(content_type)
return self.parse(get_input_stream(environ), mimetype,
content_length, options)
示例4: get_part_charset
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def get_part_charset(self, headers):
# Figure out input charset for current part
content_type = headers.get('content-type')
if content_type:
mimetype, ct_params = parse_options_header(content_type)
return ct_params.get('charset', self.charset)
return self.charset
示例5: charset
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def charset(self):
"""The charset from the content type."""
header = self.environ.get('CONTENT_TYPE')
if header:
ct, options = parse_options_header(header)
charset = options.get('charset')
if charset:
if is_known_charset(charset):
return charset
return self.unknown_charset(charset)
return self.default_charset
示例6: _get_charset
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def _get_charset(self):
header = self.headers.get('content-type')
if header:
charset = parse_options_header(header)[1].get('charset')
if charset:
return charset
return self.default_charset
示例7: _set_charset
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def _set_charset(self, charset):
header = self.headers.get('content-type')
ct, options = parse_options_header(header)
if not ct:
raise TypeError('Cannot set charset if Content-Type '
'header is missing.')
options['charset'] = charset
self.headers['Content-Type'] = dump_options_header(ct, options)
示例8: _get_mimetype_params
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def _get_mimetype_params(self):
def on_update(d):
self.headers['Content-Type'] = \
dump_options_header(self.mimetype, d)
d = parse_options_header(self.headers.get('content-type', ''))[1]
return CallbackDict(d, on_update)
示例9: test_attachment
# 需要導入模塊: from werkzeug import http [as 別名]
# 或者: from werkzeug.http import parse_options_header [as 別名]
def test_attachment(self):
app = flask.Flask(__name__)
with catch_warnings() as captured:
with app.test_request_context():
f = open(os.path.join(app.root_path, 'static/index.html'))
rv = flask.send_file(f, as_attachment=True)
value, options = parse_options_header(rv.headers['Content-Disposition'])
self.assert_equal(value, 'attachment')
rv.close()
# mimetypes + etag
self.assert_equal(len(captured), 2)
with app.test_request_context():
self.assert_equal(options['filename'], 'index.html')
rv = flask.send_file('static/index.html', as_attachment=True)
value, options = parse_options_header(rv.headers['Content-Disposition'])
self.assert_equal(value, 'attachment')
self.assert_equal(options['filename'], 'index.html')
rv.close()
with app.test_request_context():
rv = flask.send_file(StringIO('Test'), as_attachment=True,
attachment_filename='index.txt',
add_etags=False)
self.assert_equal(rv.mimetype, 'text/plain')
value, options = parse_options_header(rv.headers['Content-Disposition'])
self.assert_equal(value, 'attachment')
self.assert_equal(options['filename'], 'index.txt')
rv.close()