[Checkins] SVN: Products.CMFCore/trunk/Products/CMFCore/ - use getConfiguration instead of Globals
Yvo Schubbe
y.2011 at wcm-solutions.de
Sat Feb 5 07:43:36 EST 2011
Log message for revision 120117:
- use getConfiguration instead of Globals
- enabled more DebugModeTests
- some related header, whitespace and import cleanup
Changed:
U Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt
UU Products.CMFCore/trunk/Products/CMFCore/FSObject.py
UU Products.CMFCore/trunk/Products/CMFCore/FSPropertiesObject.py
UU Products.CMFCore/trunk/Products/CMFCore/FSZSQLMethod.py
UU Products.CMFCore/trunk/Products/CMFCore/tests/base/testcase.py
U Products.CMFCore/trunk/Products/CMFCore/tests/test_FSSecurity.py
-=-
Modified: Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt 2011-02-05 11:35:48 UTC (rev 120116)
+++ Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt 2011-02-05 12:43:36 UTC (rev 120117)
@@ -4,6 +4,9 @@
2.3.0-alpha (unreleased)
------------------------
+- DirectoryView: Modernized debug mode lookup.
+ Now getConfiguration().debug_mode is used instead of Globals.DevelopmentMode.
+
- Fix content exportimport when Title or Description are unicode (merge from
2.2 branch).
Modified: Products.CMFCore/trunk/Products/CMFCore/FSObject.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/FSObject.py 2011-02-05 11:35:48 UTC (rev 120116)
+++ Products.CMFCore/trunk/Products/CMFCore/FSObject.py 2011-02-05 12:43:36 UTC (rev 120117)
@@ -11,14 +11,11 @@
#
##############################################################################
""" Customizable objects that come from the filesystem (base class).
-
-$Id$
"""
import os
from AccessControl.Permission import Permission
-
try:
from OFS.role import RoleManager
except ImportError:
@@ -30,6 +27,7 @@
from Acquisition import aq_parent
from Acquisition import Implicit
from App.class_init import InitializeClass
+from App.config import getConfiguration
from App.special_dtml import HTML
from DateTime.DateTime import DateTime
from OFS.Cache import Cacheable
@@ -76,9 +74,9 @@
self._filepath = filepath
try:
- self._file_mod_time = os.stat(filepath)[8]
+ self._file_mod_time = os.stat(filepath)[8]
except:
- pass
+ pass
self._readFile(0)
security.declareProtected(ViewManagementScreens, 'manage_doCustomize')
@@ -95,8 +93,8 @@
# Preserve cache manager associations
cachemgr_id = self.ZCacheable_getManagerId()
- if ( cachemgr_id and
- getattr(obj, 'ZCacheable_setManagerId', None) is not None ):
+ if cachemgr_id and \
+ getattr(obj, 'ZCacheable_setManagerId', None) is not None:
obj.ZCacheable_setManagerId(cachemgr_id)
# If there are proxy roles we preserve them
@@ -128,7 +126,7 @@
skins_tool_name = 'portal_skins'
id = obj.getId()
- fpath = tuple( folder_path.split('/') )
+ fpath = tuple(folder_path.split('/'))
if root is None:
portal_skins = getToolByName(self, skins_tool_name)
else:
@@ -172,9 +170,8 @@
# Refresh our contents from the filesystem if that is newer and we are
# running in debug mode.
def _updateFromFS(self):
- import Globals # for data
parsed = self._parsed
- if not parsed or Globals.DevelopmentMode:
+ if not parsed or getConfiguration().debug_mode:
try:
mtime = os.stat(self._filepath)[8]
except:
@@ -237,8 +234,8 @@
manage_options = ({'label':'Error', 'action':'manage_showError'},)
- def __init__( self, id, filepath, exc_str=''
- , fullname=None, properties=None):
+ def __init__(self, id, filepath, exc_str='', fullname=None,
+ properties=None):
id = fullname or id # Use the whole filename.
self.exc_str = exc_str
self.file_contents = ''
@@ -246,12 +243,13 @@
security = ClassSecurityInfo()
- showError = HTML( BAD_FILE_VIEW )
+ showError = HTML(BAD_FILE_VIEW)
+
security.declareProtected(ManagePortal, 'manage_showError')
- def manage_showError( self, REQUEST ):
+ def manage_showError(self, REQUEST):
"""
"""
- return self.showError( self, REQUEST )
+ return self.showError(self, REQUEST)
security.declarePrivate('_readFile')
def _readFile(self, reparse):
@@ -267,19 +265,19 @@
data = self.file_contents = None #give up
return data
- security.declarePublic( 'getFileContents' )
- def getFileContents( self ):
+ security.declarePublic('getFileContents')
+ def getFileContents(self):
"""
Return the contents of the file, if we could read it.
"""
return self.file_contents
- security.declarePublic( 'getExceptionText' )
- def getExceptionText( self ):
+ security.declarePublic('getExceptionText')
+ def getExceptionText(self):
"""
Return the exception thrown while reading or parsing
the file.
"""
return self.exc_str
-InitializeClass( BadFile )
+InitializeClass(BadFile)
Property changes on: Products.CMFCore/trunk/Products/CMFCore/FSObject.py
___________________________________________________________________
Deleted: svn:keywords
- Author Date Id Revision
Modified: Products.CMFCore/trunk/Products/CMFCore/FSPropertiesObject.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/FSPropertiesObject.py 2011-02-05 11:35:48 UTC (rev 120116)
+++ Products.CMFCore/trunk/Products/CMFCore/FSPropertiesObject.py 2011-02-05 12:43:36 UTC (rev 120117)
@@ -11,15 +11,13 @@
#
##############################################################################
""" Customizable properties that come from the filesystem.
-
-$Id$
"""
from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import ImplicitAcquisitionWrapper
from App.class_init import InitializeClass
+from App.config import getConfiguration
from App.special_dtml import DTMLFile
-import Globals # for data
from OFS.Folder import Folder
from OFS.PropertyManager import PropertyManager
from ZPublisher.Converters import get_converter
@@ -86,7 +84,7 @@
setattr(obj, p['id'], getattr(self, p['id']))
map.append({'id': p['id'],
'type': p['type'],
- 'mode': 'wd',})
+ 'mode': 'wd', })
obj._properties = tuple(map)
return obj
@@ -101,7 +99,7 @@
file.close()
map = []
- lino=0
+ lino = 0
for line in lines:
@@ -112,14 +110,14 @@
continue
try:
- propname, proptv = line.split(':',1)
+ propname, proptv = line.split(':', 1)
#XXX multi-line properties?
- proptype, propvstr = proptv.split( '=', 1 )
+ proptype, propvstr = proptv.split('=', 1)
propname = propname.strip()
proptype = proptype.strip()
propvstr = propvstr.strip()
- converter = get_converter( proptype, lambda x: x )
- propvalue = converter( propvstr )
+ converter = get_converter(proptype, lambda x: x)
+ propvalue = converter(propvstr)
# Should be safe since we're loading from
# the filesystem.
setattr(self, propname, propvalue)
@@ -129,11 +127,11 @@
'default_value':propvalue,
})
except:
- raise ValueError, ( 'Error processing line %s of %s:\n%s'
- % (lino,self._filepath,line) )
+ raise ValueError('Error processing line %s of %s:\n%s'
+ % (lino, self._filepath, line))
self._properties = tuple(map)
- if Globals.DevelopmentMode:
+ if getConfiguration().debug_mode:
# Provide an opportunity to update the properties.
def __of__(self, parent):
self = ImplicitAcquisitionWrapper(self, parent)
Property changes on: Products.CMFCore/trunk/Products/CMFCore/FSPropertiesObject.py
___________________________________________________________________
Deleted: svn:keywords
- Author Date Id Revision
Modified: Products.CMFCore/trunk/Products/CMFCore/FSZSQLMethod.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/FSZSQLMethod.py 2011-02-05 11:35:48 UTC (rev 120116)
+++ Products.CMFCore/trunk/Products/CMFCore/FSZSQLMethod.py 2011-02-05 12:43:36 UTC (rev 120117)
@@ -11,8 +11,6 @@
#
##############################################################################
""" Customizable ZSQL methods that come from the filesystem.
-
-$Id$
"""
import logging
@@ -20,8 +18,8 @@
from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import ImplicitAcquisitionWrapper
from App.class_init import InitializeClass
+from App.config import getConfiguration
from App.special_dtml import DTMLFile
-import Globals # for data
from Products.ZSQLMethods.SQL import SQL
from Products.CMFCore.DirectoryView import registerFileExtension
@@ -43,7 +41,7 @@
manage_options = ({'label':'Customize', 'action':'manage_customise'},
{'label':'Test', 'action':'manage_testForm',
- 'help':('ZSQLMethods','Z-SQL-Method_Test.stx')},
+ 'help':('ZSQLMethods', 'Z-SQL-Method_Test.stx')},
)
security = ClassSecurityInfo()
@@ -54,7 +52,7 @@
security.declarePrivate('manage_edit')
security.declarePrivate('manage_advanced')
security.declarePrivate('manage_advancedForm')
- manage=None
+ manage = None
security.declareProtected(ViewManagementScreens, 'manage_customise')
manage_customise = DTMLFile('custzsql', _dtmldir)
@@ -90,7 +88,7 @@
file.close()
# parse parameters
- parameters={}
+ parameters = {}
start = data.find('<dtml-comment>')
end = data.find('</dtml-comment>')
if start==-1 or end==-1 or start>end:
@@ -134,8 +132,7 @@
# do we need to do anything on reparse?
-
- if Globals.DevelopmentMode:
+ if getConfiguration().debug_mode:
# Provide an opportunity to update the properties.
def __of__(self, parent):
try:
Property changes on: Products.CMFCore/trunk/Products/CMFCore/FSZSQLMethod.py
___________________________________________________________________
Deleted: svn:keywords
- Author Date Id Revision
Modified: Products.CMFCore/trunk/Products/CMFCore/tests/base/testcase.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/tests/base/testcase.py 2011-02-05 11:35:48 UTC (rev 120116)
+++ Products.CMFCore/trunk/Products/CMFCore/tests/base/testcase.py 2011-02-05 12:43:36 UTC (rev 120117)
@@ -10,7 +10,9 @@
from os.path import basename
from os.path import dirname
from os.path import join
-from shutil import copytree, rmtree
+from shutil import copytree
+from shutil import rmtree
+from shutil import ignore_patterns
from stat import S_IREAD, S_IWRITE
from tempfile import mktemp
@@ -19,9 +21,9 @@
from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
-from dummy import DummyFolder
-from security import AnonymousUser
-from security import PermissiveSecurityPolicy
+from Products.CMFCore.tests.base.dummy import DummyFolder
+from Products.CMFCore.tests.base.security import AnonymousUser
+from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy
from Products.CMFCore.utils import getPackageLocation
@@ -64,7 +66,7 @@
_old_stderr = None
_our_stderr_stream = None
- def _trap_warning_output( self ):
+ def _trap_warning_output(self):
if self._old_stderr is not None:
return
@@ -74,7 +76,7 @@
self._old_stderr = sys.stderr
self._our_stderr_stream = sys.stderr = StringIO()
- def _free_warning_output( self ):
+ def _free_warning_output(self):
if self._old_stderr is None:
return
@@ -89,7 +91,7 @@
def setUp(self):
transaction.begin()
self.app = self.root = ZopeTestCase.app()
- self.REQUEST = self.app.REQUEST
+ self.REQUEST = self.app.REQUEST
self.RESPONSE = self.app.REQUEST.RESPONSE
def tearDown(self):
@@ -126,7 +128,7 @@
# Test was called by another test.
_prefix = abspath(dirname(__file__))
-_prefix = abspath(join(_prefix,'..'))
+_prefix = abspath(join(_prefix, '..'))
class FSDVTest(unittest.TestCase):
@@ -156,7 +158,8 @@
def setUp(self):
# store the skin path name
- self.skin_path_name = join(self.tempname,self._skinname,self._layername)
+ self.skin_path_name = join(self.tempname, self._skinname,
+ self._layername)
class WritableFSDVTest(FSDVTest):
@@ -171,20 +174,20 @@
dir_mtime = stat(self.skin_path_name)[8]
except: # XXX Why bare except?
dir_mtime = 0
- thePath = join(self.skin_path_name,filename)
+ thePath = join(self.skin_path_name, filename)
try:
mtime1 = stat(thePath)[8]
except: # XXX Why bare except?
mtime1 = 0
mtime2 = mtime1
- while mtime2==mtime1:
- f = open(thePath,'w')
+ while mtime2 == mtime1:
+ f = open(thePath, 'w')
f.write(stuff)
f.close()
mtime2 = stat(thePath)[8]
self._addedOrRemoved(dir_mtime)
- def _deleteFile(self,filename):
+ def _deleteFile(self, filename):
try:
dir_mtime = stat(self.skin_path_name)[8]
except: # XXX Why bare except?
@@ -210,7 +213,7 @@
raise RuntimeError(
"This platform (%s) does not update directory mod times "
"reliably." % sys.platform)
- time.sleep(0.1)
+ time.sleep(0.02)
fn = join(self.skin_path_name, '.touch')
f = open(fn, 'w')
f.write('Temporary file')
@@ -224,14 +227,13 @@
# create the temporary folder
mkdir(self.tempname)
# copy the source fake skin to the new location
- copytree(join(self._sourceprefix,
- self._skinname),
- join(self.tempname,
- self._skinname))
+ copytree(join(self._sourceprefix, self._skinname),
+ join(self.tempname, self._skinname),
+ ignore=ignore_patterns('.svn'))
# make sure we have a writable copy
for root, dirs, files in walk(self.tempname):
for name in files:
- chmod(join(root, name), S_IREAD+S_IWRITE)
+ chmod(join(root, name), S_IREAD + S_IWRITE)
FSDVTest.setUp(self)
def tearDown(self):
Property changes on: Products.CMFCore/trunk/Products/CMFCore/tests/base/testcase.py
___________________________________________________________________
Deleted: svn:keywords
- Author Date Id Revision
Modified: Products.CMFCore/trunk/Products/CMFCore/tests/test_FSSecurity.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/tests/test_FSSecurity.py 2011-02-05 11:35:48 UTC (rev 120116)
+++ Products.CMFCore/trunk/Products/CMFCore/tests/test_FSSecurity.py 2011-02-05 12:43:36 UTC (rev 120117)
@@ -16,9 +16,8 @@
import unittest
import Testing
-from time import sleep
-
from AccessControl.Permission import Permission
+from App.config import getConfiguration
from Products.CMFCore.tests.base.testcase import LogInterceptor
from Products.CMFCore.tests.base.testcase import RequestTest
@@ -101,8 +100,18 @@
# check baseline
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
+
class DebugModeTests( FSSecurityBase ):
+ def setUp(self):
+ FSSecurityBase.setUp(self)
+ self.saved_cfg_debug_mode = getConfiguration().debug_mode
+ getConfiguration().debug_mode = True
+
+ def tearDown(self):
+ getConfiguration().debug_mode = self.saved_cfg_debug_mode
+ FSSecurityBase.tearDown(self)
+
def test_addPRM( self ):
# Test adding of a .metadata
# baseline
@@ -127,11 +136,6 @@
def test_editPRM( self ):
# Test editing a .metadata
- # we need to wait a second here or the mtime will actually
- # have the same value as set in the last test.
- # Maybe someone brainier than me can figure out a way to make this
- # suck less :-(
- sleep(1)
# baseline
self._writeFile('test5.py.metadata',
@@ -152,11 +156,6 @@
self._deleteFile('test5.py.metadata')
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
- # we need to wait a second here or the mtime will actually
- # have the same value, no human makes two edits in less
- # than a second ;-)
- sleep(1)
-
# add back
self._writeFile('test5.py.metadata',
'[security]\nView = 0:Manager,Anonymous')
@@ -171,8 +170,7 @@
def test_suite():
- import Globals # for data
- tests = [unittest.makeSuite(FSSecurityTests)]
- if Globals.DevelopmentMode:
- tests.append(unittest.makeSuite(DebugModeTests))
- return unittest.TestSuite(tests)
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(FSSecurityTests))
+ suite.addTest(unittest.makeSuite(DebugModeTests))
+ return suite
More information about the checkins
mailing list