[Checkins] SVN: z3c.extfile/trunk/ some paste fixes

Bernd Dorn bernd.dorn at lovelysystems.com
Tue Jan 8 11:59:48 EST 2008


Log message for revision 82753:
  some paste fixes

Changed:
  U   z3c.extfile/trunk/CHANGES.txt
  U   z3c.extfile/trunk/setup.py
  U   z3c.extfile/trunk/src/z3c/extfile/README.txt
  U   z3c.extfile/trunk/src/z3c/extfile/filter.py
  U   z3c.extfile/trunk/src/z3c/extfile/processor.py
  U   z3c.extfile/trunk/src/z3c/extfile/property.py

-=-
Modified: z3c.extfile/trunk/CHANGES.txt
===================================================================
--- z3c.extfile/trunk/CHANGES.txt	2008-01-08 16:36:17 UTC (rev 82752)
+++ z3c.extfile/trunk/CHANGES.txt	2008-01-08 16:59:48 UTC (rev 82753)
@@ -2,6 +2,14 @@
 Changes for z3c.extfile
 =======================
 
+After
+=====
+
+- updated config example in README.txt for paste deployment
+
+- make filter and processor handle locking sockets correctly which are
+  used by paste
+
 0.1.1 (2007-11-22)
 ==================
 

Modified: z3c.extfile/trunk/setup.py
===================================================================
--- z3c.extfile/trunk/setup.py	2008-01-08 16:36:17 UTC (rev 82752)
+++ z3c.extfile/trunk/setup.py	2008-01-08 16:59:48 UTC (rev 82753)
@@ -2,7 +2,7 @@
 
 setup(
     name = "z3c.extfile",
-    version = "0.1.1",
+    version = "0.1.2",
     author = "Zope Contributors",
     author_email = "zope3-dev at zope.org",
     description = "Large file handling for zope3",

Modified: z3c.extfile/trunk/src/z3c/extfile/README.txt
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/README.txt	2008-01-08 16:36:17 UTC (rev 82752)
+++ z3c.extfile/trunk/src/z3c/extfile/README.txt	2008-01-08 16:59:48 UTC (rev 82753)
@@ -57,11 +57,9 @@
 
 Example paste.ini::
 
- [pipeline:Paste.Main]
- pipeline = fs main
-
  [app:main]
  paste.app_factory = zope.paste.application:zope_publisher_app_factory
+ filter-with = fs
 
  [filter:fs]
  paste.filter_factory = z3c.extfile.filter:filter_factory

Modified: z3c.extfile/trunk/src/z3c/extfile/filter.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/filter.py	2008-01-08 16:36:17 UTC (rev 82752)
+++ z3c.extfile/trunk/src/z3c/extfile/filter.py	2008-01-08 16:59:48 UTC (rev 82753)
@@ -25,7 +25,12 @@
             fp = env['wsgi.input']
             out = StringIO()
             proc = processor.Processor(self.hd)
-            proc.pushInput(fp, out)
+            cl = env.get('CONTENT_LENGTH')
+            if not cl:
+                raise RuntimeError, "No content-length header found"
+            cl = int(cl)
+            proc.pushInput(fp, out, cl)
+            env['CONTENT_LENGTH'] = out.tell()
             out.seek(0)
             env['wsgi.input'] = out
         elif env.get('REQUEST_METHOD') in ('GET',):

Modified: z3c.extfile/trunk/src/z3c/extfile/processor.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/processor.py	2008-01-08 16:36:17 UTC (rev 82752)
+++ z3c.extfile/trunk/src/z3c/extfile/processor.py	2008-01-08 16:59:48 UTC (rev 82753)
@@ -1,5 +1,9 @@
 import time
+import os
+import stat
 
+BLOCK_SIZE = 1024*128
+
 def parse_header(s):
     l = [e.strip() for e in s.split(';')]
     result_value = l.pop(0).lower()
@@ -25,14 +29,17 @@
         # replaced by the current handle method for this state.
         self.handle = self.handle_first_boundary
 
-    def pushInput(self, fp, out):
-        while True:
-            s = fp.read(1024*128)
-            if not s:
-                return
-            lines = s.splitlines(True)
-            for line in lines:
-                self.pushInputLine(line, out)
+    def pushInput(self, fp, out, length=None):
+        if length is None and isinstance(fp, file):
+            length = int(os.stat(fp.name)[stat.ST_SIZE])
+        pos = 0
+        bufsize = getattr(fp, 'bufsize', BLOCK_SIZE)
+        while pos<length:
+            chunk = min(length-pos, bufsize)
+            pos += chunk
+            s = fp.read(chunk)
+            for line in s.splitlines(True):
+                self.pushInputLine(line,out)
 
     def pushInputLine(self, data, out):
         # collect data
@@ -56,7 +63,7 @@
         self.init_headers()
         self.handle = self.handle_headers
         out.write(line)
-        
+
     def init_headers(self):
         self._disposition = None
         self._disposition_options = {}
@@ -91,7 +98,7 @@
         self._f = self.hd.new()
         self._previous_line = None
         self.handle = self.handle_file_data
-        
+
     def handle_data(self, line, out):
         out.write(line)
         if line == self._boundary:

Modified: z3c.extfile/trunk/src/z3c/extfile/property.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/property.py	2008-01-08 16:36:17 UTC (rev 82752)
+++ z3c.extfile/trunk/src/z3c/extfile/property.py	2008-01-08 16:59:48 UTC (rev 82753)
@@ -31,6 +31,8 @@
     def __set__(self, inst, value):
         # ignore if value is None
         if value is None:
+            if inst.__dict__.has_key(self.__name):
+                del inst.__dict__[self.__name]
             return
         # Handle case when value is a string
         if isinstance(value, unicode):



More information about the Checkins mailing list