[Checkins] SVN: zc.urllib2sftp/branches/dev/ initial working version
Jim Fulton
jim at zope.com
Thu Sep 7 19:10:41 EDT 2006
Log message for revision 70039:
initial working version
Changed:
A zc.urllib2sftp/branches/dev/README.txt
A zc.urllib2sftp/branches/dev/bootstrap.py
A zc.urllib2sftp/branches/dev/buildout.cfg
A zc.urllib2sftp/branches/dev/setup.py
A zc.urllib2sftp/branches/dev/src/
A zc.urllib2sftp/branches/dev/src/zc/
A zc.urllib2sftp/branches/dev/src/zc/__init__.py
A zc.urllib2sftp/branches/dev/src/zc/urllib2sftp/
A zc.urllib2sftp/branches/dev/src/zc/urllib2sftp/__init__.py
-=-
Added: zc.urllib2sftp/branches/dev/README.txt
===================================================================
--- zc.urllib2sftp/branches/dev/README.txt 2006-09-07 22:45:16 UTC (rev 70038)
+++ zc.urllib2sftp/branches/dev/README.txt 2006-09-07 23:10:40 UTC (rev 70039)
@@ -0,0 +1,9 @@
+=======================
+urllib2 plugin for sftp
+=======================
+
+This package provides a urllib2 plugin for sftp. It lets you fetch
+urls like ftp URLs, except from sftp servers.
+
+If no password is specified, keys are fetched from ssh-agent.
+
Property changes on: zc.urllib2sftp/branches/dev/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: zc.urllib2sftp/branches/dev/bootstrap.py
===================================================================
--- zc.urllib2sftp/branches/dev/bootstrap.py 2006-09-07 22:45:16 UTC (rev 70038)
+++ zc.urllib2sftp/branches/dev/bootstrap.py 2006-09-07 23:10:40 UTC (rev 70039)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: zc.urllib2sftp/branches/dev/bootstrap.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zc.urllib2sftp/branches/dev/buildout.cfg
===================================================================
--- zc.urllib2sftp/branches/dev/buildout.cfg 2006-09-07 22:45:16 UTC (rev 70038)
+++ zc.urllib2sftp/branches/dev/buildout.cfg 2006-09-07 23:10:40 UTC (rev 70039)
@@ -0,0 +1,8 @@
+[buildout]
+develop = .
+parts = test
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zc.urllib2sftp
+
Property changes on: zc.urllib2sftp/branches/dev/buildout.cfg
___________________________________________________________________
Name: svn:eol-style
+ native
Added: zc.urllib2sftp/branches/dev/setup.py
===================================================================
--- zc.urllib2sftp/branches/dev/setup.py 2006-09-07 22:45:16 UTC (rev 70038)
+++ zc.urllib2sftp/branches/dev/setup.py 2006-09-07 23:10:40 UTC (rev 70039)
@@ -0,0 +1,25 @@
+from setuptools import setup
+
+name='zc.urllib2sftp'
+setup(
+ name=name,
+ version = "1.0.0a3",
+ author = "Jim Fulton",
+ author_email = "jim at zope.com",
+ description = "urllib2 plugin for sftp.",
+ long_description = open('README.txt').read(),
+ license = "ZPL 2.1",
+ keywords = "sftp",
+ url='http://www.python.org/pypi/'+name,
+
+ packages = find_packages('src'),
+ include_package_data = True,
+ package_dir = {'':'src'},
+ namespace_packages = ['zc'],
+ install_requires = ['paramiko', 'setuptools'],
+ tests_require = ['zope.testing'],
+ test_suite = name+'.tests.test_suite',
+ zip_safe=False,
+ )
+
+
Property changes on: zc.urllib2sftp/branches/dev/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zc.urllib2sftp/branches/dev/src/zc/__init__.py
===================================================================
--- zc.urllib2sftp/branches/dev/src/zc/__init__.py 2006-09-07 22:45:16 UTC (rev 70038)
+++ zc.urllib2sftp/branches/dev/src/zc/__init__.py 2006-09-07 23:10:40 UTC (rev 70039)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+ import pkg_resources
+ pkg_resources.declare_namespace(__name__)
+except ImportError:
+ import pkgutil
+ __path__ = pkgutil.extend_path(__path__, __name__)
Property changes on: zc.urllib2sftp/branches/dev/src/zc/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zc.urllib2sftp/branches/dev/src/zc/urllib2sftp/__init__.py
===================================================================
--- zc.urllib2sftp/branches/dev/src/zc/urllib2sftp/__init__.py 2006-09-07 22:45:16 UTC (rev 70038)
+++ zc.urllib2sftp/branches/dev/src/zc/urllib2sftp/__init__.py 2006-09-07 23:10:40 UTC (rev 70039)
@@ -0,0 +1,102 @@
+##############################################################################
+#
+# 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, re, stat, sys, urllib, urllib2
+import paramiko
+
+parse_host = re.compile(
+ '(?:' '([^@:]+)(?::([^@]*))?@' ')?'
+ '([^:]*)(?::(\d+))?$').match
+
+class Result:
+
+ def __init__(self, fp, url, info):
+ self._fp = fp
+ self._url = url
+ self._info = info
+
+ def geturl(self):
+ return self._url
+
+ def info(self):
+ return self._info
+
+ 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_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 '')
+
+ 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)
+ break
+ except paramiko.AuthenticationException:
+ pass
+ else:
+ raise paramiko.AuthenticationException(
+ "Authentication failed.")
+
+ sftp = paramiko.SFTPClient.from_transport(trans)
+
+ path = req.get_selector()
+ print 'Path:', path
+ url = req.get_full_url()
+ mode = sftp.stat(path).st_mode
+ if stat.S_ISDIR(mode):
+ return Result(
+ cStringIO.StringIO('\n'.join([
+ str(x)
+ for x in sftp.listdir_attr(path)
+ ])),
+ url, {})
+ else:
+ return Result(sftp.open(path), url, {})
+
+
+urllib2.install_opener(urllib2.build_opener(SFTPHandler))
+
Property changes on: zc.urllib2sftp/branches/dev/src/zc/urllib2sftp/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list