Mercurial > hg
annotate tests/get-with-headers.py @ 18944:a9c443b3b240
unionrepo: read-only operations on a union of two localrepos
unionrepo is just like bundlerepo without bundles.
The implementation is very similar to bundlerepo, but I don't see any obvious
way to generalize it.
Some most obvious use cases for this would be log and diff across local repos,
as a kind of preview of pulls, for instance:
$ hg -R union:repo1+repo2 heads
$ hg -R union:repo1+repo2 log -r REPO1REV -r REPO2REV
$ hg -R union:repo1+repo2 log -r '::REPO1REV-::REPO2REV'
$ hg -R union:repo1+repo2 log -r 'ancestor(REPO1REV,REPO2REV)'
$ hg -R union:repo1+repo2 diff -r REPO1REV -r REPO2REV
This is going to be used in RhodeCode, and Bitbucket already uses something
similar. Having a core implementation would be beneficial.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 18 Jan 2013 15:54:09 +0100 |
parents | f1118507174b |
children | ba6577a19656 |
rev | line source |
---|---|
2532
84655f721f39
Add a test for getting raw files via the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
84655f721f39
Add a test for getting raw files via the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
2 |
8447
d5ebcf8f6855
tests: fix doc string in get-with-headers.py
Martin Geisler <mg@lazybytes.net>
parents:
7544
diff
changeset
|
3 """This does HTTP GET requests given a host:port and path and returns |
2532
84655f721f39
Add a test for getting raw files via the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
4 a subset of the headers plus the body of the result.""" |
84655f721f39
Add a test for getting raw files via the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
5 |
10905
13a1b2fb7ef2
pylint, pyflakes: remove unused or duplicate imports
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9722
diff
changeset
|
6 import httplib, sys |
7054
e837f2294643
get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5561
diff
changeset
|
7 |
e837f2294643
get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5561
diff
changeset
|
8 try: |
e837f2294643
get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5561
diff
changeset
|
9 import msvcrt, os |
e837f2294643
get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5561
diff
changeset
|
10 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
e837f2294643
get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5561
diff
changeset
|
11 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
e837f2294643
get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5561
diff
changeset
|
12 except ImportError: |
e837f2294643
get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5561
diff
changeset
|
13 pass |
e837f2294643
get-with-headers: fix stream modes under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5561
diff
changeset
|
14 |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
15 twice = False |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
16 if '--twice' in sys.argv: |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
17 sys.argv.remove('--twice') |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
18 twice = True |
18400
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
19 headeronly = False |
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
20 if '--headeronly' in sys.argv: |
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
21 sys.argv.remove('--headeronly') |
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
22 headeronly = True |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
23 |
12250
bd98796c0b6f
tests: fix incompatibility with python-2.4 in test-hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
12182
diff
changeset
|
24 reasons = {'Not modified': 'Not Modified'} # python 2.4 |
bd98796c0b6f
tests: fix incompatibility with python-2.4 in test-hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
12182
diff
changeset
|
25 |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
26 tag = None |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
27 def request(host, path, show): |
17017
953faba28e91
tests: prepare get-with-headers.py for MSYS
Mads Kiilerich <mads@kiilerich.com>
parents:
12250
diff
changeset
|
28 assert not path.startswith('/'), path |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
29 global tag |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
30 headers = {} |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
31 if tag: |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
32 headers['If-None-Match'] = tag |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
2532
diff
changeset
|
33 |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
34 conn = httplib.HTTPConnection(host) |
17017
953faba28e91
tests: prepare get-with-headers.py for MSYS
Mads Kiilerich <mads@kiilerich.com>
parents:
12250
diff
changeset
|
35 conn.request("GET", '/' + path, None, headers) |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
36 response = conn.getresponse() |
12250
bd98796c0b6f
tests: fix incompatibility with python-2.4 in test-hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
12182
diff
changeset
|
37 print response.status, reasons.get(response.reason, response.reason) |
18380
a4d7fd7ad1f7
serve: don't send any content headers with 304 responses
Mads Kiilerich <madski@unity3d.com>
parents:
17017
diff
changeset
|
38 if show[:1] == ['-']: |
18393
a38039ef7312
tests: make test-hgweb.t output stable
Mads Kiilerich <madski@unity3d.com>
parents:
18380
diff
changeset
|
39 show = sorted(h for h, v in response.getheaders() |
a38039ef7312
tests: make test-hgweb.t output stable
Mads Kiilerich <madski@unity3d.com>
parents:
18380
diff
changeset
|
40 if h.lower() not in show) |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
41 for h in [h.lower() for h in show]: |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
42 if response.getheader(h, None) is not None: |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
43 print "%s: %s" % (h, response.getheader(h)) |
18400
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
44 if not headeronly: |
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
45 print |
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
46 data = response.read() |
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
47 sys.stdout.write(data) |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
48 |
18400
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
49 if twice and response.getheader('ETag', None): |
f1118507174b
get-with-headers: add a --headeronly switch
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18393
diff
changeset
|
50 tag = response.getheader('ETag') |
12182
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
51 |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
52 return response.status |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
53 |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
54 status = request(sys.argv[1], sys.argv[2], sys.argv[3:]) |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
55 if twice: |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
56 status = request(sys.argv[1], sys.argv[2], sys.argv[3:]) |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
57 |
1121af239761
tests: extend get-with-headers to support cache testing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10905
diff
changeset
|
58 if 200 <= status <= 305: |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
2532
diff
changeset
|
59 sys.exit(0) |
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
2532
diff
changeset
|
60 sys.exit(1) |