##// END OF EJS Templates
tests: fix incompatibility with python-2.4 in test-hgweb...
Dirkjan Ochtman -
r12250:bd98796c default
parent child Browse files
Show More
@@ -1,51 +1,53 b''
1 1 #!/usr/bin/env python
2 2
3 3 """This does HTTP GET requests given a host:port and path and returns
4 4 a subset of the headers plus the body of the result."""
5 5
6 6 import httplib, sys
7 7
8 8 try:
9 9 import msvcrt, os
10 10 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
11 11 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
12 12 except ImportError:
13 13 pass
14 14
15 15 twice = False
16 16 if '--twice' in sys.argv:
17 17 sys.argv.remove('--twice')
18 18 twice = True
19 19
20 reasons = {'Not modified': 'Not Modified'} # python 2.4
21
20 22 tag = None
21 23 def request(host, path, show):
22 24
23 25 global tag
24 26 headers = {}
25 27 if tag:
26 28 headers['If-None-Match'] = tag
27 29
28 30 conn = httplib.HTTPConnection(host)
29 31 conn.request("GET", path, None, headers)
30 32 response = conn.getresponse()
31 print response.status, response.reason
33 print response.status, reasons.get(response.reason, response.reason)
32 34 for h in [h.lower() for h in show]:
33 35 if response.getheader(h, None) is not None:
34 36 print "%s: %s" % (h, response.getheader(h))
35 37
36 38 print
37 39 data = response.read()
38 40 sys.stdout.write(data)
39 41
40 42 if twice and response.getheader('ETag', None):
41 43 tag = response.getheader('ETag')
42 44
43 45 return response.status
44 46
45 47 status = request(sys.argv[1], sys.argv[2], sys.argv[3:])
46 48 if twice:
47 49 status = request(sys.argv[1], sys.argv[2], sys.argv[3:])
48 50
49 51 if 200 <= status <= 305:
50 52 sys.exit(0)
51 53 sys.exit(1)
General Comments 0
You need to be logged in to leave comments. Login now