[Checkins] SVN: zc.buildoutsftp/branches/dev/ Reduce the scope of
this project because:
Jim Fulton
jim at zope.com
Tue Sep 12 18:01:18 EDT 2006
Log message for revision 70138:
Reduce the scope of this project because:
It is really at least setuptools specific and will likely end up
being buidout specific before I'm done.
I really don't know how to test this stuff. Although I might try to
do at least some lame tests by providing fake versions of paramiko
and _winreg. :(
Changed:
U zc.buildoutsftp/branches/dev/buildout.cfg
U zc.buildoutsftp/branches/dev/setup.py
A zc.buildoutsftp/branches/dev/src/zc/buildoutsftp.py
D zc.buildoutsftp/branches/dev/src/zc/urllib2sftp/__init__.py
-=-
Modified: zc.buildoutsftp/branches/dev/buildout.cfg
===================================================================
--- zc.buildoutsftp/branches/dev/buildout.cfg 2006-09-12 21:48:27 UTC (rev 70137)
+++ zc.buildoutsftp/branches/dev/buildout.cfg 2006-09-12 22:01:18 UTC (rev 70138)
@@ -4,7 +4,7 @@
[py]
recipe = zc.recipe.egg
-eggs = zc.urllib2sftp
+eggs = zc.buildoutsftp
interpreter = py
Modified: zc.buildoutsftp/branches/dev/setup.py
===================================================================
--- zc.buildoutsftp/branches/dev/setup.py 2006-09-12 21:48:27 UTC (rev 70137)
+++ zc.buildoutsftp/branches/dev/setup.py 2006-09-12 22:01:18 UTC (rev 70138)
@@ -1,15 +1,16 @@
from setuptools import setup, find_packages
-name='zc.urllib2sftp'
+name='zc.buildoutsftp'
setup(
name=name,
- version = "1.0.0a3",
+ version = "0.1",
author = "Jim Fulton",
author_email = "jim at zope.com",
- description = "urllib2 plugin for sftp.",
+ description =
+ "Specialized urllib2 plugin for sftp for use in zc.buildout.",
long_description = open('README.txt').read(),
license = "ZPL 2.1",
- keywords = "sftp",
+ keywords = "buildout",
url='http://www.python.org/pypi/'+name,
packages = find_packages('src'),
Copied: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp.py (from rev 70137, zc.buildoutsftp/branches/dev/src/zc/urllib2sftp/__init__.py)
Deleted: zc.buildoutsftp/branches/dev/src/zc/urllib2sftp/__init__.py
===================================================================
--- zc.buildoutsftp/branches/dev/src/zc/urllib2sftp/__init__.py 2006-09-12 21:48:27 UTC (rev 70137)
+++ zc.buildoutsftp/branches/dev/src/zc/urllib2sftp/__init__.py 2006-09-12 22:01:18 UTC (rev 70138)
@@ -1,135 +0,0 @@
-##############################################################################
-#
-# 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$
-"""
-
-import cStringIO, getpass, 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)@22:(\S+)$').match
- def _get_hosts_keys():
- regkey = _winreg.OpenKey(_winreg.HKEY_CURENT_USER,
- r'Software\SimonTatham\PuTTY\SshHoskKeys',
- )
- keys = paramiko.HostKeys()
- i = 0
- while 1:
- try:
- name, value, type_ = _winreg.EnumValue(regkey, i)
- i += 1
- key = paramiko.PKey(data=value)
- ktype, host = parse_reg_key_name(name).groups()
- keys.add(host, 'ssh-'+ktype, key)
- except WindowsError:
- break
-
-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([
- ('<a href="%s/%s">%s</a><br />'
- % (url, x, x)
- )
- for x in sftp.listdir(path)
- ])),
- url, {'Content-Type': 'text/html'})
- else:
- return Result(sftp.open(path), url, {})
-
-urllib2.install_opener(urllib2.build_opener(SFTPHandler))
-
More information about the Checkins
mailing list