Mercurial > public > mercurial-scm > hg
comparison tests/get-with-headers.py @ 18400:f1118507174b
get-with-headers: add a --headeronly switch
In some case we do not care about the actual rendering.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Wed, 16 Jan 2013 14:26:19 +0100 |
parents | a38039ef7312 |
children | ba6577a19656 |
comparison
equal
deleted
inserted
replaced
18399:66cec3c2ee00 | 18400:f1118507174b |
---|---|
14 | 14 |
15 twice = False | 15 twice = False |
16 if '--twice' in sys.argv: | 16 if '--twice' in sys.argv: |
17 sys.argv.remove('--twice') | 17 sys.argv.remove('--twice') |
18 twice = True | 18 twice = True |
19 headeronly = False | |
20 if '--headeronly' in sys.argv: | |
21 sys.argv.remove('--headeronly') | |
22 headeronly = True | |
19 | 23 |
20 reasons = {'Not modified': 'Not Modified'} # python 2.4 | 24 reasons = {'Not modified': 'Not Modified'} # python 2.4 |
21 | 25 |
22 tag = None | 26 tag = None |
23 def request(host, path, show): | 27 def request(host, path, show): |
35 show = sorted(h for h, v in response.getheaders() | 39 show = sorted(h for h, v in response.getheaders() |
36 if h.lower() not in show) | 40 if h.lower() not in show) |
37 for h in [h.lower() for h in show]: | 41 for h in [h.lower() for h in show]: |
38 if response.getheader(h, None) is not None: | 42 if response.getheader(h, None) is not None: |
39 print "%s: %s" % (h, response.getheader(h)) | 43 print "%s: %s" % (h, response.getheader(h)) |
44 if not headeronly: | |
45 print | |
46 data = response.read() | |
47 sys.stdout.write(data) | |
40 | 48 |
41 print | 49 if twice and response.getheader('ETag', None): |
42 data = response.read() | 50 tag = response.getheader('ETag') |
43 sys.stdout.write(data) | |
44 | |
45 if twice and response.getheader('ETag', None): | |
46 tag = response.getheader('ETag') | |
47 | 51 |
48 return response.status | 52 return response.status |
49 | 53 |
50 status = request(sys.argv[1], sys.argv[2], sys.argv[3:]) | 54 status = request(sys.argv[1], sys.argv[2], sys.argv[3:]) |
51 if twice: | 55 if twice: |