Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
# Copyright (C) 2009-2011 Fog Creek Software. All rights reserved.## To enable the "kilnauth" extension put these lines in your ~/.hgrc:# [extensions]# kilnauth = /path/to/kilnauth.py## For help on the usage of kilnauth use:# hg help kilnauth## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.'''stores authentication cookies for HTTP repositoriesThis extension knows how to capture Kiln authentication tokens when pushingover HTTP. This means you only need to enter your login and password once;after that, the FogBugz token will be stored in your home directory, allowingpushing without a password.If you ever need to logout of Kiln, simply run ``hg logout'''''fromcookielibimportMozillaCookieJar,Cookiefromurllib2importRequestimportosimportreimportshutilimportstatimportsysimporttempfiletry:fromhashlibimportmd5except:# Python 2.4importmd5try:WindowsErrorexceptNameError:WindowsError=Nonefrommercurial.i18nimport_importmercurial.urlfrommercurialimportcommandsfrommercurialimportcmdutilcurrent_user=NoneclassCookieJar(MozillaCookieJar,object):def__init__(self,filename,*args,**kwargs):self.__original_path=filenametf=tempfile.NamedTemporaryFile(delete=False)self.__temporary_path=tf.nametf.close()ifos.path.exists(filename):shutil.copyfile(filename,self.__temporary_path)returnsuper(CookieJar,self).__init__(self.__temporary_path,*args,**kwargs)def__enter__(self):passdef__exit__(self,exc_type,exc_value,traceback):os.unlink(self.__temporary_path)self.__temporary_path=Nonedef__del__(self):try:ifself.__temporary_path:os.unlink(self.__temporary_path)except(OSError,IOError):passdefsave(self,*args,**kwargs):withopen(self.__temporary_path,'rb')asf:before=md5(f.read()).digest()super(CookieJar,self).save(*args,**kwargs)withopen(self.__temporary_path,'rb')asf:after=md5(f.read()).digest()ifbefore!=after:try:os.rename(self.__temporary_path,self.__original_path)except(IOError,OSError,WindowsError):shutil.copyfile(self.__temporary_path,self.__original_path)defget_cookiejar(ui):globalcurrent_userifos.name=='nt':cookie_path=cookie_path=os.path.expandvars(os.path.expanduser('~\\_hgcookies'))else:cookie_path=os.path.expanduser('~/.hgcookies')ifnotos.path.isdir(cookie_path):ifos.path.exists(cookie_path):os.remove(cookie_path)os.mkdir(cookie_path)ifos.name=='posix':os.chmod(cookie_path,stat.S_IREAD|stat.S_IWRITE|stat.S_IEXEC)cookie_path=os.path.join(cookie_path,md5(current_user).hexdigest())# Cygwin's Python does not always expanduser() properly...ifre.match(r'^[A-Za-z]:',cookie_path)isnotNoneandre.match(r'[A-Za-z]:\\',cookie_path)isNone:cookie_path=re.sub(r'([A-Za-z]):',r'\1:\\',cookie_path)try:cj=CookieJar(cookie_path)ifnotos.path.exists(cookie_path):try:cj.save()exceptException,e:ui.warn(_('unable to save cookies: %s')%str(e))# save() destroys the tempfile; get a new onecj=CookieJar(cookie_path)ifos.name=='posix':os.chmod(cookie_path,stat.S_IREAD|stat.S_IWRITE)cj.load(ignore_discard=True,ignore_expires=True)returncjexceptIOError,e:ui.warn(_('Cookie file %s exists, but could not be opened (%s).\nContinuing without cookie authentication.\n')%(cookie_path,e))returnMozillaCookieJar(tempfile.NamedTemporaryFile().name)defmake_cookie(request,name,value):domain=request.get_host()port=Noneif':'indomain:domain,port=domain.split(':',1)if'.'notindomain:domain+=".local"returnCookie(version=0,name=name,value=value,port=port,port_specified=False,domain=domain,domain_specified=False,domain_initial_dot=False,path='/',path_specified=False,secure=False,expires=None,discard=False,comment=None,comment_url=None,rest={})defget_username(url):url=re.sub(r'https?://','',url)url=re.sub(r'/.*','',url)if'@'inurl:# There should be some login info# rfind in case it's an email addressusername=url[:url.rfind('@')]if':'inusername:username=url[:url.find(':')]returnusername# Didn't find anything...return''defget_dest(ui):frommercurial.dispatchimport_parsetry:cmd_info=_parse(ui,sys.argv[1:])cmd=cmd_info[0]dest=cmd_info[2]ifdest:dest=dest[0]elifcmdin['outgoing','push']:dest='default-push'else:dest='default'except:dest='default'returnui.expandpath(dest)defreposetup(ui,repo):globalcurrent_userifrepo.local():try:current_user=get_username(get_dest(ui))except:current_user=''defextsetup():globalcurrent_userui=mercurial.ui.ui()current_user=get_username(get_dest(ui))defopen_wrapper(func):defopen(*args,**kwargs):ifisinstance(args[0],Request):request=args[0]cj=get_cookiejar(ui)cj.set_cookie(make_cookie(args[0],'fSetNewFogBugzAuthCookie','1'))cj.add_cookie_header(request)response=func(*args,**kwargs)cj.extract_cookies(response,args[0])try:cj.save(ignore_discard=True,ignore_expires=True)exceptException,e:ui.warn(_('unable to save cookies: %s')%str(e))else:response=func(*args,**kwargs)returnresponsereturnopenold_opener=mercurial.url.openerdefopener(*args,**kwargs):urlopener=old_opener(*args,**kwargs)urlopener.open=open_wrapper(urlopener.open) return urlopener
mercurial.url.opener = opener
+if hasattr(commands, 'norepo'):+ # Pre-Mercurial 3.8+ opt_no_repo = {}+ commands.norepo += ' logout'+else:+ # Mercurial 3.8++ opt_no_repo = {'norepo': True}+cmdtable = {}
command = cmdutil.command(cmdtable)
-@command('logout', [], _('[domain]'), norepo=True)
+@command('logout', [], _('[domain]'), **opt_no_repo)
def logout(ui, domain=None, **opts):
"""log out of http repositories
Clears the cookies stored for HTTP repositories. If [domain] is specified, only that domain will be logged out. Otherwise, all domains will be logged out. """cj=get_cookiejar(ui)try:cj.clear(domain=domain)cj.save()exceptKeyError:ui.write("Not logged in to '%s'\n"%(domain,))
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.