本文整理汇总了Python中urllib2.Request.get_type方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_type方法的具体用法?Python Request.get_type怎么用?Python Request.get_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib2.Request
的用法示例。
在下文中一共展示了Request.get_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_type [as 别名]
def open(self, fullurl, data=None):
"""
Overriding to remove the timeout kwarg which was being used below to
override my own HTTPRequest.timeout attribute.
"""
# accept a URL or a Request object
if isinstance(fullurl, basestring):
req = Request(fullurl, data)
else:
req = fullurl
if data is not None:
req.add_data(data)
# This is what I want to remove and the reason to override
# req.timeout = timeout
protocol = req.get_type()
# pre-process request
meth_name = protocol+"_request"
for processor in self.process_request.get(protocol, []):
meth = getattr(processor, meth_name)
req = meth(req)
response = self._open(req, data)
# post-process response
meth_name = protocol+"_response"
for processor in self.process_response.get(protocol, []):
meth = getattr(processor, meth_name)
response = meth(req, response)
return response