[CMF-checkins] SVN: CMF/branches/tseaver-pkg_resources/CMFCore/FS -
Move resource vs. direct path knowledge into FSObject.
Tres Seaver
tseaver at palladion.com
Wed Oct 26 16:51:03 EDT 2005
Log message for revision 39654:
- Move resource vs. direct path knowledge into FSObject.
Changed:
U CMF/branches/tseaver-pkg_resources/CMFCore/FSDTMLMethod.py
U CMF/branches/tseaver-pkg_resources/CMFCore/FSFile.py
U CMF/branches/tseaver-pkg_resources/CMFCore/FSImage.py
U CMF/branches/tseaver-pkg_resources/CMFCore/FSObject.py
U CMF/branches/tseaver-pkg_resources/CMFCore/FSPageTemplate.py
U CMF/branches/tseaver-pkg_resources/CMFCore/FSPropertiesObject.py
U CMF/branches/tseaver-pkg_resources/CMFCore/FSPythonScript.py
U CMF/branches/tseaver-pkg_resources/CMFCore/FSSTXMethod.py
U CMF/branches/tseaver-pkg_resources/CMFCore/FSZSQLMethod.py
-=-
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSDTMLMethod.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSDTMLMethod.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSDTMLMethod.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -31,7 +31,6 @@
from permissions import ViewManagementScreens
from utils import _dtmldir
from utils import _setCacheHeaders
-from utils import expandpath
_marker = [] # Create a new marker object.
@@ -79,16 +78,7 @@
return DTMLMethod(self.read(), __name__=self.getId())
def _readFile(self, reparse):
- if self._filepath is None:
- data = resource_string(self._package, self._entry_subpath)
- else:
- fp = expandpath(self._filepath)
- file = open(fp, 'r') # not 'rb', as this is a text file!
- try:
- data = file.read()
- finally:
- file.close()
- self.raw = data
+ self.raw = self._readFileAsResourceOrDirect()
if reparse:
self._reading = 1 # Avoid infinite recursion
try:
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSFile.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSFile.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSFile.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -31,7 +31,6 @@
from permissions import ViewManagementScreens
from utils import _dtmldir
from utils import _setCacheHeaders, _ViewEmulator
-from utils import expandpath
class FSFile(FSObject):
@@ -85,10 +84,7 @@
return content_type
def _readFile(self, reparse):
- fp = expandpath(self._filepath)
- file = open(fp, 'rb')
- try: data = file.read()
- finally: file.close()
+ data = self._readFileAsResourceOrDirect()
if reparse or self.content_type == 'unknown/unknown':
self.ZCacheable_invalidate()
self.content_type=self._get_content_type(file, data, self.id)
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSImage.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSImage.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSImage.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -20,7 +20,8 @@
from AccessControl import ClassSecurityInfo
from webdav.common import rfc1123_date
from OFS.Cache import Cacheable
-from OFS.Image import Image, getImageInfo
+from OFS.Image import Image
+from OFS.Image import getImageInfo
from permissions import FTPAccess
from permissions import View
@@ -29,8 +30,8 @@
from DirectoryView import registerMetaType
from FSObject import FSObject
from utils import _dtmldir
-from utils import _setCacheHeaders, _ViewEmulator
-from utils import expandpath
+from utils import _ViewEmulator
+from utils import _setCacheHeaders
class FSImage(FSObject):
@@ -63,12 +64,7 @@
return Image(self.getId(), '', self._readFile(1))
def _readFile(self, reparse):
- fp = expandpath(self._filepath)
- file = open(fp, 'rb')
- try:
- data = self._data = file.read()
- finally:
- file.close()
+ data = self._readFileAsResourceOrDirect()
if reparse or self.content_type == 'unknown/unknown':
self.ZCacheable_invalidate()
ct, width, height = getImageInfo( data )
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSObject.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSObject.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSObject.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -15,7 +15,9 @@
$Id$
"""
-from os import path, stat
+from os import path
+from os import stat
+from pkg_resources import resource_string
import Globals
from AccessControl import ClassSecurityInfo
@@ -208,6 +210,20 @@
self._updateFromFS()
return self._filepath
+ security.declarePrivate('_readFileAsResourceOrDirect')
+ def _readFileAsResourceOrDirect(self):
+ """ Return our file's bits, looking in the appropriate place.
+ """
+ if self._filepath is None:
+ return resource_string(self._package, self._entry_subpath)
+ else:
+ fp = expandpath(self._filepath)
+ file = open(fp, 'r') # not 'rb', as this is a text file!
+ try:
+ return file.read()
+ finally:
+ file.close()
+
Globals.InitializeClass(FSObject)
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSPageTemplate.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSPageTemplate.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSPageTemplate.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -32,7 +32,6 @@
from permissions import View
from permissions import ViewManagementScreens
from utils import _setCacheHeaders, _checkConditionalGET
-from utils import expandpath
xml_detect_re = re.compile('^\s*<\?xml\s+(?:[^>]*?encoding=["\']([^"\'>]+))?')
_marker = [] # Create a new marker object.
@@ -81,15 +80,7 @@
# return 0
def _readFile(self, reparse):
- if self._filepath is None:
- data = resource_string(self._package, self._entry_subpath)
- else:
- fp = expandpath(self._filepath)
- file = open(fp, 'r') # not 'rb', as this is a text file!
- try:
- data = file.read()
- finally:
- file.close()
+ data = self._readFileAsResourceOrDirect()
if reparse:
# If we already have a content_type set it must come from a
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSPropertiesObject.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSPropertiesObject.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSPropertiesObject.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -26,9 +26,7 @@
from FSObject import FSObject
from permissions import ViewManagementScreens
from utils import _dtmldir
-from utils import expandpath
-
class FSPropertiesObject (FSObject, PropertyManager):
"""FSPropertiesObjects simply hold properties."""
@@ -89,14 +87,9 @@
Read the file (indicated by exandpath(self._filepath), and parse the
data if necessary.
"""
- fp = expandpath(self._filepath)
+ data = self._readFileAsResourceOrDirect()
+ lines = data.splitlines()
- file = open(fp, 'r') # not 'rb', as this is a text file!
- try:
- lines = file.readlines()
- finally:
- file.close()
-
map = []
lino=0
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSPythonScript.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSPythonScript.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSPythonScript.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -87,12 +87,8 @@
Read the file (indicated by exandpath(self._filepath), and parse the
data if necessary.
"""
- fp = expandpath(self._filepath)
- file = open(fp, 'r')
- try: data = file.read()
- finally: file.close()
- if reparse:
- self._write(data, reparse)
+ data = self._readFileAsResourceOrDirect()
+ self._write(data, reparse)
def _validateProxy(self, roles=None):
pass
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSSTXMethod.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSSTXMethod.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSSTXMethod.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -65,16 +65,7 @@
def _readFile( self, reparse ):
- fp = expandpath( self._filepath )
- file = open( fp, 'r' ) # not binary, we want CRLF munging here.
-
- try:
- data = file.read()
- finally:
- file.close()
-
- self.raw = data
-
+ self.raw = self._readFileAsResourceOrDirect()
if reparse:
self.cook()
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSZSQLMethod.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSZSQLMethod.py 2005-10-26 20:22:09 UTC (rev 39653)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSZSQLMethod.py 2005-10-26 20:51:03 UTC (rev 39654)
@@ -27,9 +27,7 @@
from permissions import View
from permissions import ViewManagementScreens
from utils import _dtmldir
-from utils import expandpath
-
class FSZSQLMethod(SQL, FSObject):
"""FSZSQLMethods act like Z SQL Methods but are not directly
modifiable from the management interface."""
@@ -80,11 +78,7 @@
return s
def _readFile(self, reparse):
- fp = expandpath(self._filepath)
- file = open(fp, 'r') # not 'rb', as this is a text file!
- try:
- data = file.read()
- finally: file.close()
+ data = self._readFileAsResourceOrDirect()
# parse parameters
parameters={}
More information about the CMF-checkins
mailing list