python - Parse a git URL like 'ssh://git@gitlab.org.net:3333/org/repo.git'? -


how extract hostname git url ssh://git@gitlab.org.net:3333/org/repo.git

u = urlparse(s) 

gives me

parseresult(scheme='ssh', netloc='git@gitlab.org.net:3333', path='/org/repo.git', params='', query='', fragment='') 

which means netloc closest want , leaves disappointing amount of work me.

should do

u.netloc.split('@')[1].split(':')[0] 

or there library handles better?

the returned parseresult has hostname attribute:

>>> urlparse('ssh://git@gitlab.org.net:3333/org/repo.git').hostname 'gitlab.org.net' 

Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -