comparison mercurial/util.py @ 5525:dcbda0c4c3eb

Do not display passwords with pull/push/incoming/outgoing Passwords specified in the repository URL are now displayed as '***' when accessing the remote repository.
author Manuel Holtgrewe <purestorm@ggnore.net>
date Mon, 05 Nov 2007 20:29:32 +0100
parents 7a64931e2d76
children e2e8e977a6cb ca4f10c76ea7
comparison
equal deleted inserted replaced
5524:453acf64f71f 5525:dcbda0c4c3eb
13 """ 13 """
14 14
15 from i18n import _ 15 from i18n import _
16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile, strutil 16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile, strutil
17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil 17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil
18 import re, urlparse
18 19
19 try: 20 try:
20 set = set 21 set = set
21 frozenset = frozenset 22 frozenset = frozenset
22 except NameError: 23 except NameError:
1696 return path 1697 return path
1697 1698
1698 def uirepr(s): 1699 def uirepr(s):
1699 # Avoid double backslash in Windows path repr() 1700 # Avoid double backslash in Windows path repr()
1700 return repr(s).replace('\\\\', '\\') 1701 return repr(s).replace('\\\\', '\\')
1702
1703 def hidepassword(url):
1704 '''replaces the password in the url string by three asterisks (***)
1705
1706 >>> hidepassword('http://www.example.com/some/path#fragment')
1707 'http://www.example.com/some/path#fragment'
1708 >>> hidepassword('http://me@www.example.com/some/path#fragment')
1709 'http://me@www.example.com/some/path#fragment'
1710 >>> hidepassword('http://me:simplepw@www.example.com/path#frag')
1711 'http://me:***@www.example.com/path#frag'
1712 >>> hidepassword('http://me:complex:pw@www.example.com/path#frag')
1713 'http://me:***@www.example.com/path#frag'
1714 >>> hidepassword('/path/to/repo')
1715 '/path/to/repo'
1716 >>> hidepassword('relative/path/to/repo')
1717 'relative/path/to/repo'
1718 >>> hidepassword('c:\\\\path\\\\to\\\\repo')
1719 'c:\\\\path\\\\to\\\\repo'
1720 >>> hidepassword('c:/path/to/repo')
1721 'c:/path/to/repo'
1722 >>> hidepassword('bundle://path/to/bundle')
1723 'bundle://path/to/bundle'
1724 '''
1725 url_parts = list(urlparse.urlparse(url))
1726 host_with_pw_pattern = re.compile('^([^:]*):([^@]*)@(.*)$')
1727 if host_with_pw_pattern.match(url_parts[1]):
1728 url_parts[1] = re.sub(host_with_pw_pattern, r'\1:***@\3',
1729 url_parts[1])
1730 return urlparse.urlunparse(url_parts)
1731