[Checkins] SVN: zope.file/branches/ajung-blobs/src/zope/file/ savepoint

Andreas Jung andreas at andreas-jung.com
Mon Feb 26 17:10:11 EST 2007


Log message for revision 72839:
  savepoint
  

Changed:
  U   zope.file/branches/ajung-blobs/src/zope/file/README.txt
  U   zope.file/branches/ajung-blobs/src/zope/file/file.py
  U   zope.file/branches/ajung-blobs/src/zope/file/upload.py

-=-
Modified: zope.file/branches/ajung-blobs/src/zope/file/README.txt
===================================================================
--- zope.file/branches/ajung-blobs/src/zope/file/README.txt	2007-02-26 21:09:33 UTC (rev 72838)
+++ zope.file/branches/ajung-blobs/src/zope/file/README.txt	2007-02-26 22:10:10 UTC (rev 72839)
@@ -91,7 +91,7 @@
 
 We need to close the file first before determining its file size
 
-  >>  w.close()
+  >>> w.close()
   >>> f.size
   19
 
@@ -106,31 +106,16 @@
   >>> r.tell()
   19
 
-The writer can continue to be used to add data::
 
-  >>> w.write(" still more")
-  >>> w.flush()
-  >>> f.size
-  30
 
-The reader can now see the new data, and continue reading from where
-it was::
-
-  >>> r.read(6)
-  ' still'
-  >>> r.read()
-  ' more'
-  >>> r.read()
-  ''
-
 The reader also has a `seek()` method that can be used to back up or
 skip forward in the data stream.  Simply passing an offset argument,
 we see that the current position is moved to that offset from the
 start of the file::
 
-  >>> r.seek(20)
+  >>> r.seek(10)
   >>> r.read()
-  'still more'
+  'more text'
 
 That's equivalent to passing 0 as the `whence` argument::
 

Modified: zope.file/branches/ajung-blobs/src/zope/file/file.py
===================================================================
--- zope.file/branches/ajung-blobs/src/zope/file/file.py	2007-02-26 21:09:33 UTC (rev 72838)
+++ zope.file/branches/ajung-blobs/src/zope/file/file.py	2007-02-26 22:10:10 UTC (rev 72839)
@@ -15,6 +15,7 @@
 """
 __docformat__ = "reStructuredText"
 
+import sys
 import cStringIO
 
 import persistent
@@ -46,6 +47,9 @@
             parameters = dict(parameters)
         self.parameters = parameters
         self._data = Blob()
+        fp = self._data.open('w')
+        fp.write('')
+        fp.close()
 
     def open(self, mode="r"):
         if mode.startswith("r"):
@@ -74,6 +78,7 @@
     _closed = False
     _sio = None
     _write = False
+    mode = None
 
     # XXX Accessor objects need to have an __parent__ to support the
     # security machinery, but they aren't ILocation instances since
@@ -85,11 +90,12 @@
 
     def __init__(self, file, mode):
         self.__parent__ = file
+        self.mode = mode
         self._stream = self.__parent__._data.open(mode)
 
     def close(self):
         if not self._closed:
-            self._stream.close()
+            self._close()
             self._closed = True
 
     def __getstate__(self):
@@ -102,6 +108,8 @@
     def stream(self):
         return self._stream
 
+    def _close(self):
+        pass
 
 
 class Reader(Accessor):
@@ -126,12 +134,12 @@
     def tell(self):
         if self._closed:
             raise ValueError("I/O operation on closed file")
-        if self._sio is None:
-            return 0L
-        else:
-            return self._sio.tell()
+        return int(self.stream.tell())
 
+    def _close(self):
+        self.stream.close()
 
+
 class Writer(Accessor):
 
     zope.interface.implements(
@@ -142,15 +150,13 @@
     def flush(self):
         if self._closed:
             raise ValueError("I/O operation on closed file")
-        if self._sio is not None:
-            self.__parent__._data = self._sio.getvalue()
-            self._data = self.__parent__._data
-
+        self.stream.flush()
+    
     def write(self, data):
         if self._closed:
             raise ValueError("I/O operation on closed file")
         self.stream.write(data)
 
     def _close(self):
-        self.flush()
+        self.stream.close()
 

Modified: zope.file/branches/ajung-blobs/src/zope/file/upload.py
===================================================================
--- zope.file/branches/ajung-blobs/src/zope/file/upload.py	2007-02-26 21:09:33 UTC (rev 72838)
+++ zope.file/branches/ajung-blobs/src/zope/file/upload.py	2007-02-26 22:10:10 UTC (rev 72839)
@@ -158,6 +158,5 @@
         ob.mimeType = mimeType
         ob.parameters = {}
     w = ob.open("wb")
-    import pdb; pdb.set_trace() 
     w.write(data)
     w.close()



More information about the Checkins mailing list