Store only cookies having names beginning with X-APPLE-WEB-KB; cache copied request cookies as _cookies rather than mutable reference.

This commit is contained in:
Adam Coddington 2015-05-24 14:49:59 -07:00
parent b0d3985a50
commit f7f1cba66a

View file

@ -1,3 +1,4 @@
import copy
import uuid import uuid
import hashlib import hashlib
import json import json
@ -163,11 +164,17 @@ class PyiCloudService(object):
def _update_cookie(self, request): def _update_cookie(self, request):
cookiefile = self._get_cookie_path() cookiefile = self._get_cookie_path()
# We really only want to keep the cookies having names
# starting with 'X-APPLE-WEB-KB'
for cookie_name, value in request.cookies.items():
if not cookie_name.startswith('X-APPLE-WEB-KB'):
del request.cookies[cookie_name]
# Save the cookie in a pickle file # Save the cookie in a pickle file
with open(cookiefile, 'wb') as f: with open(cookiefile, 'wb') as f:
pickle.dump(request.cookies, f) pickle.dump(request.cookies, f)
self._cookies = request.cookies self._cookies = copy.deepcopy(request.cookies)
@property @property
def devices(self): def devices(self):