comparison tests/get-with-headers.py @ 25208:5a6820f8da4d

tests: just use 'response.reason' There is no reason to not have simple code now that Python 2.4 is dead.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 18 May 2015 16:52:28 -0500
parents 747401086a38
children 8e86679d8acd
comparison
equal deleted inserted replaced
25207:6358391453f3 25208:5a6820f8da4d
31 formatjson = False 31 formatjson = False
32 if '--json' in sys.argv: 32 if '--json' in sys.argv:
33 sys.argv.remove('--json') 33 sys.argv.remove('--json')
34 formatjson = True 34 formatjson = True
35 35
36 reasons = {'Not modified': 'Not Modified'} # python 2.4
37
38 tag = None 36 tag = None
39 def request(host, path, show): 37 def request(host, path, show):
40 assert not path.startswith('/'), path 38 assert not path.startswith('/'), path
41 global tag 39 global tag
42 headers = {} 40 headers = {}
44 headers['If-None-Match'] = tag 42 headers['If-None-Match'] = tag
45 43
46 conn = httplib.HTTPConnection(host) 44 conn = httplib.HTTPConnection(host)
47 conn.request("GET", '/' + path, None, headers) 45 conn.request("GET", '/' + path, None, headers)
48 response = conn.getresponse() 46 response = conn.getresponse()
49 print response.status, reasons.get(response.reason, response.reason) 47 print response.status, response.reason
50 if show[:1] == ['-']: 48 if show[:1] == ['-']:
51 show = sorted(h for h, v in response.getheaders() 49 show = sorted(h for h, v in response.getheaders()
52 if h.lower() not in show) 50 if h.lower() not in show)
53 for h in [h.lower() for h in show]: 51 for h in [h.lower() for h in show]:
54 if response.getheader(h, None) is not None: 52 if response.getheader(h, None) is not None: