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


Python cgi.parse_header方法代码示例

本文整理汇总了Python中cgi.parse_header方法的典型用法代码示例。如果您正苦于以下问题:Python cgi.parse_header方法的具体用法?Python cgi.parse_header怎么用?Python cgi.parse_header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cgi的用法示例。


在下文中一共展示了cgi.parse_header方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_encoding_from_headers

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def get_encoding_from_headers(headers):
    """Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    """

    content_type = headers.get('content-type')

    if not content_type:
        return None

    content_type, params = cgi.parse_header(content_type)

    if 'charset' in params:
        return params['charset'].strip("'\"")

    if 'text' in content_type:
        return 'ISO-8859-1' 
开发者ID:war-and-code,项目名称:jawfish,代码行数:20,代码来源:utils.py

示例2: get_encoding

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def get_encoding(headers, content):
    """Get encoding from request headers or page head."""
    encoding = None

    content_type = headers.get('content-type')
    if content_type:
        _, params = cgi.parse_header(content_type)
        if 'charset' in params:
            encoding = params['charset'].strip("'\"")

    if not encoding:
        content = utils.pretty_unicode(content[:1000]) if six.PY3 else content

        charset_re = re.compile(r'<meta.*?charset=["\']*(.+?)["\'>]',
                                flags=re.I)
        pragma_re = re.compile(r'<meta.*?content=["\']*;?charset=(.+?)["\'>]',
                               flags=re.I)
        xml_re = re.compile(r'^<\?xml.*?encoding=["\']*(.+?)["\'>]')
        encoding = (charset_re.findall(content) +
                    pragma_re.findall(content) +
                    xml_re.findall(content))
        encoding = encoding and encoding[0] or None

    return encoding 
开发者ID:binux,项目名称:pyspider,代码行数:26,代码来源:response.py

示例3: _parse_accept

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def _parse_accept(request):
    """Get the accept type for a given request.

    Valid accept types are "application/json", "application/jsonlines", "application/x-recordio-protobuf",
    and "text/csv". If no accept type is set, use the value in SAGEMAKER_DEFAULT_INVOCATIONS_ACCEPT.

    :param request: flask request
    :return: parsed accept type
    """
    accept, _ = cgi.parse_header(request.headers.get("accept", ""))
    if not accept or accept == "*/*":
        return os.getenv(sm_env_constants.SAGEMAKER_DEFAULT_INVOCATIONS_ACCEPT, "text/csv")
    if accept.lower() not in SUPPORTED_ACCEPTS:
        raise ValueError("Accept type {} is not supported. Please use supported accept types: {}."
                         .format(accept, SUPPORTED_ACCEPTS))
    return accept.lower() 
开发者ID:aws,项目名称:sagemaker-xgboost-container,代码行数:18,代码来源:serve.py

示例4: get_encoding_from_headers

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def get_encoding_from_headers(headers):
    """Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    :rtype: str
    """

    content_type = headers.get('content-type')

    if not content_type:
        return None

    content_type, params = cgi.parse_header(content_type)

    if 'charset' in params:
        return params['charset'].strip("'\"")

    if 'text' in content_type:
        return 'ISO-8859-1' 
开发者ID:getavalon,项目名称:core,代码行数:21,代码来源:utils.py

示例5: __init__

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def __init__(self, content, url, headers=None):
        # Determine if we have any encoding information in our headers
        encoding = None
        if headers and "Content-Type" in headers:
            content_type, params = cgi.parse_header(headers["Content-Type"])

            if "charset" in params:
                encoding = params['charset']

        self.content = content
        self.parsed = html5lib.parse(
            self.content,
            transport_encoding=encoding,
            namespaceHTMLElements=False,
        )
        self.url = url
        self.headers = headers 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:index.py

示例6: test_success

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def test_success(self):
    """Basic dispatcher request flow."""
    # Create upload.
    upload_data = (
        """--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"

value
--================1234==--""")

    upload_url = blobstore.create_upload_url('/success?foo=bar')

    upload, forward_environ, _ = self._run_test_success(
        upload_data, upload_url)

    self.assertEquals('/success', forward_environ['PATH_INFO'])
    self.assertEquals('foo=bar', forward_environ['QUERY_STRING'])
    self.assertEquals(
        ('form-data', {'filename': 'stuff.txt', 'name': 'field1'}),
        cgi.parse_header(upload['content-disposition'])) 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:blob_upload_test.py

示例7: test_success_with_bucket

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def test_success_with_bucket(self):
    """Basic dispatcher request flow."""
    # Create upload.
    upload_data = (
        """--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"

value
--================1234==--""")

    upload_url = blobstore.create_upload_url('/success?foo=bar',
                                             gs_bucket_name='my_test_bucket')

    upload, forward_environ, forward_body = self._run_test_success(
        upload_data, upload_url)

    self.assertEquals('/success', forward_environ['PATH_INFO'])
    self.assertEquals('foo=bar', forward_environ['QUERY_STRING'])
    self.assertEquals(
        ('form-data', {'filename': 'stuff.txt', 'name': 'field1'}),
        cgi.parse_header(upload['content-disposition']))
    self.assertIn('X-AppEngine-Cloud-Storage-Object: /gs/%s' % 'my_test_bucket',
                  forward_body) 
开发者ID:elsigh,项目名称:browserscope,代码行数:27,代码来源:blob_upload_test.py

示例8: test_success_full_success_url

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def test_success_full_success_url(self):
    """Request flow with a success url containing protocol, host and port."""
    # Create upload.
    upload_data = (
        """--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"

value
--================1234==--""")

    # The scheme, host and port should all be ignored.
    upload_url = blobstore.create_upload_url(
        'https://example.com:1234/success?foo=bar')

    upload, forward_environ, _ = self._run_test_success(
        upload_data, upload_url)

    self.assertEquals('/success', forward_environ['PATH_INFO'])
    self.assertEquals('foo=bar', forward_environ['QUERY_STRING'])
    self.assertEquals(
        ('form-data', {'filename': 'stuff.txt', 'name': 'field1'}),
        cgi.parse_header(upload['content-disposition'])) 
开发者ID:elsigh,项目名称:browserscope,代码行数:26,代码来源:blob_upload_test.py

示例9: __init__

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def __init__(self, content, url, headers=None):
        # Determine if we have any encoding information in our headers
        encoding = None
        if headers and "Content-Type" in headers:
            content_type, params = cgi.parse_header(headers["Content-Type"])

            if "charset" in params:
                encoding = params['charset']

        self.content = content
        self.parsed = html5lib.parse(
            self.content,
            encoding=encoding,
            namespaceHTMLElements=False,
        )
        self.url = url
        self.headers = headers 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:index.py

示例10: __init__

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse_header [as 别名]
def __init__(self, url, content, headers):
        if not url.endswith("/"):
            url += "/"

        self._url = url
        encoding = None
        if headers and "Content-Type" in headers:
            content_type, params = cgi.parse_header(headers["Content-Type"])

            if "charset" in params:
                encoding = params["charset"]

        self._content = content

        if encoding is None:
            self._parsed = html5lib.parse(content, namespaceHTMLElements=False)
        else:
            self._parsed = html5lib.parse(
                content, transport_encoding=encoding, namespaceHTMLElements=False
            ) 
开发者ID:python-poetry,项目名称:poetry,代码行数:22,代码来源:legacy_repository.py


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