本文整理汇总了Python中urllib2.Request.get_selector方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_selector方法的具体用法?Python Request.get_selector怎么用?Python Request.get_selector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib2.Request
的用法示例。
在下文中一共展示了Request.get_selector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get1
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_selector [as 别名]
def get1(self, url, maxretry=3, maxredirect=3):
if self.debug:
print >>stderr, 'GET: %r' % url
# loop
for rtry in range(maxredirect):
# forge urllib2.Request object.
req = Request(url)
# add cookie headers if necessary.
if self.cookiejar:
self.cookiejar.add_cookie_header(req)
headers = req.unredirected_hdrs
headers.update(self.HEADERS)
else:
headers = self.HEADERS
# get response.
for ctry in range(maxretry):
try:
if not self.conn:
print >>stderr, 'Making connection: %r...' % (self.hostport,)
self.conn = HTTPConnection(self.hostport)
self.conn.request('GET', req.get_selector().replace(' ',''), '', headers)
self.conn.sock.settimeout(self.timeout)
resp = self.conn.getresponse()
break
except BadStatusLine, x:
# connection closed unexpectedly
print >>stderr, 'Connection closed unexpectedly.'
# it restarts the connection...
self.conn.close()
self.conn = None
except socket.error, x:
# connection closed unexpectedly
print >>stderr, 'Socket error:', x
self.conn.close()
self.conn = None
示例2: sign_request
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_selector [as 别名]
def sign_request(request, secret_key):
req = Request(request)
raw = "%s\n%s\n%s\n%s" % (req.get_method(),req.get_host(),req.get_selector().split('?')[0],req.get_selector().split('?')[1])
key = bytes(secret_key)
print(raw)
hashed = hmac.new(key, raw, sha1)
signature = binascii.b2a_base64(hashed.digest())
return request + '&signature=%s' % quote(signature, '\n')
示例3: test_urlwith_fragment
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_selector [as 别名]
def test_urlwith_fragment(self):
req = Request("http://www.python.org/?qs=query#fragment=true")
self.assertEqual("/?qs=query", req.get_selector())
req = Request("http://www.python.org/#fun=true")
self.assertEqual("/", req.get_selector())