##// END OF EJS Templates
httprepo/sshrepo: use url.url...
Brodie Rao -
r13819:d16894e2 default
parent child Browse files
Show More
@@ -9,7 +9,7 b''
9 from node import nullid
9 from node import nullid
10 from i18n import _
10 from i18n import _
11 import changegroup, statichttprepo, error, url, util, wireproto
11 import changegroup, statichttprepo, error, url, util, wireproto
12 import os, urllib, urllib2, urlparse, zlib, httplib
12 import os, urllib, urllib2, zlib, httplib
13 import errno, socket
13 import errno, socket
14
14
15 def zgenerator(f):
15 def zgenerator(f):
@@ -28,13 +28,13 b' class httprepository(wireproto.wirerepos'
28 self.path = path
28 self.path = path
29 self.caps = None
29 self.caps = None
30 self.handler = None
30 self.handler = None
31 scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path)
31 u = url.url(path)
32 if query or frag:
32 if u.query or u.fragment:
33 raise util.Abort(_('unsupported URL component: "%s"') %
33 raise util.Abort(_('unsupported URL component: "%s"') %
34 (query or frag))
34 (u.query or u.fragment))
35
35
36 # urllib cannot handle URLs with embedded user or passwd
36 # urllib cannot handle URLs with embedded user or passwd
37 self._url, authinfo = url.getauthinfo(path)
37 self._url, authinfo = u.authinfo()
38
38
39 self.ui = ui
39 self.ui = ui
40 self.ui.debug('using %s\n' % self._url)
40 self.ui.debug('using %s\n' % self._url)
@@ -6,8 +6,7 b''
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from i18n import _
8 from i18n import _
9 import util, error, wireproto
9 import util, error, wireproto, url
10 import re
11
10
12 class remotelock(object):
11 class remotelock(object):
13 def __init__(self, repo):
12 def __init__(self, repo):
@@ -24,16 +23,16 b' class sshrepository(wireproto.wirereposi'
24 self._url = path
23 self._url = path
25 self.ui = ui
24 self.ui = ui
26
25
27 m = re.match(r'^ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?$', path)
26 u = url.url(path, parse_query=False, parse_fragment=False)
28 if not m:
27 if u.scheme != 'ssh' or not u.host or u.path is None:
29 self._abort(error.RepoError(_("couldn't parse location %s") % path))
28 self._abort(error.RepoError(_("couldn't parse location %s") % path))
30
29
31 self.user = m.group(2)
30 self.user = u.user
32 if self.user and ':' in self.user:
31 if u.passwd is not None:
33 self._abort(error.RepoError(_("password in URL not supported")))
32 self._abort(error.RepoError(_("password in URL not supported")))
34 self.host = m.group(3)
33 self.host = u.host
35 self.port = m.group(5)
34 self.port = u.port
36 self.path = m.group(7) or "."
35 self.path = u.path or "."
37
36
38 sshcmd = self.ui.config("ui", "ssh", "ssh")
37 sshcmd = self.ui.config("ui", "ssh", "ssh")
39 remotecmd = self.ui.config("ui", "remotecmd", "hg")
38 remotecmd = self.ui.config("ui", "remotecmd", "hg")
@@ -85,7 +85,8 b' class statichttprepository(localrepo.loc'
85 self.ui = ui
85 self.ui = ui
86
86
87 self.root = path
87 self.root = path
88 self.path, authinfo = url.getauthinfo(path.rstrip('/') + "/.hg")
88 u = url.url(path.rstrip('/') + "/.hg")
89 self.path, authinfo = u.authinfo()
89
90
90 opener = build_opener(ui, authinfo)
91 opener = build_opener(ui, authinfo)
91 self.opener = opener(self.path)
92 self.opener = opener(self.path)
@@ -906,31 +906,6 b' class httpbasicauthhandler(urllib2.HTTPB'
906 return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(
906 return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(
907 self, auth_header, host, req, headers)
907 self, auth_header, host, req, headers)
908
908
909 def getauthinfo(path):
910 scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path)
911 if not urlpath:
912 urlpath = '/'
913 if scheme != 'file':
914 # XXX: why are we quoting the path again with some smart
915 # heuristic here? Anyway, it cannot be done with file://
916 # urls since path encoding is os/fs dependent (see
917 # urllib.pathname2url() for details).
918 urlpath = quotepath(urlpath)
919 host, port, user, passwd = netlocsplit(netloc)
920
921 # urllib cannot handle URLs with embedded user or passwd
922 url = urlparse.urlunsplit((scheme, netlocunsplit(host, port),
923 urlpath, query, frag))
924 if user:
925 netloc = host
926 if port:
927 netloc += ':' + port
928 # Python < 2.4.3 uses only the netloc to search for a password
929 authinfo = (None, (url, netloc), user, passwd or '')
930 else:
931 authinfo = None
932 return url, authinfo
933
934 handlerfuncs = []
909 handlerfuncs = []
935
910
936 def opener(ui, authinfo=None):
911 def opener(ui, authinfo=None):
General Comments 0
You need to be logged in to leave comments. Login now