comparison hgext/convert/subversion.py @ 28883:032c4c2f802a

pycompat: switch to util.urlreq/util.urlerr for py3 compat
author timeless <timeless@mozdev.org>
date Wed, 06 Apr 2016 23:22:12 +0000
parents 86db5cb55d46
children a0939666b836
comparison
equal deleted inserted replaced
28882:800ec7c048b0 28883:032c4c2f802a
6 import cPickle as pickle 6 import cPickle as pickle
7 import os 7 import os
8 import re 8 import re
9 import sys 9 import sys
10 import tempfile 10 import tempfile
11 import urllib
12 import urllib2
13 import xml.dom.minidom 11 import xml.dom.minidom
14 12
15 from mercurial import ( 13 from mercurial import (
16 encoding, 14 encoding,
17 error, 15 error,
23 21
24 from . import common 22 from . import common
25 23
26 stringio = util.stringio 24 stringio = util.stringio
27 propertycache = util.propertycache 25 propertycache = util.propertycache
26 urlerr = util.urlerr
27 urlreq = util.urlreq
28 28
29 commandline = common.commandline 29 commandline = common.commandline
30 commit = common.commit 30 commit = common.commit
31 converter_sink = common.converter_sink 31 converter_sink = common.converter_sink
32 converter_source = common.converter_source 32 converter_source = common.converter_source
92 # before passing them to the API. Instead, we assume the base url 92 # before passing them to the API. Instead, we assume the base url
93 # is canonical and copy the behaviour of svn URL encoding function 93 # is canonical and copy the behaviour of svn URL encoding function
94 # so we can extend it safely with new components. The "safe" 94 # so we can extend it safely with new components. The "safe"
95 # characters were taken from the "svn_uri__char_validity" table in 95 # characters were taken from the "svn_uri__char_validity" table in
96 # libsvn_subr/path.c. 96 # libsvn_subr/path.c.
97 return urllib.quote(s, "!$&'()*+,-./:=@_~") 97 return urlreq.quote(s, "!$&'()*+,-./:=@_~")
98 98
99 def geturl(path): 99 def geturl(path):
100 try: 100 try:
101 return svn.client.url_from_path(svn.core.svn_path_canonicalize(path)) 101 return svn.client.url_from_path(svn.core.svn_path_canonicalize(path))
102 except svn.core.SubversionException: 102 except svn.core.SubversionException:
231 # Check to see if a given path is the root of an svn repo over http. We verify 231 # Check to see if a given path is the root of an svn repo over http. We verify
232 # this by requesting a version-controlled URL we know can't exist and looking 232 # this by requesting a version-controlled URL we know can't exist and looking
233 # for the svn-specific "not found" XML. 233 # for the svn-specific "not found" XML.
234 def httpcheck(ui, path, proto): 234 def httpcheck(ui, path, proto):
235 try: 235 try:
236 opener = urllib2.build_opener() 236 opener = urlreq.buildopener()
237 rsp = opener.open('%s://%s/!svn/ver/0/.svn' % (proto, path)) 237 rsp = opener.open('%s://%s/!svn/ver/0/.svn' % (proto, path))
238 data = rsp.read() 238 data = rsp.read()
239 except urllib2.HTTPError as inst: 239 except urlerr.httperror as inst:
240 if inst.code != 404: 240 if inst.code != 404:
241 # Except for 404 we cannot know for sure this is not an svn repo 241 # Except for 404 we cannot know for sure this is not an svn repo
242 ui.warn(_('svn: cannot probe remote repository, assume it could ' 242 ui.warn(_('svn: cannot probe remote repository, assume it could '
243 'be a subversion repository. Use --source-type if you ' 243 'be a subversion repository. Use --source-type if you '
244 'know better.\n')) 244 'know better.\n'))
245 return True 245 return True
246 data = inst.fp.read() 246 data = inst.fp.read()
247 except Exception: 247 except Exception:
248 # Could be urllib2.URLError if the URL is invalid or anything else. 248 # Could be urlerr.urlerror if the URL is invalid or anything else.
249 return False 249 return False
250 return '<m:human-readable errcode="160013">' in data 250 return '<m:human-readable errcode="160013">' in data
251 251
252 protomap = {'http': httpcheck, 252 protomap = {'http': httpcheck,
253 'https': httpcheck, 253 'https': httpcheck,
258 proto, path = url.split('://', 1) 258 proto, path = url.split('://', 1)
259 if proto == 'file': 259 if proto == 'file':
260 if (os.name == 'nt' and path[:1] == '/' and path[1:2].isalpha() 260 if (os.name == 'nt' and path[:1] == '/' and path[1:2].isalpha()
261 and path[2:6].lower() == '%3a/'): 261 and path[2:6].lower() == '%3a/'):
262 path = path[:2] + ':/' + path[6:] 262 path = path[:2] + ':/' + path[6:]
263 path = urllib.url2pathname(path) 263 path = urlreq.url2pathname(path)
264 except ValueError: 264 except ValueError:
265 proto = 'file' 265 proto = 'file'
266 path = os.path.abspath(url) 266 path = os.path.abspath(url)
267 if proto == 'file': 267 if proto == 'file':
268 path = util.pconvert(path) 268 path = util.pconvert(path)
328 self.ra = self.transport.ra 328 self.ra = self.transport.ra
329 self.ctx = self.transport.client 329 self.ctx = self.transport.client
330 self.baseurl = svn.ra.get_repos_root(self.ra) 330 self.baseurl = svn.ra.get_repos_root(self.ra)
331 # Module is either empty or a repository path starting with 331 # Module is either empty or a repository path starting with
332 # a slash and not ending with a slash. 332 # a slash and not ending with a slash.
333 self.module = urllib.unquote(self.url[len(self.baseurl):]) 333 self.module = urlreq.unquote(self.url[len(self.baseurl):])
334 self.prevmodule = None 334 self.prevmodule = None
335 self.rootmodule = self.module 335 self.rootmodule = self.module
336 self.commits = {} 336 self.commits = {}
337 self.paths = {} 337 self.paths = {}
338 self.uuid = svn.ra.get_uuid(self.ra) 338 self.uuid = svn.ra.get_uuid(self.ra)