comparison mercurial/url.py @ 13818:bf6156bab41b

url: use url.url in url.open()
author Brodie Rao <brodie@bitheap.org>
date Wed, 30 Mar 2011 20:01:34 -0700
parents 7f18bab2c0b0
children d16894e29f91
comparison
equal deleted inserted replaced
13817:7f18bab2c0b0 13818:bf6156bab41b
5 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> 5 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
6 # 6 #
7 # This software may be used and distributed according to the terms of the 7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2 or any later version. 8 # GNU General Public License version 2 or any later version.
9 9
10 import urllib, urllib2, urlparse, httplib, os, re, socket, cStringIO 10 import urllib, urllib2, urlparse, httplib, os, socket, cStringIO
11 import __builtin__ 11 import __builtin__
12 from i18n import _ 12 from i18n import _
13 import keepalive, util 13 import keepalive, util
14 14
15 class url(object): 15 class url(object):
959 # 1.0 here is the _protocol_ version 959 # 1.0 here is the _protocol_ version
960 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')] 960 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
961 opener.addheaders.append(('Accept', 'application/mercurial-0.1')) 961 opener.addheaders.append(('Accept', 'application/mercurial-0.1'))
962 return opener 962 return opener
963 963
964 scheme_re = re.compile(r'^([a-zA-Z0-9+-.]+)://') 964 def open(ui, url_, data=None):
965 965 u = url(url_)
966 def open(ui, url, data=None): 966 if u.scheme:
967 scheme = None 967 u.scheme = u.scheme.lower()
968 m = scheme_re.search(url) 968 url_, authinfo = u.authinfo()
969 if m: 969 else:
970 scheme = m.group(1).lower() 970 path = util.normpath(os.path.abspath(url_))
971 if not scheme: 971 url_ = 'file://' + urllib.pathname2url(path)
972 path = util.normpath(os.path.abspath(url))
973 url = 'file://' + urllib.pathname2url(path)
974 authinfo = None 972 authinfo = None
975 else: 973 return opener(ui, authinfo).open(url_, data)
976 url, authinfo = getauthinfo(url)
977 return opener(ui, authinfo).open(url, data)