We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support load/save cookie_jar
I found that cookie_jar do not provide any function to _load or save cookie_jar_

Is there any pythonic way to implement  these two method?

```
session.cookie_jar.load('foo.cookie.txt')
....# do sth.
session.cookie_jar.save()

```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `aiohttp/cookiejar.py`
Content:
```
1 import datetime
2 import re
3 from collections import defaultdict
4 from collections.abc import Mapping
5 from http.cookies import Morsel, SimpleCookie
6 from math import ceil
7 
8 from yarl import URL
9 
10 from .abc import AbstractCookieJar
11 from .helpers import is_ip_address
12 
13 
14 class CookieJar(AbstractCookieJar):
15     """Implements cookie storage adhering to RFC 6265."""
16 
17     DATE_TOKENS_RE = re.compile(
18         "[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]*"
19         "(?P<token>[\x00-\x08\x0A-\x1F\d:a-zA-Z\x7F-\xFF]+)")
20 
21     DATE_HMS_TIME_RE = re.compile("(\d{1,2}):(\d{1,2}):(\d{1,2})")
22 
23     DATE_DAY_OF_MONTH_RE = re.compile("(\d{1,2})")
24 
25     DATE_MONTH_RE = re.compile("(jan)|(feb)|(mar)|(apr)|(may)|(jun)|(jul)|"
26                                "(aug)|(sep)|(oct)|(nov)|(dec)", re.I)
27 
28     DATE_YEAR_RE = re.compile("(\d{2,4})")
29 
30     MAX_TIME = 2051215261.0  # so far in future (2035-01-01)
31 
32     def __init__(self, *, unsafe=False, loop=None):
33         super().__init__(loop=loop)
34         self._cookies = defaultdict(SimpleCookie)
35         self._host_only_cookies = set()
36         self._unsafe = unsafe
37         self._next_expiration = ceil(self._loop.time())
38         self._expirations = {}
39 
40     def clear(self):
41         self._cookies.clear()
42         self._host_only_cookies.clear()
43         self._next_expiration = ceil(self._loop.time())
44         self._expirations.clear()
45 
46     def __iter__(self):
47         self._do_expiration()
48         for val in self._cookies.values():
49             yield from val.values()
50 
51     def __len__(self):
52         return sum(1 for i in self)
53 
54     def _do_expiration(self):
55         now = self._loop.time()
56         if self._next_expiration > now:
57             return
58         if not self._expirations:
59             return
60         next_expiration = self.MAX_TIME
61         to_del = []
62         cookies = self._cookies
63         expirations = self._expirations
64         for (domain, name), when in expirations.items():
65             if when < now:
66                 cookies[domain].pop(name, None)
67                 to_del.append((domain, name))
68                 self._host_only_cookies.discard((domain, name))
69             else:
70                 next_expiration = min(next_expiration, when)
71         for key in to_del:
72             del expirations[key]
73 
74         self._next_expiration = ceil(next_expiration)
75 
76     def _expire_cookie(self, when, domain, name):
77         self._next_expiration = min(self._next_expiration, when)
78         self._expirations[(domain, name)] = when
79 
80     def update_cookies(self, cookies, response_url=URL()):
81         """Update cookies."""
82         hostname = response_url.host
83 
84         if not self._unsafe and is_ip_address(hostname):
85             # Don't accept cookies from IPs
86             return
87 
88         if isinstance(cookies, Mapping):
89             cookies = cookies.items()
90 
91         for name, cookie in cookies:
92             if not isinstance(cookie, Morsel):
93                 tmp = SimpleCookie()
94                 tmp[name] = cookie
95                 cookie = tmp[name]
96 
97             domain = cookie["domain"]
98 
99             # ignore domains with trailing dots
100             if domain.endswith('.'):
101                 domain = ""
102                 del cookie["domain"]
103 
104             if not domain and hostname is not None:
105                 # Set the cookie's domain to the response hostname
106                 # and set its host-only-flag
107                 self._host_only_cookies.add((hostname, name))
108                 domain = cookie["domain"] = hostname
109 
110             if domain.startswith("."):
111                 # Remove leading dot
112                 domain = domain[1:]
113                 cookie["domain"] = domain
114 
115             if hostname and not self._is_domain_match(domain, hostname):
116                 # Setting cookies for different domains is not allowed
117                 continue
118 
119             path = cookie["path"]
120             if not path or not path.startswith("/"):
121                 # Set the cookie's path to the response path
122                 path = response_url.path
123                 if not path.startswith("/"):
124                     path = "/"
125                 else:
126                     # Cut everything from the last slash to the end
127                     path = "/" + path[1:path.rfind("/")]
128                 cookie["path"] = path
129 
130             max_age = cookie["max-age"]
131             if max_age:
132                 try:
133                     delta_seconds = int(max_age)
134                     self._expire_cookie(self._loop.time() + delta_seconds,
135                                         domain, name)
136                 except ValueError:
137                     cookie["max-age"] = ""
138 
139             else:
140                 expires = cookie["expires"]
141                 if expires:
142                     expire_time = self._parse_date(expires)
143                     if expire_time:
144                         self._expire_cookie(expire_time.timestamp(),
145                                             domain, name)
146                     else:
147                         cookie["expires"] = ""
148 
149             # use dict method because SimpleCookie class modifies value
150             # before Python 3.4.3
151             dict.__setitem__(self._cookies[domain], name, cookie)
152 
153         self._do_expiration()
154 
155     def filter_cookies(self, request_url=URL()):
156         """Returns this jar's cookies filtered by their attributes."""
157         self._do_expiration()
158         filtered = SimpleCookie()
159         hostname = request_url.host or ""
160         is_not_secure = request_url.scheme not in ("https", "wss")
161 
162         for cookie in self:
163             name = cookie.key
164             domain = cookie["domain"]
165 
166             # Send shared cookies
167             if not domain:
168                 filtered[name] = cookie.value
169                 continue
170 
171             if not self._unsafe and is_ip_address(hostname):
172                 continue
173 
174             if (domain, name) in self._host_only_cookies:
175                 if domain != hostname:
176                     continue
177             elif not self._is_domain_match(domain, hostname):
178                 continue
179 
180             if not self._is_path_match(request_url.path, cookie["path"]):
181                 continue
182 
183             if is_not_secure and cookie["secure"]:
184                 continue
185 
186             filtered[name] = cookie.value
187 
188         return filtered
189 
190     @staticmethod
191     def _is_domain_match(domain, hostname):
192         """Implements domain matching adhering to RFC 6265."""
193         if hostname == domain:
194             return True
195 
196         if not hostname.endswith(domain):
197             return False
198 
199         non_matching = hostname[:-len(domain)]
200 
201         if not non_matching.endswith("."):
202             return False
203 
204         return not is_ip_address(hostname)
205 
206     @staticmethod
207     def _is_path_match(req_path, cookie_path):
208         """Implements path matching adhering to RFC 6265."""
209         if not req_path.startswith("/"):
210             req_path = "/"
211 
212         if req_path == cookie_path:
213             return True
214 
215         if not req_path.startswith(cookie_path):
216             return False
217 
218         if cookie_path.endswith("/"):
219             return True
220 
221         non_matching = req_path[len(cookie_path):]
222 
223         return non_matching.startswith("/")
224 
225     @classmethod
226     def _parse_date(cls, date_str):
227         """Implements date string parsing adhering to RFC 6265."""
228         if not date_str:
229             return
230 
231         found_time = False
232         found_day = False
233         found_month = False
234         found_year = False
235 
236         hour = minute = second = 0
237         day = 0
238         month = 0
239         year = 0
240 
241         for token_match in cls.DATE_TOKENS_RE.finditer(date_str):
242 
243             token = token_match.group("token")
244 
245             if not found_time:
246                 time_match = cls.DATE_HMS_TIME_RE.match(token)
247                 if time_match:
248                     found_time = True
249                     hour, minute, second = [
250                         int(s) for s in time_match.groups()]
251                     continue
252 
253             if not found_day:
254                 day_match = cls.DATE_DAY_OF_MONTH_RE.match(token)
255                 if day_match:
256                     found_day = True
257                     day = int(day_match.group())
258                     continue
259 
260             if not found_month:
261                 month_match = cls.DATE_MONTH_RE.match(token)
262                 if month_match:
263                     found_month = True
264                     month = month_match.lastindex
265                     continue
266 
267             if not found_year:
268                 year_match = cls.DATE_YEAR_RE.match(token)
269                 if year_match:
270                     found_year = True
271                     year = int(year_match.group())
272 
273         if 70 <= year <= 99:
274             year += 1900
275         elif 0 <= year <= 69:
276             year += 2000
277 
278         if False in (found_day, found_month, found_year, found_time):
279             return
280 
281         if not 1 <= day <= 31:
282             return
283 
284         if year < 1601 or hour > 23 or minute > 59 or second > 59:
285             return
286 
287         return datetime.datetime(year, month, day,
288                                  hour, minute, second,
289                                  tzinfo=datetime.timezone.utc)
290
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/aiohttp/cookiejar.py b/aiohttp/cookiejar.py
--- a/aiohttp/cookiejar.py
+++ b/aiohttp/cookiejar.py
@@ -1,4 +1,6 @@
 import datetime
+import pathlib
+import pickle
 import re
 from collections import defaultdict
 from collections.abc import Mapping
@@ -37,6 +39,16 @@
         self._next_expiration = ceil(self._loop.time())
         self._expirations = {}
 
+    def save(self, file_path):
+        file_path = pathlib.Path(file_path)
+        with file_path.open(mode='wb') as f:
+            pickle.dump(self._cookies, f, pickle.HIGHEST_PROTOCOL)
+
+    def load(self, file_path):
+        file_path = pathlib.Path(file_path)
+        with file_path.open(mode='rb') as f:
+            self._cookies = pickle.load(f)
+
     def clear(self):
         self._cookies.clear()
         self._host_only_cookies.clear()

{"golden_diff": "diff --git a/aiohttp/cookiejar.py b/aiohttp/cookiejar.py\n--- a/aiohttp/cookiejar.py\n+++ b/aiohttp/cookiejar.py\n@@ -1,4 +1,6 @@\n import datetime\n+import pathlib\n+import pickle\n import re\n from collections import defaultdict\n from collections.abc import Mapping\n@@ -37,6 +39,16 @@\n         self._next_expiration = ceil(self._loop.time())\n         self._expirations = {}\n \n+    def save(self, file_path):\n+        file_path = pathlib.Path(file_path)\n+        with file_path.open(mode='wb') as f:\n+            pickle.dump(self._cookies, f, pickle.HIGHEST_PROTOCOL)\n+\n+    def load(self, file_path):\n+        file_path = pathlib.Path(file_path)\n+        with file_path.open(mode='rb') as f:\n+            self._cookies = pickle.load(f)\n+\n     def clear(self):\n         self._cookies.clear()\n         self._host_only_cookies.clear()\n", "issue": "Support load/save cookie_jar\nI found that cookie_jar do not provide any function to _load or save cookie_jar_\n\nIs there any pythonic way to implement  these two method?\n\n```\nsession.cookie_jar.load('foo.cookie.txt')\n....# do sth.\nsession.cookie_jar.save()\n\n```\n\n", "before_files": [{"content": "import datetime\nimport re\nfrom collections import defaultdict\nfrom collections.abc import Mapping\nfrom http.cookies import Morsel, SimpleCookie\nfrom math import ceil\n\nfrom yarl import URL\n\nfrom .abc import AbstractCookieJar\nfrom .helpers import is_ip_address\n\n\nclass CookieJar(AbstractCookieJar):\n    \"\"\"Implements cookie storage adhering to RFC 6265.\"\"\"\n\n    DATE_TOKENS_RE = re.compile(\n        \"[\\x09\\x20-\\x2F\\x3B-\\x40\\x5B-\\x60\\x7B-\\x7E]*\"\n        \"(?P<token>[\\x00-\\x08\\x0A-\\x1F\\d:a-zA-Z\\x7F-\\xFF]+)\")\n\n    DATE_HMS_TIME_RE = re.compile(\"(\\d{1,2}):(\\d{1,2}):(\\d{1,2})\")\n\n    DATE_DAY_OF_MONTH_RE = re.compile(\"(\\d{1,2})\")\n\n    DATE_MONTH_RE = re.compile(\"(jan)|(feb)|(mar)|(apr)|(may)|(jun)|(jul)|\"\n                               \"(aug)|(sep)|(oct)|(nov)|(dec)\", re.I)\n\n    DATE_YEAR_RE = re.compile(\"(\\d{2,4})\")\n\n    MAX_TIME = 2051215261.0  # so far in future (2035-01-01)\n\n    def __init__(self, *, unsafe=False, loop=None):\n        super().__init__(loop=loop)\n        self._cookies = defaultdict(SimpleCookie)\n        self._host_only_cookies = set()\n        self._unsafe = unsafe\n        self._next_expiration = ceil(self._loop.time())\n        self._expirations = {}\n\n    def clear(self):\n        self._cookies.clear()\n        self._host_only_cookies.clear()\n        self._next_expiration = ceil(self._loop.time())\n        self._expirations.clear()\n\n    def __iter__(self):\n        self._do_expiration()\n        for val in self._cookies.values():\n            yield from val.values()\n\n    def __len__(self):\n        return sum(1 for i in self)\n\n    def _do_expiration(self):\n        now = self._loop.time()\n        if self._next_expiration > now:\n            return\n        if not self._expirations:\n            return\n        next_expiration = self.MAX_TIME\n        to_del = []\n        cookies = self._cookies\n        expirations = self._expirations\n        for (domain, name), when in expirations.items():\n            if when < now:\n                cookies[domain].pop(name, None)\n                to_del.append((domain, name))\n                self._host_only_cookies.discard((domain, name))\n            else:\n                next_expiration = min(next_expiration, when)\n        for key in to_del:\n            del expirations[key]\n\n        self._next_expiration = ceil(next_expiration)\n\n    def _expire_cookie(self, when, domain, name):\n        self._next_expiration = min(self._next_expiration, when)\n        self._expirations[(domain, name)] = when\n\n    def update_cookies(self, cookies, response_url=URL()):\n        \"\"\"Update cookies.\"\"\"\n        hostname = response_url.host\n\n        if not self._unsafe and is_ip_address(hostname):\n            # Don't accept cookies from IPs\n            return\n\n        if isinstance(cookies, Mapping):\n            cookies = cookies.items()\n\n        for name, cookie in cookies:\n            if not isinstance(cookie, Morsel):\n                tmp = SimpleCookie()\n                tmp[name] = cookie\n                cookie = tmp[name]\n\n            domain = cookie[\"domain\"]\n\n            # ignore domains with trailing dots\n            if domain.endswith('.'):\n                domain = \"\"\n                del cookie[\"domain\"]\n\n            if not domain and hostname is not None:\n                # Set the cookie's domain to the response hostname\n                # and set its host-only-flag\n                self._host_only_cookies.add((hostname, name))\n                domain = cookie[\"domain\"] = hostname\n\n            if domain.startswith(\".\"):\n                # Remove leading dot\n                domain = domain[1:]\n                cookie[\"domain\"] = domain\n\n            if hostname and not self._is_domain_match(domain, hostname):\n                # Setting cookies for different domains is not allowed\n                continue\n\n            path = cookie[\"path\"]\n            if not path or not path.startswith(\"/\"):\n                # Set the cookie's path to the response path\n                path = response_url.path\n                if not path.startswith(\"/\"):\n                    path = \"/\"\n                else:\n                    # Cut everything from the last slash to the end\n                    path = \"/\" + path[1:path.rfind(\"/\")]\n                cookie[\"path\"] = path\n\n            max_age = cookie[\"max-age\"]\n            if max_age:\n                try:\n                    delta_seconds = int(max_age)\n                    self._expire_cookie(self._loop.time() + delta_seconds,\n                                        domain, name)\n                except ValueError:\n                    cookie[\"max-age\"] = \"\"\n\n            else:\n                expires = cookie[\"expires\"]\n                if expires:\n                    expire_time = self._parse_date(expires)\n                    if expire_time:\n                        self._expire_cookie(expire_time.timestamp(),\n                                            domain, name)\n                    else:\n                        cookie[\"expires\"] = \"\"\n\n            # use dict method because SimpleCookie class modifies value\n            # before Python 3.4.3\n            dict.__setitem__(self._cookies[domain], name, cookie)\n\n        self._do_expiration()\n\n    def filter_cookies(self, request_url=URL()):\n        \"\"\"Returns this jar's cookies filtered by their attributes.\"\"\"\n        self._do_expiration()\n        filtered = SimpleCookie()\n        hostname = request_url.host or \"\"\n        is_not_secure = request_url.scheme not in (\"https\", \"wss\")\n\n        for cookie in self:\n            name = cookie.key\n            domain = cookie[\"domain\"]\n\n            # Send shared cookies\n            if not domain:\n                filtered[name] = cookie.value\n                continue\n\n            if not self._unsafe and is_ip_address(hostname):\n                continue\n\n            if (domain, name) in self._host_only_cookies:\n                if domain != hostname:\n                    continue\n            elif not self._is_domain_match(domain, hostname):\n                continue\n\n            if not self._is_path_match(request_url.path, cookie[\"path\"]):\n                continue\n\n            if is_not_secure and cookie[\"secure\"]:\n                continue\n\n            filtered[name] = cookie.value\n\n        return filtered\n\n    @staticmethod\n    def _is_domain_match(domain, hostname):\n        \"\"\"Implements domain matching adhering to RFC 6265.\"\"\"\n        if hostname == domain:\n            return True\n\n        if not hostname.endswith(domain):\n            return False\n\n        non_matching = hostname[:-len(domain)]\n\n        if not non_matching.endswith(\".\"):\n            return False\n\n        return not is_ip_address(hostname)\n\n    @staticmethod\n    def _is_path_match(req_path, cookie_path):\n        \"\"\"Implements path matching adhering to RFC 6265.\"\"\"\n        if not req_path.startswith(\"/\"):\n            req_path = \"/\"\n\n        if req_path == cookie_path:\n            return True\n\n        if not req_path.startswith(cookie_path):\n            return False\n\n        if cookie_path.endswith(\"/\"):\n            return True\n\n        non_matching = req_path[len(cookie_path):]\n\n        return non_matching.startswith(\"/\")\n\n    @classmethod\n    def _parse_date(cls, date_str):\n        \"\"\"Implements date string parsing adhering to RFC 6265.\"\"\"\n        if not date_str:\n            return\n\n        found_time = False\n        found_day = False\n        found_month = False\n        found_year = False\n\n        hour = minute = second = 0\n        day = 0\n        month = 0\n        year = 0\n\n        for token_match in cls.DATE_TOKENS_RE.finditer(date_str):\n\n            token = token_match.group(\"token\")\n\n            if not found_time:\n                time_match = cls.DATE_HMS_TIME_RE.match(token)\n                if time_match:\n                    found_time = True\n                    hour, minute, second = [\n                        int(s) for s in time_match.groups()]\n                    continue\n\n            if not found_day:\n                day_match = cls.DATE_DAY_OF_MONTH_RE.match(token)\n                if day_match:\n                    found_day = True\n                    day = int(day_match.group())\n                    continue\n\n            if not found_month:\n                month_match = cls.DATE_MONTH_RE.match(token)\n                if month_match:\n                    found_month = True\n                    month = month_match.lastindex\n                    continue\n\n            if not found_year:\n                year_match = cls.DATE_YEAR_RE.match(token)\n                if year_match:\n                    found_year = True\n                    year = int(year_match.group())\n\n        if 70 <= year <= 99:\n            year += 1900\n        elif 0 <= year <= 69:\n            year += 2000\n\n        if False in (found_day, found_month, found_year, found_time):\n            return\n\n        if not 1 <= day <= 31:\n            return\n\n        if year < 1601 or hour > 23 or minute > 59 or second > 59:\n            return\n\n        return datetime.datetime(year, month, day,\n                                 hour, minute, second,\n                                 tzinfo=datetime.timezone.utc)\n", "path": "aiohttp/cookiejar.py"}], "after_files": [{"content": "import datetime\nimport pathlib\nimport pickle\nimport re\nfrom collections import defaultdict\nfrom collections.abc import Mapping\nfrom http.cookies import Morsel, SimpleCookie\nfrom math import ceil\n\nfrom yarl import URL\n\nfrom .abc import AbstractCookieJar\nfrom .helpers import is_ip_address\n\n\nclass CookieJar(AbstractCookieJar):\n    \"\"\"Implements cookie storage adhering to RFC 6265.\"\"\"\n\n    DATE_TOKENS_RE = re.compile(\n        \"[\\x09\\x20-\\x2F\\x3B-\\x40\\x5B-\\x60\\x7B-\\x7E]*\"\n        \"(?P<token>[\\x00-\\x08\\x0A-\\x1F\\d:a-zA-Z\\x7F-\\xFF]+)\")\n\n    DATE_HMS_TIME_RE = re.compile(\"(\\d{1,2}):(\\d{1,2}):(\\d{1,2})\")\n\n    DATE_DAY_OF_MONTH_RE = re.compile(\"(\\d{1,2})\")\n\n    DATE_MONTH_RE = re.compile(\"(jan)|(feb)|(mar)|(apr)|(may)|(jun)|(jul)|\"\n                               \"(aug)|(sep)|(oct)|(nov)|(dec)\", re.I)\n\n    DATE_YEAR_RE = re.compile(\"(\\d{2,4})\")\n\n    MAX_TIME = 2051215261.0  # so far in future (2035-01-01)\n\n    def __init__(self, *, unsafe=False, loop=None):\n        super().__init__(loop=loop)\n        self._cookies = defaultdict(SimpleCookie)\n        self._host_only_cookies = set()\n        self._unsafe = unsafe\n        self._next_expiration = ceil(self._loop.time())\n        self._expirations = {}\n\n    def save(self, file_path):\n        file_path = pathlib.Path(file_path)\n        with file_path.open(mode='wb') as f:\n            pickle.dump(self._cookies, f, pickle.HIGHEST_PROTOCOL)\n\n    def load(self, file_path):\n        file_path = pathlib.Path(file_path)\n        with file_path.open(mode='rb') as f:\n            self._cookies = pickle.load(f)\n\n    def clear(self):\n        self._cookies.clear()\n        self._host_only_cookies.clear()\n        self._next_expiration = ceil(self._loop.time())\n        self._expirations.clear()\n\n    def __iter__(self):\n        self._do_expiration()\n        for val in self._cookies.values():\n            yield from val.values()\n\n    def __len__(self):\n        return sum(1 for i in self)\n\n    def _do_expiration(self):\n        now = self._loop.time()\n        if self._next_expiration > now:\n            return\n        if not self._expirations:\n            return\n        next_expiration = self.MAX_TIME\n        to_del = []\n        cookies = self._cookies\n        expirations = self._expirations\n        for (domain, name), when in expirations.items():\n            if when < now:\n                cookies[domain].pop(name, None)\n                to_del.append((domain, name))\n                self._host_only_cookies.discard((domain, name))\n            else:\n                next_expiration = min(next_expiration, when)\n        for key in to_del:\n            del expirations[key]\n\n        self._next_expiration = ceil(next_expiration)\n\n    def _expire_cookie(self, when, domain, name):\n        self._next_expiration = min(self._next_expiration, when)\n        self._expirations[(domain, name)] = when\n\n    def update_cookies(self, cookies, response_url=URL()):\n        \"\"\"Update cookies.\"\"\"\n        hostname = response_url.host\n\n        if not self._unsafe and is_ip_address(hostname):\n            # Don't accept cookies from IPs\n            return\n\n        if isinstance(cookies, Mapping):\n            cookies = cookies.items()\n\n        for name, cookie in cookies:\n            if not isinstance(cookie, Morsel):\n                tmp = SimpleCookie()\n                tmp[name] = cookie\n                cookie = tmp[name]\n\n            domain = cookie[\"domain\"]\n\n            # ignore domains with trailing dots\n            if domain.endswith('.'):\n                domain = \"\"\n                del cookie[\"domain\"]\n\n            if not domain and hostname is not None:\n                # Set the cookie's domain to the response hostname\n                # and set its host-only-flag\n                self._host_only_cookies.add((hostname, name))\n                domain = cookie[\"domain\"] = hostname\n\n            if domain.startswith(\".\"):\n                # Remove leading dot\n                domain = domain[1:]\n                cookie[\"domain\"] = domain\n\n            if hostname and not self._is_domain_match(domain, hostname):\n                # Setting cookies for different domains is not allowed\n                continue\n\n            path = cookie[\"path\"]\n            if not path or not path.startswith(\"/\"):\n                # Set the cookie's path to the response path\n                path = response_url.path\n                if not path.startswith(\"/\"):\n                    path = \"/\"\n                else:\n                    # Cut everything from the last slash to the end\n                    path = \"/\" + path[1:path.rfind(\"/\")]\n                cookie[\"path\"] = path\n\n            max_age = cookie[\"max-age\"]\n            if max_age:\n                try:\n                    delta_seconds = int(max_age)\n                    self._expire_cookie(self._loop.time() + delta_seconds,\n                                        domain, name)\n                except ValueError:\n                    cookie[\"max-age\"] = \"\"\n\n            else:\n                expires = cookie[\"expires\"]\n                if expires:\n                    expire_time = self._parse_date(expires)\n                    if expire_time:\n                        self._expire_cookie(expire_time.timestamp(),\n                                            domain, name)\n                    else:\n                        cookie[\"expires\"] = \"\"\n\n            # use dict method because SimpleCookie class modifies value\n            # before Python 3.4.3\n            dict.__setitem__(self._cookies[domain], name, cookie)\n\n        self._do_expiration()\n\n    def filter_cookies(self, request_url=URL()):\n        \"\"\"Returns this jar's cookies filtered by their attributes.\"\"\"\n        self._do_expiration()\n        filtered = SimpleCookie()\n        hostname = request_url.host or \"\"\n        is_not_secure = request_url.scheme not in (\"https\", \"wss\")\n\n        for cookie in self:\n            name = cookie.key\n            domain = cookie[\"domain\"]\n\n            # Send shared cookies\n            if not domain:\n                filtered[name] = cookie.value\n                continue\n\n            if not self._unsafe and is_ip_address(hostname):\n                continue\n\n            if (domain, name) in self._host_only_cookies:\n                if domain != hostname:\n                    continue\n            elif not self._is_domain_match(domain, hostname):\n                continue\n\n            if not self._is_path_match(request_url.path, cookie[\"path\"]):\n                continue\n\n            if is_not_secure and cookie[\"secure\"]:\n                continue\n\n            filtered[name] = cookie.value\n\n        return filtered\n\n    @staticmethod\n    def _is_domain_match(domain, hostname):\n        \"\"\"Implements domain matching adhering to RFC 6265.\"\"\"\n        if hostname == domain:\n            return True\n\n        if not hostname.endswith(domain):\n            return False\n\n        non_matching = hostname[:-len(domain)]\n\n        if not non_matching.endswith(\".\"):\n            return False\n\n        return not is_ip_address(hostname)\n\n    @staticmethod\n    def _is_path_match(req_path, cookie_path):\n        \"\"\"Implements path matching adhering to RFC 6265.\"\"\"\n        if not req_path.startswith(\"/\"):\n            req_path = \"/\"\n\n        if req_path == cookie_path:\n            return True\n\n        if not req_path.startswith(cookie_path):\n            return False\n\n        if cookie_path.endswith(\"/\"):\n            return True\n\n        non_matching = req_path[len(cookie_path):]\n\n        return non_matching.startswith(\"/\")\n\n    @classmethod\n    def _parse_date(cls, date_str):\n        \"\"\"Implements date string parsing adhering to RFC 6265.\"\"\"\n        if not date_str:\n            return\n\n        found_time = False\n        found_day = False\n        found_month = False\n        found_year = False\n\n        hour = minute = second = 0\n        day = 0\n        month = 0\n        year = 0\n\n        for token_match in cls.DATE_TOKENS_RE.finditer(date_str):\n\n            token = token_match.group(\"token\")\n\n            if not found_time:\n                time_match = cls.DATE_HMS_TIME_RE.match(token)\n                if time_match:\n                    found_time = True\n                    hour, minute, second = [\n                        int(s) for s in time_match.groups()]\n                    continue\n\n            if not found_day:\n                day_match = cls.DATE_DAY_OF_MONTH_RE.match(token)\n                if day_match:\n                    found_day = True\n                    day = int(day_match.group())\n                    continue\n\n            if not found_month:\n                month_match = cls.DATE_MONTH_RE.match(token)\n                if month_match:\n                    found_month = True\n                    month = month_match.lastindex\n                    continue\n\n            if not found_year:\n                year_match = cls.DATE_YEAR_RE.match(token)\n                if year_match:\n                    found_year = True\n                    year = int(year_match.group())\n\n        if 70 <= year <= 99:\n            year += 1900\n        elif 0 <= year <= 69:\n            year += 2000\n\n        if False in (found_day, found_month, found_year, found_time):\n            return\n\n        if not 1 <= day <= 31:\n            return\n\n        if year < 1601 or hour > 23 or minute > 59 or second > 59:\n            return\n\n        return datetime.datetime(year, month, day,\n                                 hour, minute, second,\n                                 tzinfo=datetime.timezone.utc)\n", "path": "aiohttp/cookiejar.py"}]}