requests cookies behaving
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 14bd9eb · Browse files · 2 files·+20 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+20 added−13 removed
- other:+20 added−13 removed
Provenance
- Commit
5c132c9- Tree
401a6eb- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
14bd9eb
2 files changed+20 added−13 removed
modified:requests/models.py+2 added-10 removed
162 unmodified lines163 history = []164 165 # Create the lone response object.166 r = build(resp)167+ self.cookies.update(r.cookies)168 169 # Store the HTTP response, just in case.170 r._response = resp171 64 unmodified lines236 237 # Send her away!238 request.send()239 r = request.response240+ self.cookies.update(r.cookies)241 242 # Insert collected history.243 r.history = history244 100 unmodified lines345 # Set the pools manager for redirections, if allowed.346 if self.config.get('keepalive') and pools:347 self._pools = pools348 347- # Extract cookies.348- if self.cookies is not None:349- pass350- # cookies = cookiejar_from_dict(self.cookies)351-# >>> C = Cookie.SimpleCookie()352-# >>> C["rocky"] = "road"353-# >>> C["rocky"]["path"] = "/cookie"354-# >>> print C.output(header="Cookie:")355-# Cookie: rocky=road; Path=/cookie356- # self.cookiejar.extract_cookies(resp, req)349 350 # except (urllib2.HTTPError, urllib2.URLError), why:351 except Exception, why:352 print why.__dict__148 unmodified linesmodified:requests/sessions.py+18 added-3 removed
56 unmodified lines57 hooks=None,58 config=None):59 60 self.headers = headers61- self.cookies = cookies61+ self.cookies = cookies or {}62 self.auth = auth63 self.timeout = timeout64 self.proxies = proxies65 self.hooks = hooks29 unmodified lines95 _kwargs = {}96 97 # Merge local and session arguments.98 for attr in self.__attrs__:99+ # if attr == 'cookies':100+ # print getattr(self, attr)101+ # print kwargs.get(attr)102+103+ # Merge local and session dictionaries.104 default_attr = getattr(self, attr)105 local_attr = kwargs.get(attr)106 102- # Merge local and session dictionaries.107+ # Cookies persist.108+ if attr == 'cookies':109+ local_attr = local_attr or {}110+111 new_attr = merge_kwargs(local_attr, default_attr)112 113 # Skip attributes that were set to None.114 if new_attr is not None:8 unmodified lines123 if self.config.get('keepalive'):124 _kwargs['_pools'] = self.__pools125 126 # TODO: Persist cookies.127+ # print self.cookies128 129+ # print _kwargs.get('cookies')130+ # print '%%%'131+120- return func(*args, **_kwargs)132+ r = func(*args, **_kwargs)133+ # print r.cookies134+ self.cookies.update(r.cookies)135+ return r136 return wrapper_func137 138 # Map and decorate each function available in requests.api139 map(lambda fn: setattr(self, fn, pass_args(getattr(api, fn))), api.__all__)6 unmodified lines