Mercurial > hg
annotate mercurial/httprepo.py @ 5403:477136fa6571
Always copy the necessary files before applying a git patch
This patch removes the "copymod" attribute from the gitpatch
class.
AFAICS, that attribute was only used to delay the copying of
renamed/copied files if there are no other changes to the target,
but in this case, if there are changes to the source, we'll end
up copying the wrong version.
This should fix issue762.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sat, 06 Oct 2007 15:30:15 -0300 |
parents | 24de027551c1 |
children | b3afa6725082 |
rev | line source |
---|---|
1089 | 1 # httprepo.py - HTTP repository proxy classes for mercurial |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 # |
2859 | 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
4 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 # |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 # of the GNU General Public License, incorporated herein by reference. |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
8 |
1089 | 9 from node import * |
10 from remoterepo import * | |
3891 | 11 from i18n import _ |
5176
664a1c312972
fix-up references to repo.RepoError
Matt Mackall <mpm@selenic.com>
parents:
5123
diff
changeset
|
12 import repo, os, urllib, urllib2, urlparse, zlib, util, httplib |
3877
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3703
diff
changeset
|
13 import errno, keepalive, tempfile, socket, changegroup |
926 | 14 |
2447
cd00531ecc16
httprepo: make "http://user:pass@host/" urls work
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2446
diff
changeset
|
15 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm): |
2281
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
16 def __init__(self, ui): |
2447
cd00531ecc16
httprepo: make "http://user:pass@host/" urls work
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2446
diff
changeset
|
17 urllib2.HTTPPasswordMgrWithDefaultRealm.__init__(self) |
2281
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
18 self.ui = ui |
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
19 |
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
20 def find_user_password(self, realm, authuri): |
2447
cd00531ecc16
httprepo: make "http://user:pass@host/" urls work
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2446
diff
changeset
|
21 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( |
2281
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
22 self, realm, authuri) |
2556
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
23 user, passwd = authinfo |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
24 if user and passwd: |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
25 return (user, passwd) |
2281
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
26 |
2446
1b2bbb2b4911
httprepo: fix small bug in authentication.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
27 if not self.ui.interactive: |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
28 raise util.Abort(_('http authorization required')) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
29 |
2281
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
30 self.ui.write(_("http authorization required\n")) |
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
31 self.ui.status(_("realm: %s\n") % realm) |
2556
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
32 if user: |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
33 self.ui.status(_("user: %s\n") % user) |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
34 else: |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
35 user = self.ui.prompt(_("user:"), default=None) |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
36 |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
37 if not passwd: |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
38 passwd = self.ui.getpass() |
2281
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
39 |
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
40 self.add_password(realm, authuri, user, passwd) |
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
41 return (user, passwd) |
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
42 |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
43 def netlocsplit(netloc): |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
44 '''split [user[:passwd]@]host[:port] into 4-tuple.''' |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
45 |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
46 a = netloc.find('@') |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
47 if a == -1: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
48 user, passwd = None, None |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
49 else: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
50 userpass, netloc = netloc[:a], netloc[a+1:] |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
51 c = userpass.find(':') |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
52 if c == -1: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
53 user, passwd = urllib.unquote(userpass), None |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
54 else: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
55 user = urllib.unquote(userpass[:c]) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
56 passwd = urllib.unquote(userpass[c+1:]) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
57 c = netloc.find(':') |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
58 if c == -1: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
59 host, port = netloc, None |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
60 else: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
61 host, port = netloc[:c], netloc[c+1:] |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
62 return host, port, user, passwd |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
63 |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
64 def netlocunsplit(host, port, user=None, passwd=None): |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
65 '''turn host, port, user, passwd into [user[:passwd]@]host[:port].''' |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
66 if port: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
67 hostport = host + ':' + port |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
68 else: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
69 hostport = host |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
70 if user: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
71 if passwd: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
72 userpass = urllib.quote(user) + ':' + urllib.quote(passwd) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
73 else: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
74 userpass = urllib.quote(user) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
75 return userpass + '@' + hostport |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
76 return hostport |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
77 |
4226
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
78 # work around a bug in Python < 2.4.2 |
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
79 # (it leaves a "\n" at the end of Proxy-authorization headers) |
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
80 class request(urllib2.Request): |
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
81 def add_header(self, key, val): |
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
82 if key.lower() == 'proxy-authorization': |
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
83 val = val.strip() |
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
84 return urllib2.Request.add_header(self, key, val) |
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
85 |
4025
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
86 class httpsendfile(file): |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
87 def __len__(self): |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
88 return os.fstat(self.fileno()).st_size |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
89 |
4025
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
90 def _gen_sendfile(connection): |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
91 def _sendfile(self, data): |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
92 # send a file |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
93 if isinstance(data, httpsendfile): |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
94 # if auth required, some data sent twice, so rewind here |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
95 data.seek(0) |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
96 for chunk in util.filechunkiter(data): |
4025
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
97 connection.send(self, chunk) |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
98 else: |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
99 connection.send(self, data) |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
100 return _sendfile |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
101 |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
102 class httpconnection(keepalive.HTTPConnection): |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
103 # must be able to send big bundle as stream. |
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
104 send = _gen_sendfile(keepalive.HTTPConnection) |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
105 |
2569
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
106 class basehttphandler(keepalive.HTTPHandler): |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
107 def http_open(self, req): |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
108 return self.do_open(httpconnection, req) |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
109 |
2569
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
110 has_https = hasattr(urllib2, 'HTTPSHandler') |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
111 if has_https: |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
112 class httpsconnection(httplib.HTTPSConnection): |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
113 response_class = keepalive.HTTPResponse |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
114 # must be able to send big bundle as stream. |
4025
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
115 send = _gen_sendfile(httplib.HTTPSConnection) |
2557
1727ff712a4e
Fix push over https.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2556
diff
changeset
|
116 |
2569
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
117 class httphandler(basehttphandler, urllib2.HTTPSHandler): |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
118 def https_open(self, req): |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
119 return self.do_open(httpsconnection, req) |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
120 else: |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
121 class httphandler(basehttphandler): |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
122 pass |
2557
1727ff712a4e
Fix push over https.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2556
diff
changeset
|
123 |
4678
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
124 # In python < 2.5 AbstractDigestAuthHandler raises a ValueError if |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
125 # it doesn't know about the auth type requested. This can happen if |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
126 # somebody is using BasicAuth and types a bad password. |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
127 class httpdigestauthhandler(urllib2.HTTPDigestAuthHandler): |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
128 def http_error_auth_reqed(self, auth_header, host, req, headers): |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
129 try: |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
130 return urllib2.HTTPDigestAuthHandler.http_error_auth_reqed( |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
131 self, auth_header, host, req, headers) |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
132 except ValueError, inst: |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
133 arg = inst.args[0] |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
134 if arg.startswith("AbstractDigestAuthHandler doesn't know "): |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
135 return |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
136 raise |
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
137 |
3661
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
138 def zgenerator(f): |
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
139 zd = zlib.decompressobj() |
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
140 try: |
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
141 for chunk in util.filechunkiter(f): |
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
142 yield zd.decompress(chunk) |
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
143 except httplib.HTTPException, inst: |
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
144 raise IOError(None, _('connection ended unexpectedly')) |
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
145 yield zd.flush() |
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
146 |
5066
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
147 _safe = ('abcdefghijklmnopqrstuvwxyz' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
148 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
149 '0123456789' '_.-/') |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
150 _safeset = None |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
151 _hex = None |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
152 def quotepath(path): |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
153 '''quote the path part of a URL |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
154 |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
155 This is similar to urllib.quote, but it also tries to avoid |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
156 quoting things twice (inspired by wget): |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
157 |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
158 >>> quotepath('abc def') |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
159 'abc%20def' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
160 >>> quotepath('abc%20def') |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
161 'abc%20def' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
162 >>> quotepath('abc%20 def') |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
163 'abc%20%20def' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
164 >>> quotepath('abc def%20') |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
165 'abc%20def%20' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
166 >>> quotepath('abc def%2') |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
167 'abc%20def%252' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
168 >>> quotepath('abc def%') |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
169 'abc%20def%25' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
170 ''' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
171 global _safeset, _hex |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
172 if _safeset is None: |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
173 _safeset = util.set(_safe) |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
174 _hex = util.set('abcdefABCDEF0123456789') |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
175 l = list(path) |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
176 for i in xrange(len(l)): |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
177 c = l[i] |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
178 if c == '%' and i + 2 < len(l) and (l[i+1] in _hex and l[i+2] in _hex): |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
179 pass |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
180 elif c not in _safeset: |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
181 l[i] = '%%%02X' % ord(c) |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
182 return ''.join(l) |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
183 |
926 | 184 class httprepository(remoterepository): |
60 | 185 def __init__(self, ui, path): |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
186 self.path = path |
2442
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
187 self.caps = None |
4132
0d94e4a3ddb4
Close keepalive connections to fix server traceback
Andrei Vermel <avermel@mail.ru>
parents:
4025
diff
changeset
|
188 self.handler = None |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
189 scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
190 if query or frag: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
191 raise util.Abort(_('unsupported URL component: "%s"') % |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
192 (query or frag)) |
5066
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
193 if not urlpath: |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
194 urlpath = '/' |
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
195 urlpath = quotepath(urlpath) |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
196 host, port, user, passwd = netlocsplit(netloc) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
197 |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
198 # urllib cannot handle URLs with embedded user or passwd |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
199 self._url = urlparse.urlunsplit((scheme, netlocunsplit(host, port), |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
200 urlpath, '', '')) |
60 | 201 self.ui = ui |
5066
167c422c745f
httprepo: quote the path part of the URL
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4739
diff
changeset
|
202 self.ui.debug(_('using %s\n') % self._url) |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
203 |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
204 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy') |
3131
cff3c58a5766
fix warnings spotted by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3072
diff
changeset
|
205 # XXX proxyauthinfo = None |
4132
0d94e4a3ddb4
Close keepalive connections to fix server traceback
Andrei Vermel <avermel@mail.ru>
parents:
4025
diff
changeset
|
206 self.handler = httphandler() |
0d94e4a3ddb4
Close keepalive connections to fix server traceback
Andrei Vermel <avermel@mail.ru>
parents:
4025
diff
changeset
|
207 handlers = [self.handler] |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
208 |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
209 if proxyurl: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
210 # proxy can be proper url or host[:port] |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
211 if not (proxyurl.startswith('http:') or |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
212 proxyurl.startswith('https:')): |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
213 proxyurl = 'http://' + proxyurl + '/' |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
214 snpqf = urlparse.urlsplit(proxyurl) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
215 proxyscheme, proxynetloc, proxypath, proxyquery, proxyfrag = snpqf |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
216 hpup = netlocsplit(proxynetloc) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
217 |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
218 proxyhost, proxyport, proxyuser, proxypasswd = hpup |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
219 if not proxyuser: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
220 proxyuser = ui.config("http_proxy", "user") |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
221 proxypasswd = ui.config("http_proxy", "passwd") |
515 | 222 |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
223 # see if we should use a proxy for this url |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
224 no_list = [ "localhost", "127.0.0.1" ] |
2501
b73552a00b20
Make "[web] allow_push, deny_push" and "[http_proxy] no" use ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2484
diff
changeset
|
225 no_list.extend([p.lower() for |
b73552a00b20
Make "[web] allow_push, deny_push" and "[http_proxy] no" use ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2484
diff
changeset
|
226 p in ui.configlist("http_proxy", "no")]) |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
227 no_list.extend([p.strip().lower() for |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
228 p in os.getenv("no_proxy", '').split(',') |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
229 if p.strip()]) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
230 # "http_proxy.always" config is for running tests on localhost |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
231 if (not ui.configbool("http_proxy", "always") and |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
232 host.lower() in no_list): |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
233 ui.debug(_('disabling proxy for %s\n') % host) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
234 else: |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
235 proxyurl = urlparse.urlunsplit(( |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
236 proxyscheme, netlocunsplit(proxyhost, proxyport, |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
237 proxyuser, proxypasswd or ''), |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
238 proxypath, proxyquery, proxyfrag)) |
3608
802da51cab5b
Use httpconnection even with proxies.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3570
diff
changeset
|
239 handlers.append(urllib2.ProxyHandler({scheme: proxyurl})) |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3170
diff
changeset
|
240 ui.debug(_('proxying through http://%s:%s\n') % |
3170
36ab673f66a5
do not disclose proxy user and password in debug messages
TK Soh <teekaysoh@yahoo.com>
parents:
3131
diff
changeset
|
241 (proxyhost, proxyport)) |
321 | 242 |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
243 # urllib2 takes proxy values from the environment and those |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
244 # will take precedence if found, so drop them |
424
9294dce4b633
Allow override of HTTP_PROXY, http_proxy and no_proxy; make no_proxy work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
385
diff
changeset
|
245 for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]: |
859
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
246 try: |
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
247 if os.environ.has_key(env): |
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
248 del os.environ[env] |
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
249 except OSError: |
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
250 pass |
321 | 251 |
2337
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
252 passmgr = passwordmgr(ui) |
3f24bc5dee81
http: fix many problems with url parsing and auth. added proxy test.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2336
diff
changeset
|
253 if user: |
2556
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
254 ui.debug(_('http auth: user %s, password %s\n') % |
f1ebc4311f47
Allow http://user@example.com URLs (i.e. without passwords)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2501
diff
changeset
|
255 (user, passwd and '*' * len(passwd) or 'not set')) |
5188
942c0827dc5b
recognize user:password in URLs that include port numbers.
Peter Meerwald <pmeerw@pmeerw.net>
parents:
5066
diff
changeset
|
256 passmgr.add_password(None, self._url, user, passwd or '') |
321 | 257 |
3608
802da51cab5b
Use httpconnection even with proxies.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3570
diff
changeset
|
258 handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr), |
4678
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
259 httpdigestauthhandler(passmgr))) |
3608
802da51cab5b
Use httpconnection even with proxies.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3570
diff
changeset
|
260 opener = urllib2.build_opener(*handlers) |
2281
7761597b5da3
prompt user for http authentication info
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2015
diff
changeset
|
261 |
1359
51ac9a79f3e5
Set the user agent for httprepo communication
Matt Mackall <mpm@selenic.com>
parents:
1251
diff
changeset
|
262 # 1.0 here is the _protocol_ version |
51ac9a79f3e5
Set the user agent for httprepo communication
Matt Mackall <mpm@selenic.com>
parents:
1251
diff
changeset
|
263 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')] |
321 | 264 urllib2.install_opener(opener) |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4369
diff
changeset
|
265 |
4132
0d94e4a3ddb4
Close keepalive connections to fix server traceback
Andrei Vermel <avermel@mail.ru>
parents:
4025
diff
changeset
|
266 def __del__(self): |
0d94e4a3ddb4
Close keepalive connections to fix server traceback
Andrei Vermel <avermel@mail.ru>
parents:
4025
diff
changeset
|
267 if self.handler: |
0d94e4a3ddb4
Close keepalive connections to fix server traceback
Andrei Vermel <avermel@mail.ru>
parents:
4025
diff
changeset
|
268 self.handler.close_all() |
0d94e4a3ddb4
Close keepalive connections to fix server traceback
Andrei Vermel <avermel@mail.ru>
parents:
4025
diff
changeset
|
269 self.handler = None |
60 | 270 |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
271 def url(self): |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
272 return self.path |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
273 |
2442
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
274 # look up capabilities only when needed |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
275 |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
276 def get_caps(self): |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
277 if self.caps is None: |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
278 try: |
5258
b534c502bfb3
Turn capabilities into a mutable set, instead of a fixed tuple.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5196
diff
changeset
|
279 self.caps = util.set(self.do_read('capabilities').split()) |
5176
664a1c312972
fix-up references to repo.RepoError
Matt Mackall <mpm@selenic.com>
parents:
5123
diff
changeset
|
280 except repo.RepoError: |
5258
b534c502bfb3
Turn capabilities into a mutable set, instead of a fixed tuple.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5196
diff
changeset
|
281 self.caps = util.set() |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
282 self.ui.debug(_('capabilities: %s\n') % |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
283 (' '.join(self.caps or ['none']))) |
2442
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
284 return self.caps |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
285 |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
286 capabilities = property(get_caps) |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
287 |
1870
8a8ab47cccde
make push over http print good error message.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1736
diff
changeset
|
288 def lock(self): |
8a8ab47cccde
make push over http print good error message.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1736
diff
changeset
|
289 raise util.Abort(_('operation not supported over http')) |
8a8ab47cccde
make push over http print good error message.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1736
diff
changeset
|
290 |
60 | 291 def do_cmd(self, cmd, **args): |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
292 data = args.pop('data', None) |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
293 headers = args.pop('headers', {}) |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
294 self.ui.debug(_("sending %s command\n") % cmd) |
60 | 295 q = {"cmd": cmd} |
296 q.update(args) | |
3562
88b4755fa48f
httprepo: record the url after a request, makes pull + redirect works
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3445
diff
changeset
|
297 qs = '?%s' % urllib.urlencode(q) |
88b4755fa48f
httprepo: record the url after a request, makes pull + redirect works
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3445
diff
changeset
|
298 cu = "%s%s" % (self._url, qs) |
2294
ce67fa312f61
Catch urllib's HTTPException and give a meaningful error message to the user.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2281
diff
changeset
|
299 try: |
3567
3bab1fc0ab75
Turn bundle file into a string for http push, for urllib2 over proxies.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3566
diff
changeset
|
300 if data: |
5333
6e6a00a7bf75
Push over HTTP: really tell the user the size of the bundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5188
diff
changeset
|
301 self.ui.debug(_("sending %s bytes\n") % len(data)) |
4226
fffacca46f09
Work around a urllib2 bug in Python < 2.4.2
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4132
diff
changeset
|
302 resp = urllib2.urlopen(request(cu, data, headers)) |
2467
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
303 except urllib2.HTTPError, inst: |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
304 if inst.code == 401: |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
305 raise util.Abort(_('authorization failed')) |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
306 raise |
2294
ce67fa312f61
Catch urllib's HTTPException and give a meaningful error message to the user.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2281
diff
changeset
|
307 except httplib.HTTPException, inst: |
2336
f77edcffb837
http: print better error if exception happens.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2294
diff
changeset
|
308 self.ui.debug(_('http error while sending %s command\n') % cmd) |
f77edcffb837
http: print better error if exception happens.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2294
diff
changeset
|
309 self.ui.print_exc() |
f77edcffb837
http: print better error if exception happens.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2294
diff
changeset
|
310 raise IOError(None, inst) |
3399
5dbb3a991bbf
Catch python2.3's IndexError with bogus http proxy settings. (issue203)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3223
diff
changeset
|
311 except IndexError: |
5dbb3a991bbf
Catch python2.3's IndexError with bogus http proxy settings. (issue203)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3223
diff
changeset
|
312 # this only happens with Python 2.3, later versions raise URLError |
5dbb3a991bbf
Catch python2.3's IndexError with bogus http proxy settings. (issue203)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3223
diff
changeset
|
313 raise util.Abort(_('http error, possibly caused by proxy setting')) |
3562
88b4755fa48f
httprepo: record the url after a request, makes pull + redirect works
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3445
diff
changeset
|
314 # record the url we got redirected to |
3570
c141d07198b9
Inform the user about the new URL when being redirected via http.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3569
diff
changeset
|
315 resp_url = resp.geturl() |
c141d07198b9
Inform the user about the new URL when being redirected via http.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3569
diff
changeset
|
316 if resp_url.endswith(qs): |
c141d07198b9
Inform the user about the new URL when being redirected via http.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3569
diff
changeset
|
317 resp_url = resp_url[:-len(qs)] |
c141d07198b9
Inform the user about the new URL when being redirected via http.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3569
diff
changeset
|
318 if self._url != resp_url: |
c141d07198b9
Inform the user about the new URL when being redirected via http.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3569
diff
changeset
|
319 self.ui.status(_('real URL is %s\n') % resp_url) |
c141d07198b9
Inform the user about the new URL when being redirected via http.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3569
diff
changeset
|
320 self._url = resp_url |
2435
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
321 try: |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
322 proto = resp.getheader('content-type') |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
323 except AttributeError: |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
324 proto = resp.headers['content-type'] |
752 | 325 |
753 | 326 # accept old "text/plain" and "application/hg-changegroup" for now |
4633
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4516
diff
changeset
|
327 if not (proto.startswith('application/mercurial-') or |
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4516
diff
changeset
|
328 proto.startswith('text/plain') or |
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4516
diff
changeset
|
329 proto.startswith('application/hg-changegroup')): |
4739
1da35d1e7ef9
Added full URL to debug output if something doesn't look like an http hg repo.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4678
diff
changeset
|
330 self.ui.debug(_("Requested URL: '%s'\n") % cu) |
5176
664a1c312972
fix-up references to repo.RepoError
Matt Mackall <mpm@selenic.com>
parents:
5123
diff
changeset
|
331 raise repo.RepoError(_("'%s' does not appear to be an hg repository") |
4633
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4516
diff
changeset
|
332 % self._url) |
752 | 333 |
4012
d1e31d7f7d44
fix handling of multiple Content-type headers
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3703
diff
changeset
|
334 if proto.startswith('application/mercurial-'): |
d1e31d7f7d44
fix handling of multiple Content-type headers
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3703
diff
changeset
|
335 try: |
4356
aed9e6dceb85
Avoid float rounding errors when checking http protocol version.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4226
diff
changeset
|
336 version = proto.split('-', 1)[1] |
aed9e6dceb85
Avoid float rounding errors when checking http protocol version.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4226
diff
changeset
|
337 version_info = tuple([int(n) for n in version.split('.')]) |
4012
d1e31d7f7d44
fix handling of multiple Content-type headers
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3703
diff
changeset
|
338 except ValueError: |
5176
664a1c312972
fix-up references to repo.RepoError
Matt Mackall <mpm@selenic.com>
parents:
5123
diff
changeset
|
339 raise repo.RepoError(_("'%s' sent a broken Content-type " |
4012
d1e31d7f7d44
fix handling of multiple Content-type headers
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3703
diff
changeset
|
340 "header (%s)") % (self._url, proto)) |
4356
aed9e6dceb85
Avoid float rounding errors when checking http protocol version.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4226
diff
changeset
|
341 if version_info > (0, 1): |
5176
664a1c312972
fix-up references to repo.RepoError
Matt Mackall <mpm@selenic.com>
parents:
5123
diff
changeset
|
342 raise repo.RepoError(_("'%s' uses newer protocol %s") % |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
343 (self._url, version)) |
753 | 344 |
752 | 345 return resp |
60 | 346 |
2435
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
347 def do_read(self, cmd, **args): |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
348 fp = self.do_cmd(cmd, **args) |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
349 try: |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
350 return fp.read() |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
351 finally: |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
352 # if using keepalive, allow connection to be reused |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
353 fp.close() |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
354 |
3444
3505fcd5a231
Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3399
diff
changeset
|
355 def lookup(self, key): |
5259
65dc707606ed
Push capability checking into protocol-level code.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5258
diff
changeset
|
356 self.requirecap('lookup', _('look up remote revision')) |
3445
233c733e4af5
httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents:
3444
diff
changeset
|
357 d = self.do_cmd("lookup", key = key).read() |
233c733e4af5
httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents:
3444
diff
changeset
|
358 success, data = d[:-1].split(' ', 1) |
233c733e4af5
httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents:
3444
diff
changeset
|
359 if int(success): |
233c733e4af5
httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents:
3444
diff
changeset
|
360 return bin(data) |
5176
664a1c312972
fix-up references to repo.RepoError
Matt Mackall <mpm@selenic.com>
parents:
5123
diff
changeset
|
361 raise repo.RepoError(data) |
3444
3505fcd5a231
Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3399
diff
changeset
|
362 |
222 | 363 def heads(self): |
2435
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
364 d = self.do_read("heads") |
222 | 365 try: |
366 return map(bin, d[:-1].split(" ")) | |
367 except: | |
3565
9073d7366776
Use the new UnexpectedOutput exception in httprepo, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3562
diff
changeset
|
368 raise util.UnexpectedOutput(_("unexpected response:"), d) |
222 | 369 |
60 | 370 def branches(self, nodes): |
371 n = " ".join(map(hex, nodes)) | |
2435
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
372 d = self.do_read("branches", nodes=n) |
217 | 373 try: |
374 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] | |
375 return br | |
376 except: | |
3565
9073d7366776
Use the new UnexpectedOutput exception in httprepo, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3562
diff
changeset
|
377 raise util.UnexpectedOutput(_("unexpected response:"), d) |
60 | 378 |
379 def between(self, pairs): | |
380 n = "\n".join(["-".join(map(hex, p)) for p in pairs]) | |
2435
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
381 d = self.do_read("between", pairs=n) |
217 | 382 try: |
383 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] | |
384 return p | |
385 except: | |
3565
9073d7366776
Use the new UnexpectedOutput exception in httprepo, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3562
diff
changeset
|
386 raise util.UnexpectedOutput(_("unexpected response:"), d) |
60 | 387 |
1736
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1402
diff
changeset
|
388 def changegroup(self, nodes, kind): |
60 | 389 n = " ".join(map(hex, nodes)) |
752 | 390 f = self.do_cmd("changegroup", roots=n) |
3661
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
391 return util.chunkbuffer(zgenerator(f)) |
3444
3505fcd5a231
Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3399
diff
changeset
|
392 |
3505fcd5a231
Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3399
diff
changeset
|
393 def changegroupsubset(self, bases, heads, source): |
5259
65dc707606ed
Push capability checking into protocol-level code.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5258
diff
changeset
|
394 self.requirecap('changegroupsubset', _('look up remote changes')) |
3444
3505fcd5a231
Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3399
diff
changeset
|
395 baselst = " ".join([hex(n) for n in bases]) |
3505fcd5a231
Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3399
diff
changeset
|
396 headlst = " ".join([hex(n) for n in heads]) |
3505fcd5a231
Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3399
diff
changeset
|
397 f = self.do_cmd("changegroupsubset", bases=baselst, heads=headlst) |
3661
e99ba8726bda
remove duplicate zgenerator in httprepo
Matt Mackall <mpm@selenic.com>
parents:
3614
diff
changeset
|
398 return util.chunkbuffer(zgenerator(f)) |
635
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
634
diff
changeset
|
399 |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2435
diff
changeset
|
400 def unbundle(self, cg, heads, source): |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
401 # have to stream bundle to a temp file because we do not have |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
402 # http 1.1 chunked transfer. |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
403 |
3662
f4dc02d7fb71
unduplicate bundle writing code from httprepo
Matt Mackall <mpm@selenic.com>
parents:
3661
diff
changeset
|
404 type = "" |
f4dc02d7fb71
unduplicate bundle writing code from httprepo
Matt Mackall <mpm@selenic.com>
parents:
3661
diff
changeset
|
405 types = self.capable('unbundle') |
3703
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
406 # servers older than d1b16a746db6 will send 'unbundle' as a |
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
407 # boolean capability |
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
408 try: |
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
409 types = types.split(',') |
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
410 except AttributeError: |
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
411 types = [""] |
3662
f4dc02d7fb71
unduplicate bundle writing code from httprepo
Matt Mackall <mpm@selenic.com>
parents:
3661
diff
changeset
|
412 if types: |
3703
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
413 for x in types: |
3662
f4dc02d7fb71
unduplicate bundle writing code from httprepo
Matt Mackall <mpm@selenic.com>
parents:
3661
diff
changeset
|
414 if x in changegroup.bundletypes: |
f4dc02d7fb71
unduplicate bundle writing code from httprepo
Matt Mackall <mpm@selenic.com>
parents:
3661
diff
changeset
|
415 type = x |
f4dc02d7fb71
unduplicate bundle writing code from httprepo
Matt Mackall <mpm@selenic.com>
parents:
3661
diff
changeset
|
416 break |
3613
cbf352b9a3cd
Client support for hgweb unbundle with versions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3609
diff
changeset
|
417 |
3662
f4dc02d7fb71
unduplicate bundle writing code from httprepo
Matt Mackall <mpm@selenic.com>
parents:
3661
diff
changeset
|
418 tempname = changegroup.writebundle(cg, None, type) |
4025
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
419 fp = httpsendfile(tempname, "rb") |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
420 try: |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
421 try: |
2467
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
422 rfp = self.do_cmd( |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
423 'unbundle', data=fp, |
4025
d8b3edf88af0
Subclass file with a __len__ method instead of setting Content-length
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
4012
diff
changeset
|
424 headers={'content-type': 'application/octet-stream'}, |
2467
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
425 heads=' '.join(map(hex, heads))) |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
426 try: |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
427 ret = int(rfp.readline()) |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
428 self.ui.write(rfp.read()) |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
429 return ret |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
430 finally: |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
431 rfp.close() |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
432 except socket.error, err: |
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
433 if err[0] in (errno.ECONNRESET, errno.EPIPE): |
3072
bc3fe3b5b785
Never apply string formatting to generated errors with util.Abort.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2859
diff
changeset
|
434 raise util.Abort(_('push failed: %s') % err[1]) |
2467
4e78dc71d946
http client: better work with authorization errors, broken sockets.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2465
diff
changeset
|
435 raise util.Abort(err[1]) |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
436 finally: |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
437 fp.close() |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
438 os.unlink(tempname) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2435
diff
changeset
|
439 |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2569
diff
changeset
|
440 def stream_out(self): |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2569
diff
changeset
|
441 return self.do_cmd('stream_out') |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2569
diff
changeset
|
442 |
923 | 443 class httpsrepository(httprepository): |
2569
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
444 def __init__(self, ui, path): |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
445 if not has_https: |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
446 raise util.Abort(_('Python support for SSL and HTTPS ' |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
447 'is not installed')) |
52ce0d6bc375
HTTPS: fix python2.3, persistent connections, don't explode if SSL is not available
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2557
diff
changeset
|
448 httprepository.__init__(self, ui, path) |
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
449 |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
450 def instance(ui, path, create): |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
451 if create: |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
452 raise util.Abort(_('cannot create new http repository')) |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
453 if path.startswith('https:'): |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
454 return httpsrepository(ui, path) |
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
455 return httprepository(ui, path) |