{"action":"created","comment":{"url":"https://api.github.com/repos/shazow/urllib3/pulls/comments/62734836","id":62734836,"diff_hunk":"@@ -0,0 +1,87 @@\n+import time\n+\n+from ..packages.six.moves.http_cookiejar import(\n+    DefaultCookiePolicy as PythonCookiePolicy,\n+    CookieJar as PythonCookieJar\n+)\n+\n+\n+class DefaultCookiePolicy(PythonCookiePolicy):\n+    \"\"\"\n+    The default urllib3 cookie policy - similar to the Python default,\n+    but :param:`strict_ns_domain` is set to `DomainStrict` for security.\n+    \"\"\"\n+    def __init__(self, *args, **kwargs):\n+        policy = PythonCookiePolicy.DomainStrict\n+        kwargs.setdefault('strict_ns_domain', policy)\n+        # Old-style class on Python 2\n+        PythonCookiePolicy.__init__(self, *args, **kwargs)\n+\n+\n+class CookieJar(PythonCookieJar):\n+\n+    def __init__(self, policy=None):\n+        policy = policy or DefaultCookiePolicy()\n+        # Old-style class on Python 2\n+        PythonCookieJar.__init__(self, policy=policy)\n+\n+    def add_cookie_header(self, request):\n+        \"\"\"\n+        Add correct Cookie: header to Request object.\n+        This is copied from and slightly modified from the stdlib version.\n+        \"\"\"\n+        self._cookies_lock.acquire()\n+        try:\n+            self._policy._now = self._now = int(time.time())\n+            cookies = self._cookies_for_request(request)\n+            attrs = self._cookie_attrs(cookies)\n+            # This is a modification; stdlib sets the entire cookie header\n+            # and only if it's not there already. We're less picky.\n+            if attrs:\n+                request.add_cookies(*attrs)\n+        finally:\n+            self._cookies_lock.release()\n+        self.clear_expired_cookies()\n+\n+\n+class Context(object):\n+    \"\"\"\n+    Extensible class encapsulated by :class:`.SessionManager`; currently\n+    used to manage cookies.\n+\n+    :param cookie_jar:\n+        Used to pass a prebuilt :class:`http.cookiejar.CookieJar` into the\n+        context to be used instead of an empty jar.\n+    \"\"\"\n+\n+    def __init__(self, cookie_jar=None):\n+        # We unfortunately have to do it this way; empty cookie jars","path":"urllib3/util/context.py","position":58,"original_position":58,"commit_id":"ded386f240caffcd4f9b47db1c01a259f194ccc3","original_commit_id":"ded386f240caffcd4f9b47db1c01a259f194ccc3","user":{"login":"krishnamannem","id":9054726,"avatar_url":"https://avatars.githubusercontent.com/u/9054726?v=3","gravatar_id":"","url":"https://api.github.com/users/krishnamannem","html_url":"https://github.com/krishnamannem","followers_url":"https://api.github.com/users/krishnamannem/followers","following_url":"https://api.github.com/users/krishnamannem/following{/other_user}","gists_url":"https://api.github.com/users/krishnamannem/gists{/gist_id}","starred_url":"https://api.github.com/users/krishnamannem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krishnamannem/subscriptions","organizations_url":"https://api.github.com/users/krishnamannem/orgs","repos_url":"https://api.github.com/users/krishnamannem/repos","events_url":"https://api.github.com/users/krishnamannem/events{/privacy}","received_events_url":"https://api.github.com/users/krishnamannem/received_events","type":"User","site_admin":false},"body":"Not a pro at python but can we not minimize this by\r\n\r\n```\r\ndef __init__(self, cookie_jar=CookieJar()):\r\n      self.cookie_jar = cookie_jar\r\n```","created_at":"2016-05-10T19:18:33Z","updated_at":"2016-05-10T19:18:33Z","html_url":"https://github.com/shazow/urllib3/pull/849#discussion_r62734836","pull_request_url":"https://api.github.com/repos/shazow/urllib3/pulls/849","_links":{"self":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/comments/62734836"},"html":{"href":"https://github.com/shazow/urllib3/pull/849#discussion_r62734836"},"pull_request":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/849"}}},"pull_request":{"url":"https://api.github.com/repos/shazow/urllib3/pulls/849","id":67130610,"html_url":"https://github.com/shazow/urllib3/pull/849","diff_url":"https://github.com/shazow/urllib3/pull/849.diff","patch_url":"https://github.com/shazow/urllib3/pull/849.patch","issue_url":"https://api.github.com/repos/shazow/urllib3/issues/849","number":849,"state":"open","locked":false,"title":"Add session manager","user":{"login":"haikuginger","id":7773758,"avatar_url":"https://avatars.githubusercontent.com/u/7773758?v=3","gravatar_id":"","url":"https://api.github.com/users/haikuginger","html_url":"https://github.com/haikuginger","followers_url":"https://api.github.com/users/haikuginger/followers","following_url":"https://api.github.com/users/haikuginger/following{/other_user}","gists_url":"https://api.github.com/users/haikuginger/gists{/gist_id}","starred_url":"https://api.github.com/users/haikuginger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haikuginger/subscriptions","organizations_url":"https://api.github.com/users/haikuginger/orgs","repos_url":"https://api.github.com/users/haikuginger/repos","events_url":"https://api.github.com/users/haikuginger/events{/privacy}","received_events_url":"https://api.github.com/users/haikuginger/received_events","type":"User","site_admin":false},"body":"Implements #843; supersedes #844.","created_at":"2016-04-20T05:32:05Z","updated_at":"2016-05-10T19:18:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1505585ed8c4f695229845baf0c5edcd5b4d6e6b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/shazow/urllib3/pulls/849/commits","review_comments_url":"https://api.github.com/repos/shazow/urllib3/pulls/849/comments","review_comment_url":"https://api.github.com/repos/shazow/urllib3/pulls/comments{/number}","comments_url":"https://api.github.com/repos/shazow/urllib3/issues/849/comments","statuses_url":"https://api.github.com/repos/shazow/urllib3/statuses/ded386f240caffcd4f9b47db1c01a259f194ccc3","head":{"label":"haikuginger:add-session-manager","ref":"add-session-manager","sha":"ded386f240caffcd4f9b47db1c01a259f194ccc3","user":{"login":"haikuginger","id":7773758,"avatar_url":"https://avatars.githubusercontent.com/u/7773758?v=3","gravatar_id":"","url":"https://api.github.com/users/haikuginger","html_url":"https://github.com/haikuginger","followers_url":"https://api.github.com/users/haikuginger/followers","following_url":"https://api.github.com/users/haikuginger/following{/other_user}","gists_url":"https://api.github.com/users/haikuginger/gists{/gist_id}","starred_url":"https://api.github.com/users/haikuginger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haikuginger/subscriptions","organizations_url":"https://api.github.com/users/haikuginger/orgs","repos_url":"https://api.github.com/users/haikuginger/repos","events_url":"https://api.github.com/users/haikuginger/events{/privacy}","received_events_url":"https://api.github.com/users/haikuginger/received_events","type":"User","site_admin":false},"repo":{"id":54031804,"name":"urllib3","full_name":"haikuginger/urllib3","owner":{"login":"haikuginger","id":7773758,"avatar_url":"https://avatars.githubusercontent.com/u/7773758?v=3","gravatar_id":"","url":"https://api.github.com/users/haikuginger","html_url":"https://github.com/haikuginger","followers_url":"https://api.github.com/users/haikuginger/followers","following_url":"https://api.github.com/users/haikuginger/following{/other_user}","gists_url":"https://api.github.com/users/haikuginger/gists{/gist_id}","starred_url":"https://api.github.com/users/haikuginger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haikuginger/subscriptions","organizations_url":"https://api.github.com/users/haikuginger/orgs","repos_url":"https://api.github.com/users/haikuginger/repos","events_url":"https://api.github.com/users/haikuginger/events{/privacy}","received_events_url":"https://api.github.com/users/haikuginger/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/haikuginger/urllib3","description":"Python HTTP library with thread-safe connection pooling, file post support, sanity friendly, and more.","fork":true,"url":"https://api.github.com/repos/haikuginger/urllib3","forks_url":"https://api.github.com/repos/haikuginger/urllib3/forks","keys_url":"https://api.github.com/repos/haikuginger/urllib3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/haikuginger/urllib3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/haikuginger/urllib3/teams","hooks_url":"https://api.github.com/repos/haikuginger/urllib3/hooks","issue_events_url":"https://api.github.com/repos/haikuginger/urllib3/issues/events{/number}","events_url":"https://api.github.com/repos/haikuginger/urllib3/events","assignees_url":"https://api.github.com/repos/haikuginger/urllib3/assignees{/user}","branches_url":"https://api.github.com/repos/haikuginger/urllib3/branches{/branch}","tags_url":"https://api.github.com/repos/haikuginger/urllib3/tags","blobs_url":"https://api.github.com/repos/haikuginger/urllib3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/haikuginger/urllib3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/haikuginger/urllib3/git/refs{/sha}","trees_url":"https://api.github.com/repos/haikuginger/urllib3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/haikuginger/urllib3/statuses/{sha}","languages_url":"https://api.github.com/repos/haikuginger/urllib3/languages","stargazers_url":"https://api.github.com/repos/haikuginger/urllib3/stargazers","contributors_url":"https://api.github.com/repos/haikuginger/urllib3/contributors","subscribers_url":"https://api.github.com/repos/haikuginger/urllib3/subscribers","subscription_url":"https://api.github.com/repos/haikuginger/urllib3/subscription","commits_url":"https://api.github.com/repos/haikuginger/urllib3/commits{/sha}","git_commits_url":"https://api.github.com/repos/haikuginger/urllib3/git/commits{/sha}","comments_url":"https://api.github.com/repos/haikuginger/urllib3/comments{/number}","issue_comment_url":"https://api.github.com/repos/haikuginger/urllib3/issues/comments{/number}","contents_url":"https://api.github.com/repos/haikuginger/urllib3/contents/{+path}","compare_url":"https://api.github.com/repos/haikuginger/urllib3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/haikuginger/urllib3/merges","archive_url":"https://api.github.com/repos/haikuginger/urllib3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/haikuginger/urllib3/downloads","issues_url":"https://api.github.com/repos/haikuginger/urllib3/issues{/number}","pulls_url":"https://api.github.com/repos/haikuginger/urllib3/pulls{/number}","milestones_url":"https://api.github.com/repos/haikuginger/urllib3/milestones{/number}","notifications_url":"https://api.github.com/repos/haikuginger/urllib3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/haikuginger/urllib3/labels{/name}","releases_url":"https://api.github.com/repos/haikuginger/urllib3/releases{/id}","deployments_url":"https://api.github.com/repos/haikuginger/urllib3/deployments","created_at":"2016-03-16T12:56:31Z","updated_at":"2016-03-16T12:56:32Z","pushed_at":"2016-04-21T15:56:53Z","git_url":"git://github.com/haikuginger/urllib3.git","ssh_url":"git@github.com:haikuginger/urllib3.git","clone_url":"https://github.com/haikuginger/urllib3.git","svn_url":"https://github.com/haikuginger/urllib3","homepage":"http://urllib3.readthedocs.org/","size":2747,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"shazow:master","ref":"master","sha":"6891abfd084fed6624d4372e2c10c7a1cdbd0bf7","user":{"login":"shazow","id":6292,"avatar_url":"https://avatars.githubusercontent.com/u/6292?v=3","gravatar_id":"","url":"https://api.github.com/users/shazow","html_url":"https://github.com/shazow","followers_url":"https://api.github.com/users/shazow/followers","following_url":"https://api.github.com/users/shazow/following{/other_user}","gists_url":"https://api.github.com/users/shazow/gists{/gist_id}","starred_url":"https://api.github.com/users/shazow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shazow/subscriptions","organizations_url":"https://api.github.com/users/shazow/orgs","repos_url":"https://api.github.com/users/shazow/repos","events_url":"https://api.github.com/users/shazow/events{/privacy}","received_events_url":"https://api.github.com/users/shazow/received_events","type":"User","site_admin":false},"repo":{"id":2410676,"name":"urllib3","full_name":"shazow/urllib3","owner":{"login":"shazow","id":6292,"avatar_url":"https://avatars.githubusercontent.com/u/6292?v=3","gravatar_id":"","url":"https://api.github.com/users/shazow","html_url":"https://github.com/shazow","followers_url":"https://api.github.com/users/shazow/followers","following_url":"https://api.github.com/users/shazow/following{/other_user}","gists_url":"https://api.github.com/users/shazow/gists{/gist_id}","starred_url":"https://api.github.com/users/shazow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shazow/subscriptions","organizations_url":"https://api.github.com/users/shazow/orgs","repos_url":"https://api.github.com/users/shazow/repos","events_url":"https://api.github.com/users/shazow/events{/privacy}","received_events_url":"https://api.github.com/users/shazow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shazow/urllib3","description":"Python HTTP library with thread-safe connection pooling, file post support, sanity friendly, and more.","fork":false,"url":"https://api.github.com/repos/shazow/urllib3","forks_url":"https://api.github.com/repos/shazow/urllib3/forks","keys_url":"https://api.github.com/repos/shazow/urllib3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shazow/urllib3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shazow/urllib3/teams","hooks_url":"https://api.github.com/repos/shazow/urllib3/hooks","issue_events_url":"https://api.github.com/repos/shazow/urllib3/issues/events{/number}","events_url":"https://api.github.com/repos/shazow/urllib3/events","assignees_url":"https://api.github.com/repos/shazow/urllib3/assignees{/user}","branches_url":"https://api.github.com/repos/shazow/urllib3/branches{/branch}","tags_url":"https://api.github.com/repos/shazow/urllib3/tags","blobs_url":"https://api.github.com/repos/shazow/urllib3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shazow/urllib3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shazow/urllib3/git/refs{/sha}","trees_url":"https://api.github.com/repos/shazow/urllib3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shazow/urllib3/statuses/{sha}","languages_url":"https://api.github.com/repos/shazow/urllib3/languages","stargazers_url":"https://api.github.com/repos/shazow/urllib3/stargazers","contributors_url":"https://api.github.com/repos/shazow/urllib3/contributors","subscribers_url":"https://api.github.com/repos/shazow/urllib3/subscribers","subscription_url":"https://api.github.com/repos/shazow/urllib3/subscription","commits_url":"https://api.github.com/repos/shazow/urllib3/commits{/sha}","git_commits_url":"https://api.github.com/repos/shazow/urllib3/git/commits{/sha}","comments_url":"https://api.github.com/repos/shazow/urllib3/comments{/number}","issue_comment_url":"https://api.github.com/repos/shazow/urllib3/issues/comments{/number}","contents_url":"https://api.github.com/repos/shazow/urllib3/contents/{+path}","compare_url":"https://api.github.com/repos/shazow/urllib3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shazow/urllib3/merges","archive_url":"https://api.github.com/repos/shazow/urllib3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shazow/urllib3/downloads","issues_url":"https://api.github.com/repos/shazow/urllib3/issues{/number}","pulls_url":"https://api.github.com/repos/shazow/urllib3/pulls{/number}","milestones_url":"https://api.github.com/repos/shazow/urllib3/milestones{/number}","notifications_url":"https://api.github.com/repos/shazow/urllib3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shazow/urllib3/labels{/name}","releases_url":"https://api.github.com/repos/shazow/urllib3/releases{/id}","deployments_url":"https://api.github.com/repos/shazow/urllib3/deployments","created_at":"2011-09-18T18:08:28Z","updated_at":"2016-05-09T03:40:15Z","pushed_at":"2016-05-10T01:31:29Z","git_url":"git://github.com/shazow/urllib3.git","ssh_url":"git@github.com:shazow/urllib3.git","clone_url":"https://github.com/shazow/urllib3.git","svn_url":"https://github.com/shazow/urllib3","homepage":"http://urllib3.readthedocs.org/","size":4750,"stargazers_count":1037,"watchers_count":1037,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":336,"mirror_url":null,"open_issues_count":102,"forks":336,"open_issues":102,"watchers":1037,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/849"},"html":{"href":"https://github.com/shazow/urllib3/pull/849"},"issue":{"href":"https://api.github.com/repos/shazow/urllib3/issues/849"},"comments":{"href":"https://api.github.com/repos/shazow/urllib3/issues/849/comments"},"review_comments":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/849/comments"},"review_comment":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/shazow/urllib3/pulls/849/commits"},"statuses":{"href":"https://api.github.com/repos/shazow/urllib3/statuses/ded386f240caffcd4f9b47db1c01a259f194ccc3"}}}}