python引入header_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

​点赞 6

# 需要导入模块: 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,

示例2: get_encoding

​点赞 6

# 需要导入模块: 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']',

flags=re.I)

pragma_re = re.compile(r']',

flags=re.I)

xml_re = re.compile(r'^]')

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,

示例3: _parse_accept

​点赞 6

# 需要导入模块: 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,

示例4: get_encoding_from_headers

​点赞 6

# 需要导入模块: 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,

示例5: __init__

​点赞 6

# 需要导入模块: 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,

示例6: test_success

​点赞 6

# 需要导入模块: 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,

示例7: test_success_with_bucket

​点赞 6

# 需要导入模块: 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,

示例8: test_success_full_success_url

​点赞 6

# 需要导入模块: 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,

示例9: __init__

​点赞 6

# 需要导入模块: 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,

示例10: __init__

​点赞 6

# 需要导入模块: 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,

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值