comparison mercurial/httppeer.py @ 46907:ffd3e823a7e5

urlutil: extract `url` related code from `util` into the new module The new module is well fitting for this new code. And this will be useful to make the gathered code collaborate more later. Differential Revision: https://phab.mercurial-scm.org/D10374
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 12 Apr 2021 03:01:04 +0200
parents d4ba4d51f85f
children 04688c51f81f
comparison
equal deleted inserted replaced
46906:33524c46a092 46907:ffd3e823a7e5
36 util as interfaceutil, 36 util as interfaceutil,
37 ) 37 )
38 from .utils import ( 38 from .utils import (
39 cborutil, 39 cborutil,
40 stringutil, 40 stringutil,
41 urlutil,
41 ) 42 )
42 43
43 httplib = util.httplib 44 httplib = util.httplib
44 urlerr = util.urlerr 45 urlerr = util.urlerr
45 urlreq = util.urlreq 46 urlreq = util.urlreq
303 raise error.Abort(_(b'authorization failed')) 304 raise error.Abort(_(b'authorization failed'))
304 raise 305 raise
305 except httplib.HTTPException as inst: 306 except httplib.HTTPException as inst:
306 ui.debug( 307 ui.debug(
307 b'http error requesting %s\n' 308 b'http error requesting %s\n'
308 % util.hidepassword(req.get_full_url()) 309 % urlutil.hidepassword(req.get_full_url())
309 ) 310 )
310 ui.traceback() 311 ui.traceback()
311 raise IOError(None, inst) 312 raise IOError(None, inst)
312 finally: 313 finally:
313 if ui.debugflag and ui.configbool(b'devel', b'debug.peer-request'): 314 if ui.debugflag and ui.configbool(b'devel', b'debug.peer-request'):
350 try: 351 try:
351 proto = pycompat.bytesurl(resp.getheader('content-type', '')) 352 proto = pycompat.bytesurl(resp.getheader('content-type', ''))
352 except AttributeError: 353 except AttributeError:
353 proto = pycompat.bytesurl(resp.headers.get('content-type', '')) 354 proto = pycompat.bytesurl(resp.headers.get('content-type', ''))
354 355
355 safeurl = util.hidepassword(baseurl) 356 safeurl = urlutil.hidepassword(baseurl)
356 if proto.startswith(b'application/hg-error'): 357 if proto.startswith(b'application/hg-error'):
357 raise error.OutOfBandError(resp.read()) 358 raise error.OutOfBandError(resp.read())
358 359
359 # Pre 1.0 versions of Mercurial used text/plain and 360 # Pre 1.0 versions of Mercurial used text/plain and
360 # application/hg-changegroup. We don't support such old servers. 361 # application/hg-changegroup. We don't support such old servers.
361 if not proto.startswith(b'application/mercurial-'): 362 if not proto.startswith(b'application/mercurial-'):
362 ui.debug(b"requested URL: '%s'\n" % util.hidepassword(requrl)) 363 ui.debug(b"requested URL: '%s'\n" % urlutil.hidepassword(requrl))
363 msg = _( 364 msg = _(
364 b"'%s' does not appear to be an hg repository:\n" 365 b"'%s' does not appear to be an hg repository:\n"
365 b"---%%<--- (%s)\n%s\n---%%<---\n" 366 b"---%%<--- (%s)\n%s\n---%%<---\n"
366 ) % (safeurl, proto or b'no content-type', resp.read(1024)) 367 ) % (safeurl, proto or b'no content-type', resp.read(1024))
367 368
1056 connections, perform HTTP requests. 1057 connections, perform HTTP requests.
1057 1058
1058 ``requestbuilder`` is the type used for constructing HTTP requests. 1059 ``requestbuilder`` is the type used for constructing HTTP requests.
1059 It exists as an argument so extensions can override the default. 1060 It exists as an argument so extensions can override the default.
1060 """ 1061 """
1061 u = util.url(path) 1062 u = urlutil.url(path)
1062 if u.query or u.fragment: 1063 if u.query or u.fragment:
1063 raise error.Abort( 1064 raise error.Abort(
1064 _(b'unsupported URL component: "%s"') % (u.query or u.fragment) 1065 _(b'unsupported URL component: "%s"') % (u.query or u.fragment)
1065 ) 1066 )
1066 1067