@@ -261,24 +261,27 @@ class MercurialRepository(BaseRepository
"""
from mercurial.util import url as Url
# those authnadlers are patched for python 2.6.5 bug an
# infinit looping when given invalid resources
from mercurial.url import httpbasicauthhandler, httpdigestauthhandler
# check first if it's not an local url
if os.path.isdir(url) or url.startswith('file:'):
return True
if('+' in url[:url.find('://')]):
url = url[url.find('+')+1:]
handlers = []
test_uri, authinfo = Url(url).authinfo()
if authinfo:
#create a password manager
passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
passmgr.add_password(*authinfo)
handlers.extend((httpbasicauthhandler(passmgr),
httpdigestauthhandler(passmgr)))
o = urllib2.build_opener(*handlers)
@@ -361,63 +361,60 @@ def SlugifyName():
def _to_python(self, value, state):
return repo_name_slug(value)
def validate_python(self, value, state):
pass
return _validator
def ValidCloneUri():
from rhodecode.lib.utils import make_ui
def url_handler(repo_type, url, proto, ui=None):
def url_handler(repo_type, url, ui=None):
if repo_type == 'hg':
from mercurial.httprepo import httprepository, httpsrepository
if proto == 'https':
if url.startswith('https'):
httpsrepository(make_ui('db'), url).capabilities
elif proto == 'http':
elif url.startswith('http'):
httprepository(make_ui('db'), url).capabilities
elif url.startswith('svn+http'):
from hgsubversion.svnrepo import svnremoterepo
svnremoterepo(make_ui('db'), url).capabilities
elif repo_type == 'git':
#TODO: write a git url validator
class _validator(formencode.validators.FancyValidator):
messages = {
'clone_uri': _(u'invalid clone url'),
'invalid_clone_uri': _(u'Invalid clone url, provide a '
'valid clone http\s url')
'valid clone http(s)/svn+http(s) url')
}
repo_type = value.get('repo_type')
url = value.get('clone_uri')
if not url:
elif url.startswith('https') or url.startswith('http'):
_type = 'https' if url.startswith('https') else 'http'
else:
try:
url_handler(repo_type, url, _type, make_ui('db'))
url_handler(repo_type, url, make_ui('db'))
except Exception:
log.exception('Url validation failed')
msg = M(self, 'clone_uri')
raise formencode.Invalid(msg, value, state,
error_dict=dict(clone_uri=msg)
)
msg = M(self, 'invalid_clone_uri', state)
def ValidForkType(old_data={}):
'invalid_fork_type': _(u'Fork have to be the same type as parent')
if old_data['repo_type'] != value:
msg = M(self, 'invalid_fork_type', state)
Status change: