PK 8,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__)
PK 8/5₯U:g g zc/__init__.pyc;ς
}+Ec @ sO y d k Z e i e Wn. e j
o" d k Z e i e e Z n Xd S( N( s
pkg_resourcess declare_namespaces __name__s ImportErrors pkgutils extend_paths __path__( s __path__s
pkg_resourcess pkgutil( ( s) build/bdist.linux-i686/egg/zc/__init__.pys ? s
PK Β6.5/kΝΑ9 9 zc/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)
)
PK C6/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#
PK 29-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()
PK 8/5\\±1 1 zc/buildoutsftp/buildoutsftp.pyc;ς
Μ4 Ec @ s" d k Z d k Z e d Z d S( Nc C s# t i t i t i i i d S( N( s urllib2s install_openers build_openers zcs buildoutsftps urllib2sftps SFTPHandler( s buildout( ( s: build/bdist.linux-i686/egg/zc/buildoutsftp/buildoutsftp.pys install s ( s urllib2s zc.buildoutsftp.urllib2sftps zcs Nones install( s urllib2s installs zc( ( s: build/bdist.linux-i686/egg/zc/buildoutsftp/buildoutsftp.pys ? s PK 8/5brM zc/buildoutsftp/urllib2sftp.pyc;ς
^
Ec @ sγ d Z d k Z d k Z d k Z d k Z d k Z d k Z d k Z d k Z d k Z d k
Z
e i d i Z
e i d j o( d k Z e i d i Z d Z n
d Z d f d YZ d e i f d
YZ d S( sO SFTP Handler for urllib2
$Id: urllib2sftp.py 70181 2006-09-14 19:39:03Z jim $
Ns. (?:([^@:]+)(?::([^@]*))?@)?([^:]*)(?::(\d+))?$s win32s (rsa|dss)2?@22:(\S+)$c C s, t i t i d }
t i } d } xϊ n oς yΧ t i |
| \ } } } | d 7} g i } | i d D] } | t | d qp ~ } t | i \ } } | d j o t i d | } n | d j o t i d | } n | i | d | | Wq* t j
o Pq* Xq1 W| Sd S(
Ns&