PK8Ž,5Έ?bΘΘzc/__init__.py# this is a namespace package try: import pkg_resources pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil __path__ = pkgutil.extend_path(__path__, __name__) PK8/5₯U:ggzc/__init__.pyc;ς }+Ec@sOydkZeieƒWn.ej o"dkZeieeƒZnXdS(N(s pkg_resourcessdeclare_namespaces__name__s ImportErrorspkgutils extend_paths__path__(s__path__s pkg_resourcesspkgutil((s)build/bdist.linux-i686/egg/zc/__init__.pys?s   PKΒ6.5/kΝΑ99zc/buildoutsftp/buildoutsftp.py############################################################################## # # Copyright (c) 2006 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## import urllib2 import zc.buildoutsftp.urllib2sftp def install(buildout=None): urllib2.install_opener( urllib2.build_opener(zc.buildoutsftp.urllib2sftp.SFTPHandler) ) PKC6/53wjΔ__zc/buildoutsftp/urllib2sftp.py############################################################################## # # Copyright (c) 2005 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """SFTP Handler for urllib2 $Id: urllib2sftp.py 70181 2006-09-14 19:39:03Z jim $ """ import cStringIO, getpass, mimetypes, os, re, stat, sys, urllib, urllib2 import paramiko parse_url_host = re.compile( '(?:' '([^@:]+)(?::([^@]*))?@' ')?' '([^:]*)(?::(\d+))?$').match if sys.platform == 'win32': import _winreg parse_reg_key_name = re.compile('(rsa|dss)2?@22:(\S+)$').match def _get_hosts_keys(): regkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r'Software\SimonTatham\PuTTY\SshHostKeys', ) keys = paramiko.HostKeys() i = 0 while 1: try: name, value, type_ = _winreg.EnumValue(regkey, i) i += 1 value = [long(v, 16) for v in value.split(',')] ktype, host = parse_reg_key_name(name).groups() if ktype == 'rsa': key = paramiko.RSAKey(vals=value) if ktype == 'dss': key = paramiko.DSSKey(vals=value) keys.add(host, 'ssh-'+ktype, key) except WindowsError: break return keys else: def _get_hosts_keys(): return paramiko.HostKeys(os.path.expanduser('~/.ssh/known_hosts')) class Result: def __init__(self, fp, url, info): self._fp = fp self.url = url self.headers = info def geturl(self): return self.url def info(self): return self.headers def __getattr__(self, name): return getattr(self._fp, name) class SFTPHandler(urllib2.BaseHandler): def sftp_open(self, req): host = req.get_host() if not host: raise IOError, ('sftp error', 'no host given') parsed = parse_url_host(host) if not parsed: raise IOError, ('sftp error', 'invalid host', host) user, pw, host, port = parsed.groups() if user: user = urllib.unquote(user) else: user = getpass.getuser() if port: port = int(port) else: port = 22 if pw: pw = urllib.unquote(pw) host = urllib.unquote(host or '') hostkey = _get_hosts_keys() hostkey = hostkey.get(host) if hostkey is None: raise paramiko.AuthenticationException( "No stored host key", host) [hostkeytype] = list(hostkey) hostkey = hostkey[hostkeytype] trans = paramiko.Transport((host, port)) if pw is not None: trans.connect(username=user, password=pw) else: for key in paramiko.Agent().get_keys(): try: trans.connect(username=user, pkey=key, hostkey=hostkey) break except paramiko.AuthenticationException: pass else: raise paramiko.AuthenticationException( "Authentication failed.") sftp = paramiko.SFTPClient.from_transport(trans) path = req.get_selector() url = req.get_full_url() mode = sftp.stat(path).st_mode if stat.S_ISDIR(mode): return Result( cStringIO.StringIO('\n'.join([ ('%s
' % (url, x, x) ) for x in sftp.listdir(path) ])), url, {'content-type': 'text/html'}) else: mtype = mimetypes.guess_type(url)[0] if mtype is None: mtype = 'application/octet-stream' return Result(sftp.open(path), url, {'content-type': mtype}) PKμ.-5€Œ₯zc/buildoutsftp/__init__.py# PK29-5a<Š  zc/buildoutsftp/tests.py############################################################################## # # Copyright (c) 2006 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## import os, sys import paramiko from zope.testing import doctest class Replace: def __init__(self, module, **attrs): self.module = module self.original = original = {} for name, value in attrs.iteritems(): original[name] = getattr(module, name) setattr(module, name, value) def restore(self): for name, value in self.attrs.iteritems(): setattt(self.module, name, value) hkeys = [ ('foo.com', 'comkey'), ('foo.org', 'orgkey'), ('foo.net', 'netkey'), ('foo.biz', 'bizkey'), ] def setup(test): # We're going to replace much of paramiko, and, if necessary, _winreg # to try to control urllib2sftp's environment. teardown = [] test.globs['__teardown'] = teardown test.globs['__HOME'] = os.environ.get('HOME') os.environ['HOME'] == '/testhome' if sys.platform == 'win32': import _winreg key = object() def OpenKey(*args): if args != (_winreg.HKEY_CURENT_USER, r'Software\SimonTatham\PuTTY\SshHoskKeys'): raise ValueError("Bad keys", *args) return key def EnumValue(k, index): if k is not key: raise ValueError('Bad key') try: host, hkey = hkeys[index] except IndexError: raise WindowsError(index) return 'rsa@22:'+host, hkey, 0 HostKeys = paramiko.HostKeys teardown.append(Replace(_winreg, OpenKey=OpenKey, EnumValue=EnumValue, ).restore ) else: def HostKeys(path=None): if path != '/testhome/.ssh/known_hosts': raise IOError('No suh file', path) return dict([ (host, {'ssh-rsa': paramiko.PKey(hkey)}) for (host, hkey) in hkeys ]) def test_suite(): return doctest.DocTestSuite() PK8/5\\±11 zc/buildoutsftp/buildoutsftp.pyc;ς Μ4 Ec@s"dkZdkZed„ZdS(NcCs#tititiiiƒƒdS(N(surllib2sinstall_openers build_openerszcs buildoutsftps urllib2sftps SFTPHandler(sbuildout((s:build/bdist.linux-i686/egg/zc/buildoutsftp/buildoutsftp.pysinstalls(surllib2szc.buildoutsftp.urllib2sftpszcsNonesinstall(surllib2sinstallszc((s:build/bdist.linux-i686/egg/zc/buildoutsftp/buildoutsftp.pys?s  PK8/5brM””zc/buildoutsftp/urllib2sftp.pyc;ς ^… Ec@sγdZdkZdkZdkZdkZdkZdkZdkZdkZdk Z dk Z ei dƒi Z eidjo(dkZei dƒi Zd„Zn d„Zdfd„ƒYZd e ifd „ƒYZdS( sOSFTP Handler for urllib2 $Id: urllib2sftp.py 70181 2006-09-14 19:39:03Z jim $ Ns.(?:([^@:]+)(?::([^@]*))?@)?([^:]*)(?::(\d+))?$swin32s(rsa|dss)2?@22:(\S+)$c Cs,titidƒ} tiƒ}d}xϊnoςyΧti| |ƒ\}}}|d7}gi }|idƒD]} |t| dƒƒqp~}t|ƒiƒ\}}|djotid|ƒ}n|djotid|ƒ}n|i|d ||ƒWq*tj oPq*Xq1W|SdS( Ns&Software\SimonTatham\PuTTY\SshHostKeysiis,isrsasvalssdsssssh-(s_winregsOpenKeysHKEY_CURRENT_USERsregkeysparamikosHostKeysskeyssis EnumValuesnamesvaluestype_sappends_[1]ssplitsvslongsparse_reg_key_namesgroupssktypeshostsRSAKeyskeysDSSKeysadds WindowsError( snamesktypeskeysshostsvalues_[1]sistype_skeysvsregkey((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pys_get_hosts_keyss&    9   cCstitiidƒƒSdS(Ns~/.ssh/known_hosts(sparamikosHostKeyssosspaths expanduser(((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pys_get_hosts_keys5ssResultcBs,tZd„Zd„Zd„Zd„ZRS(NcCs||_||_||_dS(N(sfpsselfs_fpsurlsinfosheaders(sselfsfpsurlsinfo((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pys__init__;s  cCs |iSdS(N(sselfsurl(sself((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pysgeturl@scCs |iSdS(N(sselfsheaders(sself((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pysinfoCscCst|i|ƒSdS(N(sgetattrsselfs_fpsname(sselfsname((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pys __getattr__Fs(s__name__s __module__s__init__sgeturlsinfos __getattr__(((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pysResult9s   s SFTPHandlercBstZd„ZRS(Nc CsΤ|iƒ}| otddf‚nt|ƒ}| otdd|f‚n|iƒ\}}}}|ot i |ƒ}n t i ƒ}|ot|ƒ}nd}|ot i |ƒ}nt i |pdƒ}tƒ}|i|ƒ}|tjotid|ƒ‚nt|ƒ\}||}ti||fƒ}|tj o|id|d|ƒngxctiƒiƒD]@} y!|id|d | d |ƒPWqtij oqXqWtid ƒ‚tii|ƒ} |i ƒ} |i"ƒ} | i$| ƒi%}t$i'|ƒoft(t)i*d i+gi,}| i.| ƒD]}|d | ||fƒqD~ƒƒ| hdd<ƒSnMt0i1| ƒd} | tjo d} nt(| i3| ƒ| hd| <ƒSdS(Ns sftp errors no host givens invalid hostissNo stored host keysusernamespasswordspkeyshostkeysAuthentication failed.s s%s
s content-types text/htmlisapplication/octet-stream(4sreqsget_hostshostsIOErrorsparse_url_hostsparsedsgroupssuserspwsportsurllibsunquotesgetpasssgetusersints_get_hosts_keysshostkeysgetsNonesparamikosAuthenticationExceptionslists hostkeytypes TransportstranssconnectsAgentsget_keysskeys SFTPClientsfrom_transportssftps get_selectorspaths get_full_urlsurlsstatsst_modesmodesS_ISDIRsResults cStringIOsStringIOsjoinsappends_[1]slistdirsxs mimetypess guess_typesmtypesopen(sselfsreqs hostkeytypesportshostkeyspwsparsedshostsuserskeyspathsmtypesurlssftps_[1]smodesxstrans((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pys sftp_openKsX          O  (s__name__s __module__s sftp_open(((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pys SFTPHandlerIs(s__doc__s cStringIOsgetpasss mimetypessossresstatssyssurllibsurllib2sparamikoscompilesmatchsparse_url_hostsplatforms_winregsparse_reg_key_names_get_hosts_keyssResults BaseHandlers SFTPHandler(sparse_reg_key_names cStringIOs mimetypessstatsurllibsurllib2sgetpasssresparse_url_hostssyssResults SFTPHandlers_winregsossparamikos_get_hosts_keys((s9build/bdist.linux-i686/egg/zc/buildoutsftp/urllib2sftp.pys?sQ    PK8/5ju††zc/buildoutsftp/__init__.pyc;ς ŒΥEc@sdS(N((((s6build/bdist.linux-i686/egg/zc/buildoutsftp/__init__.pys?sPK8/5=ŸθDΨ Ψ zc/buildoutsftp/tests.pyc;ς πζEc@s{dkZdkZdkZdklZdfd„ƒYZddfddfdd fd d fgZd „Zd „ZdS(N(sdoctestsReplacecBstZd„Zd„ZRS(NcKsZ||_h|_}x=|iƒD]/\}}t||ƒ||=1.0.0b5 is needed for this to work properly.) An SFTP URL is similar to an FTP URL and is of the form:: sftp://user:password@hostname:port/path where the user name, password, and port are optional. Here are some examples: The following URL accesses the path /distribution on download.zope.org:: sftp://download.zope.org/distribution The following URL accesses the path /distribution on download.zope.org using the user id jim:: sftp://jim@download.zope.org/distribution The following URL accesses the path /distribution on download.zope.org using the user id jim and password 123:: sftp://jim:123@download.zope.org/distribution The following url accesses the path /distribution on download.zope.org using an ssh server running on port 1022:: sftp://download.zope.org:1022/distribution The buildout extension actually installs a urllib2 handler for the "sftp" protocol. This handler is actually setuptools specific because it generates HTML directory listings, needed by setuptools and makes no effort to make directory listings useful for anything else. It is possible that, in the future, setuptools will provide it's own extension mechanism for handling alternate protocols, in which case, we might bypass the urllib2 extension mechanism. SSH Compatibility ================= The extension works with Open SSH on unix-based systems and PuTTY on Windows. Unless a password is given in the URL, private keys are ontained from ssh agent (pagent on Windows). Status and Change History ========================= This package is experimental. It seems to work based on manual testing. I'm still trying to figure out how to write automated tests for this. 0.2 --- Added missing entry point. Adjusted content-type information to work with setuptools. 0.1 --- Initial release Keywords: buildout Platform: UNKNOWN Classifier: Framework :: Buildout Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Topic :: Software Development :: Build Tools Classifier: Topic :: Software Development :: Libraries :: Python Modules PK8/5¦ ρh::EGG-INFO/SOURCES.txtCHANGES.txt README.txt bootstrap.py buildout.cfg get.py setup.py src/zc/__init__.py src/zc.buildoutsftp.egg-info/PKG-INFO src/zc.buildoutsftp.egg-info/SOURCES.txt src/zc.buildoutsftp.egg-info/dependency_links.txt src/zc.buildoutsftp.egg-info/entry_points.txt src/zc.buildoutsftp.egg-info/namespace_packages.txt src/zc.buildoutsftp.egg-info/not-zip-safe src/zc.buildoutsftp.egg-info/requires.txt src/zc.buildoutsftp.egg-info/top_level.txt src/zc/buildoutsftp/__init__.py src/zc/buildoutsftp/buildoutsftp.py src/zc/buildoutsftp/tests.py src/zc/buildoutsftp/urllib2sftp.py PK8/5“Χ2EGG-INFO/dependency_links.txt PK8/5tœb]HHEGG-INFO/entry_points.txt[zc.buildout.extension] default = zc.buildoutsftp.buildoutsftp:install PK8/5ξε"EGG-INFO/namespace_packages.txtzc PKύŽ,5“Χ2EGG-INFO/not-zip-safe PK8/5ρc,ϊEGG-INFO/requires.txtparamiko setuptoolsPK8/5ξε"EGG-INFO/top_level.txtzc PK8Ž,5Έ?bΘΘ€zc/__init__.pyPK8/5₯U:gg€τzc/__init__.pycPKΒ6.5/kΝΑ99€ˆzc/buildoutsftp/buildoutsftp.pyPKC6/53wjΔ__€ώzc/buildoutsftp/urllib2sftp.pyPKμ.-5€Œ₯€™zc/buildoutsftp/__init__.pyPK29-5a<Š  €Τzc/buildoutsftp/tests.pyPK8/5\\±11 €™"zc/buildoutsftp/buildoutsftp.pycPK8/5brM””€%zc/buildoutsftp/urllib2sftp.pycPK8/5ju††€Ω:zc/buildoutsftp/__init__.pycPK8/5=ŸθDΨ Ψ €™;zc/buildoutsftp/tests.pycPK8/5·ͺ½R3 3 €¨IEGG-INFO/PKG-INFOPK8/5¦ ρh::€ WEGG-INFO/SOURCES.txtPK8/5“Χ2€vYEGG-INFO/dependency_links.txtPK8/5tœb]HH€²YEGG-INFO/entry_points.txtPK8/5ξε"€1ZEGG-INFO/namespace_packages.txtPKύŽ,5“Χ2€qZEGG-INFO/not-zip-safePK8/5ρc,ϊ€₯ZEGG-INFO/requires.txtPK8/5ξε"€λZEGG-INFO/top_level.txtPKχ"[