Skip to content
Myr

Allow copying of PreparedRequests without headers/cookies

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Gouldin · committed by David Gouldin · parent 6999611 · Browse files · 2 files+30 added−2 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+30 added−2 removed

  • other:+30 added−2 removed

2 files+30 added−2 removed

modified:requests/models.py+2 added-2 removed
307 unmodified lines
308 def copy(self):309 p = PreparedRequest()310 p.method = self.method311 p.url = self.url312 p.headers = self.headers.copy()313 p._cookies = self._cookies.copy()312 p.headers = self.headers.copy() if self.headers is not None else None313 p._cookies = self._cookies.copy() if self._cookies is not None else None314 p.body = self.body315 p.hooks = self.hooks316 return p317
490 unmodified lines
modified:test_requests.py+28 added
1367 unmodified lines
1368 hooks=default_hooks()1369 )1370 assert p.body == urlencode(data)13711372def assert_copy(p, p_copy):1373 for attr in ('method', 'url', 'headers', '_cookies', 'body', 'hooks'):1374 assert getattr(p, attr) == getattr(p_copy, attr)13751376def test_prepared_request_empty_copy():1377 p = PreparedRequest()1378 assert_copy(p, p.copy())13791380def test_prepared_request_no_cookies_copy():1381 p = PreparedRequest()1382 p.prepare(1383 method='GET',1384 url='http://www.example.com',1385 data='foo=bar',1386 hooks=default_hooks()1387 )1388 assert_copy(p, p.copy())13891390def test_prepared_request_complete_copy():1391 p = PreparedRequest()1392 p.prepare(1393 method='GET',1394 url='http://www.example.com',1395 data='foo=bar',1396 hooks=default_hooks(),1397 cookies={'foo': 'bar'}1398 )1399 assert_copy(p, p.copy())14001401if __name__ == '__main__':1402 unittest.main()