Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fa5c76
commit a2d0992
Showing
12 changed files
with
302 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
syntax on | ||
colorscheme darkblue | ||
set background=dark | ||
set tabstop=3 | ||
set shiftwidth=3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,37 @@ | ||
#!/usr/bin/env python | ||
|
||
import cookielib, sys, os, urllib2 | ||
|
||
class FakeRequest: | ||
def __init__(self, argv): | ||
self.argv = argv | ||
self.cookies = None | ||
if len(self.argv) == 12: | ||
self.cookies = self.argv[11] | ||
def get_full_url(self): | ||
#TODO: this is a hack, fix in uzbl.c! | ||
u = self.get_host()+self.argv[10] | ||
if self.argv[6].startswith('https'): | ||
u = 'https://'+u | ||
else: | ||
u = 'http://'+u | ||
return u | ||
def get_host(self): | ||
return self.argv[9] | ||
def get_type(self): | ||
return self.get_full_url().split(':')[0] | ||
def is_unverifiable(self): | ||
return False | ||
def get_origin_req_host(self): | ||
return self.argv[9] | ||
def has_header(self, header): | ||
if header == 'Cookie': | ||
return self.cookies!=None | ||
def get_header(self, header_name, default=None): | ||
if header_name == 'Cookie' and self.cookies: | ||
return self.cookies | ||
else: | ||
return default | ||
def header_items(self): | ||
if self.cookies: | ||
return [('Cookie',self.cookies)] | ||
else: | ||
return [] | ||
def add_unredirected_header(self, key, header): | ||
if key == 'Cookie': | ||
self.cookies = header | ||
|
||
class FakeHeaders: | ||
def __init__(self, argv): | ||
self.argv = argv | ||
def getallmatchingheaders(self, header): | ||
if header == 'Set-Cookie' and len(self.argv) == 12: | ||
return ['Set-Cookie: '+self.argv[11]] | ||
else: | ||
return [] | ||
def getheaders(self, header): | ||
if header == 'Set-Cookie' and len(self.argv) == 12: | ||
return [self.argv[11]] | ||
else: | ||
return [] | ||
class FakeResponse: | ||
def __init__(self, argv): | ||
self.argv = argv | ||
def info(self): | ||
return FakeHeaders(self.argv) | ||
import StringIO, cookielib, os, sys, urllib2 | ||
|
||
if __name__ == '__main__': | ||
if os.environ['XDG_DATA_HOME']: | ||
jar = cookielib.MozillaCookieJar(os.environ['XDG_DATA_HOME']+'/uzbl/cookies.txt') | ||
action = sys.argv[8] | ||
uri = urllib2.urlparse.ParseResult( | ||
scheme=sys.argv[9], | ||
netloc=sys.argv[10], | ||
path=sys.argv[11], | ||
params='', | ||
query='', | ||
fragment='').geturl() | ||
set_cookie = sys.argv[12] if len(sys.argv)>12 else None | ||
|
||
if 'XDG_DATA_HOME' in os.environ.keys() and os.environ['XDG_DATA_HOME']: | ||
f = os.path.join(os.environ['XDG_DATA_HOME'],'uzbl/cookies.txt') | ||
else: | ||
jar = cookielib.MozillaCookieJar(os.environ['HOME']+'.local/share/uzbl/cookies.txt') | ||
f = os.path.join(os.environ['HOME'],'.local/share/uzbl/cookies.txt') | ||
jar = cookielib.MozillaCookieJar(f) | ||
|
||
try: | ||
jar.load() | ||
jar.load(ignore_discard=True) | ||
except: | ||
pass | ||
|
||
req = FakeRequest(sys.argv) | ||
|
||
action = sys.argv[8] | ||
req = urllib2.Request(uri) | ||
|
||
if action == 'GET': | ||
jar.add_cookie_header(req) | ||
if req.cookies: | ||
print req.cookies | ||
if req.has_header('Cookie'): | ||
print req.get_header('Cookie') | ||
elif action == 'PUT': | ||
res = FakeResponse(sys.argv) | ||
hdr = urllib2.httplib.HTTPMessage(StringIO.StringIO('Set-Cookie: %s' % set_cookie)) | ||
res = urllib2.addinfourl(StringIO.StringIO(), hdr, req.get_full_url()) | ||
jar.extract_cookies(res,req) | ||
jar.save(ignore_discard=True) # save session cookies too | ||
#jar.save() # save everything but session cookies | ||
jar.save(ignore_discard=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.