[Checkins] SVN: zc.buildoutsftp/branches/dev/ More rearranging.

Jim Fulton jim at zope.com
Wed Sep 13 07:22:00 EDT 2006


Log message for revision 70142:
  More rearranging.
  

Changed:
  U   zc.buildoutsftp/branches/dev/README.txt
  A   zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/
  A   zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/__init__.py
  A   zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/buildoutsftp.py
  A   zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/urllib2sftp.py
  D   zc.buildoutsftp/branches/dev/src/zc/buildoutsftp.py
  D   zc.buildoutsftp/branches/dev/src/zc/urllib2sftp/

-=-
Modified: zc.buildoutsftp/branches/dev/README.txt
===================================================================
--- zc.buildoutsftp/branches/dev/README.txt	2006-09-13 09:26:01 UTC (rev 70141)
+++ zc.buildoutsftp/branches/dev/README.txt	2006-09-13 11:21:59 UTC (rev 70142)
@@ -1,9 +1,42 @@
-=======================
-urllib2 plugin for sftp
-=======================
+===========================================
+Secure FTP (SFTP) Extension for zc.buildout
+===========================================
 
-This package provides a urllib2 plugin for sftp.  It lets you fetch
-urls like ftp URLs, except from sftp servers.
+The zc.buildoutsftp package provides a zc.buildout extension that
+provides support for SFTP.  To use it, simple provide the option::
 
-If no password is specified, keys are fetched from ssh-agent.
+  extension = zc.buildoutsftp 
 
+in your buildout section. Then you can use sftp URLs for fine-links or
+index URLs.
+
+An SFTP URL is similar to an FTP URL and is of the form::
+
+  sftp:://user:password at hostname:port/path
+
+where the user name, password, and port are optional.  Here are some
+examples:
+
+sftp://download.zope.org/distribution
+   This accesses the path /distribution on download.zope.org
+
+sftp://jim@download.zope.org/distribution
+   This accesses the path /distribution on download.zope.org using the
+   user id jim.
+
+sftp://jim:123@download.zope.org/distribution
+   This accesses the path /distribution on download.zope.org using the
+   user id jim and password 123.
+
+sftp://download.zope.org:1022/distribution
+   This accesses the path /distribution on download.zope.org using an
+   ssh server running on port 1022.
+
+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.
+

Added: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/__init__.py
===================================================================
--- zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/__init__.py	2006-09-13 09:26:01 UTC (rev 70141)
+++ zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/__init__.py	2006-09-13 11:21:59 UTC (rev 70142)
@@ -0,0 +1 @@
+#


Property changes on: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/buildoutsftp.py
===================================================================
--- zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/buildoutsftp.py	2006-09-13 09:26:01 UTC (rev 70141)
+++ zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/buildoutsftp.py	2006-09-13 11:21:59 UTC (rev 70142)
@@ -0,0 +1,21 @@
+##############################################################################
+#
+# 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.buildout2sftp.urllib2sftp
+
+def install(buildout=None):
+    urllib2.install_opener(
+        urllib2.build_opener(zc.buildout2sftp.urllib2sftp.SFTPHandler)
+        )


Property changes on: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/buildoutsftp.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Copied: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/urllib2sftp.py (from rev 70138, zc.buildoutsftp/branches/dev/src/zc/buildoutsftp.py)
===================================================================
--- zc.buildoutsftp/branches/dev/src/zc/buildoutsftp.py	2006-09-12 22:01:18 UTC (rev 70138)
+++ zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/urllib2sftp.py	2006-09-13 11:21:59 UTC (rev 70142)
@@ -0,0 +1,133 @@
+##############################################################################
+#
+# 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, {})
+        

Deleted: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp.py
===================================================================
--- zc.buildoutsftp/branches/dev/src/zc/buildoutsftp.py	2006-09-13 09:26:01 UTC (rev 70141)
+++ zc.buildoutsftp/branches/dev/src/zc/buildoutsftp.py	2006-09-13 11:21:59 UTC (rev 70142)
@@ -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