def set_request_context(self, url, get, post,
referer, cookies, multipart=False):
"""
Sets everything needed for the request.
"""
url = safequote(url)
if get:
get = urlencode(get)
url = "{0}?{1}".format(url, get)
self.setopt(pycurl.URL, url)
if post:
self.setopt(pycurl.POST, 1)
if not multipart:
if isinstance(post, str):
post = convert.to_bytes(post, post)
elif not isinstance(post, bytes):
post = safeurlencode(post)
self.setopt(pycurl.POSTFIELDS, post)
else:
post = [(x, convert.to_bytes(y, y))
for x, y in post.items()]
self.setopt(pycurl.HTTPPOST, post)
else:
self.setopt(pycurl.POST, 0)
if referer and self.last_url:
self.headers['Referer'] = str(self.last_url)
else:
self.headers['Referer'] = ""
if cookies:
for c in self.cj.output().splitlines():
self.setopt(pycurl.COOKIELIST, c)
else:
# Magic string that erases all cookies
self.setopt(pycurl.COOKIELIST, 'ALL')
# TODO: remove auth again
if "auth" in self.options:
self.setopt(pycurl.USERPWD, self.options['auth'])
self.setopt(pycurl.HTTPHEADER, self.headers.list())
评论列表
文章目录