Python cookielib.CookieJar() Examples
The following are 30
code examples of cookielib.CookieJar().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cookielib
, or try the search function
.
Example #1
Source File: test_cookielib.py From BinderFilter with MIT License | 6 votes |
def test_secure(self): from cookielib import CookieJar, DefaultCookiePolicy for ns in True, False: for whitespace in " ", "": c = CookieJar() if ns: pol = DefaultCookiePolicy(rfc2965=False) int = interact_netscape vs = "" else: pol = DefaultCookiePolicy(rfc2965=True) int = interact_2965 vs = "; Version=1" c.set_policy(pol) url = "http://www.acme.com/" int(c, url, "foo1=bar%s%s" % (vs, whitespace)) int(c, url, "foo2=bar%s; secure%s" % (vs, whitespace)) self.assertTrue( not c._cookies["www.acme.com"]["/"]["foo1"].secure, "non-secure cookie registered secure") self.assertTrue( c._cookies["www.acme.com"]["/"]["foo2"].secure, "secure cookie registered non-secure")
Example #2
Source File: test_cookielib.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_path_mirror(self): from cookielib import CookieJar, DefaultCookiePolicy pol = DefaultCookiePolicy(rfc2965=True) c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, "spam=eggs; Version=1") h = interact_2965(c, url) self.assertNotIn("Path", h, "absent path returned with path present") c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, 'spam=eggs; Version=1; Path=/') h = interact_2965(c, url) self.assertIn('$Path="/"', h, "path not returned")
Example #3
Source File: dedecms全版本验证码绕过爆破.py From fuzzdb-collect with GNU General Public License v3.0 | 6 votes |
def __init__(self,host=None,user=None,password=None,fileusr=None,filepwd=None): self.user=user self.host=host self.password=password self.fileusr=fileusr self.filepwd=filepwd self.cj=cookielib.CookieJar() self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj)) self.opener.addheaders.append(('User-Agent','Mozilla/5.0')) self.opener.addheaders.append(('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')) self.opener.addheaders.append(('Accept-Language','zh-cn,zh;q=0.5')) self.opener.addheaders.append(('Accept-Encoding','gzip,deflate')) self.opener.addheaders.append(('Accept-Charset','GB2312,utf-8;q=0.7,*;q=0.7')) self.opener.addheaders.append(('Keep-Alive','115')) self.opener.addheaders.append(('Connection','keep-alive')) self.opener.addheaders.append(('X-Forwarded-For','219.78.113.243'))
Example #4
Source File: logger_base.py From loggers with GNU General Public License v2.0 | 6 votes |
def send_post(url, form_data_dict): "pass value by POST method, return response string" #set headers user_agent = \ 'Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) ' +\ 'AppleWebKit/537.36 (KHTML, like Gecko) ' +\ 'Chrome/31.0.1650.59 Mobile Safari/537.36' headers = {'User-Agent': user_agent} #convert form dict data data = urllib.urlencode(form_data_dict) #get request object req = urllib2.Request(url, data, headers) #set cookie and create a general opener instead urlopen() cookie = cookielib.CookieJar() # CookieJar object to store cookie handler = urllib2.HTTPCookieProcessor(cookie) # create cookie processor opener = urllib2.build_opener(handler) # a general opener #return response page content response = opener.open(req, timeout=100) page = response.read() return page
Example #5
Source File: dedecms无视验证码爆破.py From fuzzdb-collect with GNU General Public License v3.0 | 6 votes |
def __init__(self,host=None,user=None,password=None,fileusr=None,filepwd=None): self.user=user self.host=host self.password=password self.fileusr=fileusr self.filepwd=filepwd self.cj=cookielib.CookieJar() self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj)) self.opener.addheaders.append(('User-Agent','Mozilla/5.0')) self.opener.addheaders.append(('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')) self.opener.addheaders.append(('Accept-Language','zh-cn,zh;q=0.5')) self.opener.addheaders.append(('Accept-Encoding','gzip,deflate')) self.opener.addheaders.append(('Accept-Charset','GB2312,utf-8;q=0.7,*;q=0.7')) self.opener.addheaders.append(('Keep-Alive','115')) self.opener.addheaders.append(('Connection','keep-alive')) self.opener.addheaders.append(('X-Forwarded-For','219.78.113.243'))
Example #6
Source File: test_cookielib.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_url_encoding(self): # Try some URL encodings of the PATHs. # (the behaviour here has changed from libwww-perl) from cookielib import CookieJar, DefaultCookiePolicy c = CookieJar(DefaultCookiePolicy(rfc2965=True)) interact_2965(c, "http://www.acme.com/foo%2f%25/%3c%3c%0Anew%E5/%E5", "foo = bar; version = 1") cookie = interact_2965( c, "http://www.acme.com/foo%2f%25/<<%0anew�/���", 'bar=baz; path="/foo/"; version=1'); version_re = re.compile(r'^\$version=\"?1\"?', re.I) self.assertIn("foo=bar", cookie) self.assertRegexpMatches(cookie, version_re) cookie = interact_2965( c, "http://www.acme.com/foo/%25/<<%0anew�/���") self.assertFalse(cookie) # unicode URL doesn't raise exception cookie = interact_2965(c, u"http://www.acme.com/\xfc")
Example #7
Source File: test_cookielib.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_secure(self): from cookielib import CookieJar, DefaultCookiePolicy for ns in True, False: for whitespace in " ", "": c = CookieJar() if ns: pol = DefaultCookiePolicy(rfc2965=False) int = interact_netscape vs = "" else: pol = DefaultCookiePolicy(rfc2965=True) int = interact_2965 vs = "; Version=1" c.set_policy(pol) url = "http://www.acme.com/" int(c, url, "foo1=bar%s%s" % (vs, whitespace)) int(c, url, "foo2=bar%s; secure%s" % (vs, whitespace)) self.assertFalse( c._cookies["www.acme.com"]["/"]["foo1"].secure, "non-secure cookie registered secure") self.assertTrue( c._cookies["www.acme.com"]["/"]["foo2"].secure, "secure cookie registered non-secure")
Example #8
Source File: captcha_handler.py From PySide_For_Amazon_Order with MIT License | 6 votes |
def __init__(self, user, pwd, softId="110614", softKey="469c0d8a805a40f39d3c1ec3c9281e9c", codeType="1004"): self.softId = softId self.softKey = softKey self.user = user self.pwd = pwd self.codeType = codeType self.uid = "100" self.initUrl = "http://common.taskok.com:9000/Service/ServerConfig.aspx" self.version = '1.1.1.2' self.cookieJar = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(self.cookieJar)) self.loginUrl = None self.uploadUrl = None self.codeUrl = None self.params = [] self.uKey = None
Example #9
Source File: test_cookielib.py From BinderFilter with MIT License | 6 votes |
def test_path_mirror(self): from cookielib import CookieJar, DefaultCookiePolicy pol = DefaultCookiePolicy(rfc2965=True) c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, "spam=eggs; Version=1") h = interact_2965(c, url) self.assertNotIn("Path", h, "absent path returned with path present") c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, 'spam=eggs; Version=1; Path=/') h = interact_2965(c, url) self.assertIn('$Path="/"', h, "path not returned")
Example #10
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token): self.token = token self.action = 'user?access_token=%s' % self.token self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'GET' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, None) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_authenticated = False else: self.is_authenticated = True self.username = data['user']['name']
Example #11
Source File: test_cookielib.py From BinderFilter with MIT License | 5 votes |
def test_strict_domain(self): # Cookies whose domain is a country-code tld like .co.uk should # not be set if CookiePolicy.strict_domain is true. from cookielib import CookieJar, DefaultCookiePolicy cp = DefaultCookiePolicy(strict_domain=True) cj = CookieJar(policy=cp) interact_netscape(cj, "http://example.co.uk/", 'no=problemo') interact_netscape(cj, "http://example.co.uk/", 'okey=dokey; Domain=.example.co.uk') self.assertEqual(len(cj), 2) for pseudo_tld in [".co.uk", ".org.za", ".tx.us", ".name.us"]: interact_netscape(cj, "http://example.%s/" % pseudo_tld, 'spam=eggs; Domain=.co.uk') self.assertEqual(len(cj), 2)
Example #12
Source File: test_cookielib.py From BinderFilter with MIT License | 5 votes |
def test_port_mirror(self): from cookielib import CookieJar, DefaultCookiePolicy pol = DefaultCookiePolicy(rfc2965=True) c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, "spam=eggs; Version=1") h = interact_2965(c, url) self.assertNotIn("Port", h, "absent port returned with port present") c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, "spam=eggs; Version=1; Port") h = interact_2965(c, url) self.assertTrue(re.search("\$Port([^=]|$)", h), "port with no value not returned with no value") c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, 'spam=eggs; Version=1; Port="80"') h = interact_2965(c, url) self.assertIn('$Port="80"', h, "port with single value not returned with single value") c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, 'spam=eggs; Version=1; Port="80,8080"') h = interact_2965(c, url) self.assertIn('$Port="80,8080"', h, "port with multiple values not returned with multiple " "values")
Example #13
Source File: test_cookielib.py From BinderFilter with MIT License | 5 votes |
def test_domain_allow(self): from cookielib import CookieJar, DefaultCookiePolicy from urllib2 import Request c = CookieJar(policy=DefaultCookiePolicy( blocked_domains=["acme.com"], allowed_domains=["www.acme.com"])) req = Request("http://acme.com/") headers = ["Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/"] res = FakeResponse(headers, "http://acme.com/") c.extract_cookies(res, req) self.assertEqual(len(c), 0) req = Request("http://www.acme.com/") res = FakeResponse(headers, "http://www.acme.com/") c.extract_cookies(res, req) self.assertEqual(len(c), 1) req = Request("http://www.coyote.com/") res = FakeResponse(headers, "http://www.coyote.com/") c.extract_cookies(res, req) self.assertEqual(len(c), 1) # set a cookie with non-allowed domain... req = Request("http://www.coyote.com/") res = FakeResponse(headers, "http://www.coyote.com/") cookies = c.make_cookies(res, req) c.set_cookie(cookies[0]) self.assertEqual(len(c), 2) # ... and check is doesn't get returned c.add_cookie_header(req) self.assertTrue(not req.has_header("Cookie"))
Example #14
Source File: test_cookielib.py From BinderFilter with MIT License | 5 votes |
def test_quote_cookie_value(self): from cookielib import CookieJar, DefaultCookiePolicy c = CookieJar(policy=DefaultCookiePolicy(rfc2965=True)) interact_2965(c, "http://www.acme.com/", r'foo=\b"a"r; Version=1') h = interact_2965(c, "http://www.acme.com/") self.assertEqual(h, r'$Version=1; foo=\\b\"a\"r')
Example #15
Source File: test_cookielib.py From BinderFilter with MIT License | 5 votes |
def test_missing_final_slash(self): # Missing slash from request URL's abs_path should be assumed present. from cookielib import CookieJar, DefaultCookiePolicy from urllib2 import Request url = "http://www.acme.com" c = CookieJar(DefaultCookiePolicy(rfc2965=True)) interact_2965(c, url, "foo=bar; Version=1") req = Request(url) self.assertEqual(len(c), 1) c.add_cookie_header(req) self.assertTrue(req.has_header("Cookie"))
Example #16
Source File: test_cookielib.py From BinderFilter with MIT License | 5 votes |
def test_Cookie_iterator(self): from cookielib import CookieJar, Cookie, DefaultCookiePolicy cs = CookieJar(DefaultCookiePolicy(rfc2965=True)) # add some random cookies interact_2965(cs, "http://blah.spam.org/", 'foo=eggs; Version=1; ' 'Comment="does anybody read these?"; ' 'CommentURL="http://foo.bar.net/comment.html"') interact_netscape(cs, "http://www.acme.com/blah/", "spam=bar; secure") interact_2965(cs, "http://www.acme.com/blah/", "foo=bar; secure; Version=1") interact_2965(cs, "http://www.acme.com/blah/", "foo=bar; path=/; Version=1") interact_2965(cs, "http://www.sol.no", r'bang=wallop; version=1; domain=".sol.no"; ' r'port="90,100, 80,8080"; ' r'max-age=100; Comment = "Just kidding! (\"|\\\\) "') versions = [1, 1, 1, 0, 1] names = ["bang", "foo", "foo", "spam", "foo"] domains = [".sol.no", "blah.spam.org", "www.acme.com", "www.acme.com", "www.acme.com"] paths = ["/", "/", "/", "/blah", "/blah/"] for i in range(4): i = 0 for c in cs: self.assertIsInstance(c, Cookie) self.assertEqual(c.version, versions[i]) self.assertEqual(c.name, names[i]) self.assertEqual(c.domain, domains[i]) self.assertEqual(c.path, paths[i]) i = i + 1
Example #17
Source File: test_cookielib.py From BinderFilter with MIT License | 5 votes |
def test_bad_cookie_header(self): def cookiejar_from_cookie_headers(headers): from cookielib import CookieJar from urllib2 import Request c = CookieJar() req = Request("http://www.example.com/") r = FakeResponse(headers, "http://www.example.com/") c.extract_cookies(r, req) return c # none of these bad headers should cause an exception to be raised for headers in [ ["Set-Cookie: "], # actually, nothing wrong with this ["Set-Cookie2: "], # ditto # missing domain value ["Set-Cookie2: a=foo; path=/; Version=1; domain"], # bad max-age ["Set-Cookie: b=foo; max-age=oops"], # bad version ["Set-Cookie: b=foo; version=spam"], ]: c = cookiejar_from_cookie_headers(headers) # these bad cookies shouldn't be set self.assertEqual(len(c), 0) # cookie with invalid expires is treated as session cookie headers = ["Set-Cookie: c=foo; expires=Foo Bar 12 33:22:11 2000"] c = cookiejar_from_cookie_headers(headers) cookie = c._cookies["www.example.com"]["/"]["c"] self.assertTrue(cookie.expires is None)
Example #18
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, code): self.client_id = '845mHJx5-CxI8dSlStHB' self.client_secret = 'lvN6LZOZkUAH8aa_WAbvAJ4AXGcSo7irZyAPdRQj' self.action = 'oauth/access_token' self.code = code request_data = urllib.urlencode({ 'client_id' : self.client_id, 'client_secret' : self.client_secret, 'code' : self.code }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_authorized = False self.message = data['message'] else: self.is_authorized = True self.access_token = data['access_token']
Example #19
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self): self.client_id = '845mHJx5-CxI8dSlStHB' self.action = 'oauth/device/code' request_data = urllib.urlencode({ 'client_id' : self.client_id }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_code = False else: self.is_code = True self.device_code = data['device_code'] self.user_code = data['user_code'] self.verification_url = data['verification_url'] self.expires_in = data['expires_in'] self.interval = data['interval']
Example #20
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, page, limit): self.token = token self.page = page self.limit = limit self.action = 'library?access_token=%s&page=%s&limit=%s' % (self.token, self.page, self.limit) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'GET' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, None) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_found = False else: self.is_found = True self.resultdata = data['result'] self.shows = data['shows']
Example #21
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, episode_id, emotion_id): self.token = token self.episode_id = episode_id self.emotion_id = emotion_id self.action = 'emotion' request_data = urllib.urlencode({ 'access_token' : self.token, 'episode_id' : self.episode_id, 'emotion_id' : self.emotion_id }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_set = False else: self.is_set = True
Example #22
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, shows): self.token = token self.shows = shows self.action = 'delete_show_progress' request_data = urllib.urlencode({ 'access_token' : self.token, 'shows' : self.shows }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_delete = False else: self.is_delete = True self.resultdata = data['result']
Example #23
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, shows): self.token = token self.shows = shows self.action = 'show_progress' request_data = urllib.urlencode({ 'access_token' : self.token, 'shows' : self.shows }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_set = False else: self.is_set = True
Example #24
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, show_id, season, episode): self.token = token self.show_id = show_id self.season = season self.episode = episode self.action = 'show_progress' request_data = urllib.urlencode({ 'access_token' : self.token, 'show_id' : self.show_id, 'season' : self.season, 'episode' : self.episode }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_set = False else: self.is_set = True
Example #25
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, show_id): self.token = token self.show_id = show_id self.action = 'follow' request_data = urllib.urlencode({ 'access_token' : self.token, 'show_id' : self.show_id }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_follow = False else: self.is_follow = True
Example #26
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, show_id): self.token = token self.show_id = show_id self.action = 'follow' request_data = urllib.urlencode({ 'access_token' : self.token, 'show_id' : self.show_id }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_follow = False else: self.is_follow = True
Example #27
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, episode_id, progress): self.token = token self.episode_id = episode_id self.progress = progress self.action = 'progress' request_data = urllib.urlencode({ 'access_token' : self.token, 'episode_id' : self.episode_id, 'progress' : self.progress }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_set = False else: self.is_set = True
Example #28
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, episode_id, facebook=0, twitter=0): self.token = token self.episode_id = episode_id self.facebook = facebook if self.facebook == True: self.facebook = 1 else: self.facebook = 0 self.twitter = twitter if self.twitter == True: self.twitter = 1 else: self.twitter = 0 self.action = 'checkin' request_data = urllib.urlencode({ 'access_token' : self.token, 'episode_id' : self.episode_id, 'publish_on_ticker' : self.facebook, 'publish_on_twitter' : self.twitter }) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'POST' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, request_data) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_marked = False else: self.is_marked = True
Example #29
Source File: tvtime.py From script.tvtime with GNU General Public License v2.0 | 5 votes |
def __init__(self, token, episode_id): self.token = token self.episode_id = episode_id self.action = 'checkin?access_token=%s&episode_id=%s' % (self.token, self.episode_id) self.cj = cookielib.CookieJar() self.opener = urllib2.build_opener( urllib2.HTTPRedirectHandler(), urllib2.HTTPHandler(debuglevel=0), urllib2.HTTPSHandler(debuglevel=0), urllib2.HTTPCookieProcessor(self.cj) ) self.opener.addheaders = [ ('User-agent', 'Lynx/2.8.1pre.9 libwww-FM/2.14') ] self.opener.get_method = lambda: 'GET' request_url = "%s%s" % (request_uri, self.action) try: response = self.opener.open(request_url, None) data = json.loads(''.join(response.readlines())) except: data = None if (data is None) or (data['result'] == "KO"): self.is_found = False else: self.is_found = True self.is_watched = data['code']
Example #30
Source File: jsoncookie.py From watchdog with Apache License 2.0 | 5 votes |
def cookiejar(self, domain): if not domain: return None dotdomain = domain if domain[0] == '.' else '.' + domain exploded = dotdomain.split(".") parent_domains = [".%s" % (".".join(exploded[x:])) for x in range(1, len(exploded) - 1)] matching_domains = [d for d in parent_domains if d in self.cookiedict] if not matching_domains: return None cj = cookielib.CookieJar() for d in matching_domains: for path in self.cookiedict[d]: for cookie_name, cookie_attrs in self.cookiedict[d][path].items(): ck = cookielib.Cookie(version=cookie_attrs["version"], name=cookie_name, value=cookie_attrs["value"], port=None, port_specified=False, domain=d, domain_specified=True, domain_initial_dot=False, path=path, path_specified=True, secure=cookie_attrs["secure"], expires=cookie_attrs["expires"], discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False) if cookie_attrs["port"]: ck.port = cookie_attrs["port"] ck.port_specified = True cj.set_cookie(ck) return cj