当前位置: 首页>>代码示例>>Python>>正文


Python http.parse_options_header方法代码示例

本文整理汇总了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'] 
开发者ID:spoqa,项目名称:geofront,代码行数:8,代码来源:server_test.py

示例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 
开发者ID:spoqa,项目名称:geofront,代码行数:32,代码来源:github.py

示例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) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:formparser.py

示例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 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:formparser.py

示例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 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:wrappers.py

示例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 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:wrappers.py

示例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) 
开发者ID:jpush,项目名称:jbox,代码行数:10,代码来源:wrappers.py

示例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) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:test.py

示例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() 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:31,代码来源:helpers.py


注:本文中的werkzeug.http.parse_options_header方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。