當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。