diff -r c0b0e7aef360 -r df24375f3321 Lib/http/cookiejar.py --- a/Lib/http/cookiejar.py Tue Jan 07 23:29:19 2014 -0700 +++ b/Lib/http/cookiejar.py Wed Feb 05 10:38:22 2014 +0100 @@ -1,3 +1,4 @@ + r"""HTTP cookie handling for web clients. This module has (now fairly distant) origins in Gisle Aas' Perl module @@ -11,17 +12,17 @@ distributed with the Python standard library, but are available from http://wwwsearch.sf.net/): - CookieJar____ - / \ \ - FileCookieJar \ \ - / | \ \ \ - MozillaCookieJar | LWPCookieJar \ \ - | | \ - | ---MSIEBase | \ - | / | | \ - | / MSIEDBCookieJar BSDDBCookieJar - |/ - MSIECookieJar + CookieJar____ + / \ \ + FileCookieJar \ \ + / / | \ \ \ + SafariCookieJar / | LWPCookieJar \ \ + / | | \ + MozillaCookieJar | ---MSIEBase | \ + | / | | \ + | / MSIEDBCookieJar BSDDBCookieJar + |/ + MSIECookieJar """ @@ -31,8 +32,11 @@ import copy import datetime import re +import getpass import time import urllib.parse, urllib.request +import struct +import io try: import threading as _threading except ImportError: @@ -40,6 +44,9 @@ import http.client # only for the default HTTP port from calendar import timegm +import difflib +#from difflib_data import * + debug = False # set to True to enable debugging via the logging module logger = None @@ -1938,6 +1945,109 @@ raise LoadError("invalid Set-Cookie3 format file %r: %r" % (filename, line)) +class SafariCookieJar(FileCookieJar): + """ + Read Cookies from Safari + + """ + def load(self, filename=None): + if filename == None: + username = getpass.getuser() + path = '/Users/' + username + '/Library/Cookies/Cookies.binarycookies' + else: + path = filename + + bf=open(path,mode='rb') + scook = bf.read(4).decode("UTF-8") + if scook == 'cook': + NumberOfPages=struct.unpack('>i',bf.read(4))[0] + page_sizes=[] + for np in range(NumberOfPages): + page_sizes.append(struct.unpack('>i',bf.read(4))[0]) + pages=[] + for ps in page_sizes: + pages.append(bf.read(ps)) + + for page in pages: + page=io.BytesIO(page) + page.read(4) + num_cookies=struct.unpack('