[Zope3-checkins] CVS: Zope3/src/zope/fssync - fssync.py:1.30

Guido van Rossum guido@python.org
Wed, 4 Jun 2003 17:48:28 -0400


Update of /cvs-repository/Zope3/src/zope/fssync
In directory cvs.zope.org:/tmp/cvs-serv20622

Modified Files:
	fssync.py 
Log Message:
Refactor commit(), making datasource() into a class.  (Preparing for
adding checkin().)  Remove a redundant try: ... finally: pass block!


=== Zope3/src/zope/fssync/fssync.py 1.29 => 1.30 ===
--- Zope3/src/zope/fssync/fssync.py:1.29	Mon Jun  2 13:09:19 2003
+++ Zope3/src/zope/fssync/fssync.py	Wed Jun  4 17:48:28 2003
@@ -257,6 +257,19 @@
         self.conn.send("%x\r\n" % len(s))
         self.conn.send(s)
 
+class DataSource(object):
+
+    """Helper class to provide a data source for httpreq."""
+
+    def __init__(self, head, tail):
+        self.head = head
+        self.tail = tail
+
+    def __call__(self, f):
+        snf = Snarfer(f)
+        snf.add(join(self.head, self.tail), self.tail)
+        snf.addtree(join(self.head, "@@Zope"), "@@Zope/")
+
 class FSSync(object):
 
     def __init__(self, metadata=None, network=None, rooturl=None):
@@ -308,20 +321,14 @@
             raise Error("nothing known about", target)
         self.network.loadrooturl(target)
         path = entry["path"]
+        view = "@@fromFS.snarf?note=%s" % urllib.quote(note)
         head, tail = split(realpath(target))
+        data = DataSource(head, tail)
+        fp, headers = self.network.httpreq(path, view, data)
         try:
-            view = "@@fromFS.snarf?note=%s" % urllib.quote(note)
-            def datasource(f):
-                snf = Snarfer(f)
-                snf.add(join(head, tail), tail)
-                snf.addtree(join(head, "@@Zope"), "@@Zope/")
-            outfp, headers = self.network.httpreq(path, view, datasource)
+            self.merge_snarffile(fp, head, tail)
         finally:
-            pass
-        try:
-            self.merge_snarffile(outfp, head, tail)
-        finally:
-            outfp.close()
+            fp.close()
 
     def update(self, target):
         entry = self.metadata.getentry(target)