[Checkins] SVN: z3c.blobfile/trunk/ Added bootstrap file
Uwe Oestermeier
u.oestermeier at iwm-kmrc.de
Sat Nov 10 09:37:10 EST 2007
Log message for revision 81714:
Added bootstrap file
Changed:
A z3c.blobfile/trunk/bootstrap.py
U z3c.blobfile/trunk/buildout.cfg
U z3c.blobfile/trunk/setup.py
A z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt
U z3c.blobfile/trunk/src/z3c/blobfile/file.py
-=-
Added: z3c.blobfile/trunk/bootstrap.py
===================================================================
--- z3c.blobfile/trunk/bootstrap.py (rev 0)
+++ z3c.blobfile/trunk/bootstrap.py 2007-11-10 14:37:10 UTC (rev 81714)
@@ -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: bootstrap.py 73774 2007-03-27 15:11:34Z dobe $
+"""
+
+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)
Modified: z3c.blobfile/trunk/buildout.cfg
===================================================================
--- z3c.blobfile/trunk/buildout.cfg 2007-11-10 14:17:45 UTC (rev 81713)
+++ z3c.blobfile/trunk/buildout.cfg 2007-11-10 14:37:10 UTC (rev 81714)
@@ -1,5 +1,4 @@
[buildout]
-#index = http//download.zope.org/zope3.4
develop = .
parts = test
Modified: z3c.blobfile/trunk/setup.py
===================================================================
--- z3c.blobfile/trunk/setup.py 2007-11-10 14:17:45 UTC (rev 81713)
+++ z3c.blobfile/trunk/setup.py 2007-11-10 14:37:10 UTC (rev 81714)
@@ -35,10 +35,8 @@
'Detailed Dcoumentation\n' +
'----------------------\n'
+ '\n\n' +
- read('src', 'zope', 'app', 'file', 'browser', 'file.txt')
+ read('src', 'z3c', 'blobfile', 'blobfile.txt')
+ '\n\n' +
- read('src', 'zope', 'app', 'file', 'browser', 'url.txt')
- + '\n\n' +
read('CHANGES.txt')
),
classifiers = [
Added: z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt
===================================================================
--- z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt (rev 0)
+++ z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt 2007-11-10 14:37:10 UTC (rev 81714)
@@ -0,0 +1,19 @@
+Blob File Implementation
+========================
+
+
+ >>> file = File()
+ >>> content = "This is some file\\ncontent."
+ >>> file.data = content
+ >>> file.contentType = "text/plain"
+ >>> FileReadFile(file).read() == content
+ True
+ >>> FileReadFile(file).size() == len(content)
+ True
+
+
+ >>> file = File()
+ >>> content = "This is some file\\ncontent."
+ >>> FileWriteFile(file).write(content)
+ >>> file.data == content
+ True
Modified: z3c.blobfile/trunk/src/z3c/blobfile/file.py
===================================================================
--- z3c.blobfile/trunk/src/z3c/blobfile/file.py 2007-11-10 14:17:45 UTC (rev 81713)
+++ z3c.blobfile/trunk/src/z3c/blobfile/file.py 2007-11-10 14:37:10 UTC (rev 81714)
@@ -23,6 +23,8 @@
import zope.app.publication.interfaces
from zope.app.file import interfaces
+from ZODB.blob import Blob
+
# set the size of the chunks
MAXCHUNKSIZE = 1 << 16
@@ -118,167 +120,136 @@
implements(zope.app.publication.interfaces.IFileContent, interfaces.IFile)
+ _data = ""
+ size = 0
+
def __init__(self, data='', contentType=''):
- self.data = data
+ self._data = Blob()
self.contentType = contentType
+ fp = self._data.open('w')
+ fp.write(data)
+ fp.close()
- def _getData(self):
- if isinstance(self._data, FileChunk):
- return str(self._data)
- else:
- return self._data
+# def _getData(self):
+# if isinstance(self._data, FileChunk):
+# return str(self._data)
+# else:
+# return self._data
+#
+# def _setData(self, data) :
+#
+# # Handle case when data is a string
+# if isinstance(data, unicode):
+# data = data.encode('UTF-8')
+#
+# if isinstance(data, str):
+# self._data, self._size = FileChunk(data), len(data)
+# return
+#
+# # Handle case when data is None
+# if data is None:
+# raise TypeError('Cannot set None data on a file.')
+#
+# # Handle case when data is already a FileChunk
+# if isinstance(data, FileChunk):
+# size = len(data)
+# self._data, self._size = data, size
+# return
+#
+# # Handle case when data is a file object
+# seek = data.seek
+# read = data.read
+#
+# seek(0, 2)
+# size = end = data.tell()
+#
+# if size <= 2*MAXCHUNKSIZE:
+# seek(0)
+# if size < MAXCHUNKSIZE:
+# self._data, self._size = read(size), size
+# return
+# self._data, self._size = FileChunk(read(size)), size
+# return
+#
+# # Make sure we have an _p_jar, even if we are a new object, by
+# # doing a sub-transaction commit.
+# transaction.savepoint(optimistic=True)
+#
+# jar = self._p_jar
+#
+# if jar is None:
+# # Ugh
+# seek(0)
+# self._data, self._size = FileChunk(read(size)), size
+# return
+#
+# # Now we're going to build a linked list from back
+# # to front to minimize the number of database updates
+# # and to allow us to get things out of memory as soon as
+# # possible.
+# next = None
+# while end > 0:
+# pos = end - MAXCHUNKSIZE
+# if pos < MAXCHUNKSIZE:
+# pos = 0 # we always want at least MAXCHUNKSIZE bytes
+# seek(pos)
+# data = FileChunk(read(end - pos))
+#
+# # Woooop Woooop Woooop! This is a trick.
+# # We stuff the data directly into our jar to reduce the
+# # number of updates necessary.
+# jar.add(data)
+#
+# # This is needed and has side benefit of getting
+# # the thing registered:
+# data.next = next
+#
+# # Now make it get saved in a sub-transaction!
+# transaction.savepoint(optimistic=True)
+#
+# # Now make it a ghost to free the memory. We
+# # don't need it anymore!
+# data._p_changed = None
+#
+# next = data
+# end = pos
+#
+# self._data, self._size = next, size
+# return
- def _setData(self, data) :
+# data = property(_getData, _setData)
+
+
+ @property
+ def size(self):
+ if self._data == "":
+ return 0
+ reader = self.open()
+ reader.seek(0,2)
+ size = int(reader.tell())
+ reader.close()
+ return size
- # Handle case when data is a string
- if isinstance(data, unicode):
- data = data.encode('UTF-8')
- if isinstance(data, str):
- self._data, self._size = FileChunk(data), len(data)
- return
- # Handle case when data is None
- if data is None:
- raise TypeError('Cannot set None data on a file.')
-
- # Handle case when data is already a FileChunk
- if isinstance(data, FileChunk):
- size = len(data)
- self._data, self._size = data, size
- return
-
- # Handle case when data is a file object
- seek = data.seek
- read = data.read
-
- seek(0, 2)
- size = end = data.tell()
-
- if size <= 2*MAXCHUNKSIZE:
- seek(0)
- if size < MAXCHUNKSIZE:
- self._data, self._size = read(size), size
- return
- self._data, self._size = FileChunk(read(size)), size
- return
-
- # Make sure we have an _p_jar, even if we are a new object, by
- # doing a sub-transaction commit.
- transaction.savepoint(optimistic=True)
-
- jar = self._p_jar
-
- if jar is None:
- # Ugh
- seek(0)
- self._data, self._size = FileChunk(read(size)), size
- return
-
- # Now we're going to build a linked list from back
- # to front to minimize the number of database updates
- # and to allow us to get things out of memory as soon as
- # possible.
- next = None
- while end > 0:
- pos = end - MAXCHUNKSIZE
- if pos < MAXCHUNKSIZE:
- pos = 0 # we always want at least MAXCHUNKSIZE bytes
- seek(pos)
- data = FileChunk(read(end - pos))
-
- # Woooop Woooop Woooop! This is a trick.
- # We stuff the data directly into our jar to reduce the
- # number of updates necessary.
- jar.add(data)
-
- # This is needed and has side benefit of getting
- # the thing registered:
- data.next = next
-
- # Now make it get saved in a sub-transaction!
- transaction.savepoint(optimistic=True)
-
- # Now make it a ghost to free the memory. We
- # don't need it anymore!
- data._p_changed = None
-
- next = data
- end = pos
-
- self._data, self._size = next, size
- return
-
- def getSize(self):
- '''See `IFile`'''
- return self._size
-
- # See IFile.
- data = property(_getData, _setData)
-
-
-class FileChunk(Persistent):
- """Wrapper for possibly large data"""
-
- next = None
-
- def __init__(self, data):
- self._data = data
-
- def __getslice__(self, i, j):
- return self._data[i:j]
-
- def __len__(self):
- data = str(self)
- return len(data)
-
- def __str__(self):
- next = self.next
- if next is None:
- return self._data
-
- result = [self._data]
- while next is not None:
- self = next
- result.append(self._data)
- next = self.next
-
- return ''.join(result)
-
-
class FileReadFile(object):
- '''Adapter for file-system style read access.
-
- >>> file = File()
- >>> content = "This is some file\\ncontent."
- >>> file.data = content
- >>> file.contentType = "text/plain"
- >>> FileReadFile(file).read() == content
- True
- >>> FileReadFile(file).size() == len(content)
- True
- '''
+ """Adapter for file-system style read access."""
+
def __init__(self, context):
self.context = context
- def read(self):
+ def read(self, bytes=-1):
return self.context.data
def size(self):
- return len(self.context.data)
+ return self.context.size
class FileWriteFile(object):
- """Adapter for file-system style write access.
-
- >>> file = File()
- >>> content = "This is some file\\ncontent."
- >>> FileWriteFile(file).write(content)
- >>> file.data == content
- True
- """
+ """Adapter for file-system style write access."""
+
def __init__(self, context):
self.context = context
def write(self, data):
- self.context.data = data
+ self.context.write(data)
More information about the Checkins
mailing list