[CMF-checkins] SVN: CMF/trunk/C Replaced use of deprecated 'zLOG'
module with standard Python 'logging' module.
Tres Seaver
tseaver at palladion.com
Mon Jan 16 13:56:23 EST 2006
Log message for revision 41334:
Replaced use of deprecated 'zLOG' module with standard Python 'logging' module.
Also repaire some lines > 80 characters.
Changed:
U CMF/trunk/CHANGES.txt
U CMF/trunk/CMFCore/CMFCatalogAware.py
U CMF/trunk/CMFCore/DirectoryView.py
U CMF/trunk/CMFCore/FSFile.py
U CMF/trunk/CMFCore/FSMetadata.py
U CMF/trunk/CMFCore/FSZSQLMethod.py
U CMF/trunk/CMFCore/MembershipTool.py
U CMF/trunk/CMFCore/Skinnable.py
U CMF/trunk/CMFCore/TypesTool.py
U CMF/trunk/CMFCore/tests/base/testcase.py
U CMF/trunk/CMFCore/tests/test_FSSecurity.py
U CMF/trunk/CMFUid/UniqueIdHandlerTool.py
-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CHANGES.txt 2006-01-16 18:56:22 UTC (rev 41334)
@@ -167,6 +167,9 @@
Others
+ - Replaced use of deprecated 'zLOG' module with standard Python
+ 'logging' module.
+
- CMFCore utils: Made _checkPermission depend on Zope's checkPermission.
There is no longer a need to modify the checkPermission behavior in CMF.
Modified: CMF/trunk/CMFCore/CMFCatalogAware.py
===================================================================
--- CMF/trunk/CMFCore/CMFCatalogAware.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/CMFCatalogAware.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -15,7 +15,8 @@
$Id$
"""
-from zLOG import LOG, PROBLEM
+import logging
+
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from ExtensionClass import Base
@@ -117,7 +118,7 @@
# BBB: Ignore old references to deleted objects.
# Can happen only when using
# catalog-getObject-raises off in Zope 2.8
- LOG('reindexObjectSecurity', PROBLEM,
+ logging.warn('reindexObjectSecurity',
"Cannot get %s from catalog" % brain_path)
continue
# Recatalog with the same catalog uid.
Modified: CMF/trunk/CMFCore/DirectoryView.py
===================================================================
--- CMF/trunk/CMFCore/DirectoryView.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/DirectoryView.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -15,9 +15,9 @@
$Id$
"""
+import logging
import re
from os import path, listdir, stat
-from sys import exc_info
from sys import platform
from AccessControl import ClassSecurityInfo
@@ -30,7 +30,6 @@
from Globals import Persistent
from OFS.Folder import Folder
from OFS.ObjectManager import bad_id
-from zLOG import LOG, ERROR
from zope.interface import implements
from FSMetadata import FSMetadata
@@ -141,10 +140,8 @@
path.walk(self._filepath, self._walker, filelist)
filelist.sort()
except:
- LOG('DirectoryView',
- ERROR,
- 'Error checking for directory modification',
- error=exc_info())
+ logging.exception('DirectoryView',
+ 'Error checking for directory modification')
if mtime != self._v_last_read or filelist != self._v_last_filelist:
self._v_last_read = mtime
@@ -166,10 +163,8 @@
self.data, self.objects = self.prepareContents(registry,
register_subdirs=changed)
except:
- LOG('DirectoryView',
- ERROR,
- 'Error during prepareContents:',
- error=exc_info())
+ logging.exception('DirectoryView',
+ 'Error during prepareContents:')
self.data = {}
self.objects = ()
@@ -245,15 +240,15 @@
ob = t(name, entry_minimal_fp, fullname=entry,
properties=metadata.getProperties())
except:
+ import sys
import traceback
- typ, val, tb = exc_info()
+ typ, val, tb = sys.exc_info()
try:
+ logging.exception( 'DirectoryView')
+
exc_lines = traceback.format_exception( typ,
val,
tb )
- LOG( 'DirectoryView', ERROR,
- '\n'.join(exc_lines) )
-
ob = BadFile( name,
entry_minimal_fp,
exc_str='\r\n'.join(exc_lines),
@@ -269,20 +264,16 @@
try:
ob.manage_permission(name,roles,acquire)
except ValueError:
- LOG('DirectoryView',
- ERROR,
- 'Error setting permissions',
- error=exc_info())
+ logging.exception('DirectoryView',
+ 'Error setting permissions')
# only DTML Methods and Python Scripts can have proxy roles
if hasattr(ob, '_proxy_roles'):
try:
ob._proxy_roles = tuple(metadata.getProxyRoles())
except:
- LOG('DirectoryView',
- ERROR,
- 'Error setting proxy role',
- error=exc_info())
+ logging.exception('DirectoryView',
+ 'Error setting proxy role')
ob_id = ob.getId()
data[ob_id] = ob
Modified: CMF/trunk/CMFCore/FSFile.py
===================================================================
--- CMF/trunk/CMFCore/FSFile.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/FSFile.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -20,7 +20,7 @@
from AccessControl import ClassSecurityInfo
from DateTime import DateTime
from OFS.Cache import Cacheable
-from OFS.content_types import guess_content_type
+from zope.app.content_types import guess_content_type
from OFS.Image import File
from webdav.common import rfc1123_date
Modified: CMF/trunk/CMFCore/FSMetadata.py
===================================================================
--- CMF/trunk/CMFCore/FSMetadata.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/FSMetadata.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -15,8 +15,6 @@
$Id$
"""
-from zLOG import LOG, ERROR
-from sys import exc_info
from os.path import exists
from ConfigParser import ConfigParser
from warnings import warn
@@ -90,10 +88,8 @@
self._security = self._getSectionDict(cfg, 'security',
self._securityParser)
except:
- LOG('FSMetadata',
- ERROR,
- 'Error parsing .metadata file',
- error=exc_info())
+ logging.exception('FSMetadata',
+ 'Error parsing .metadata file')
# to add in a new value such as proxy roles,
# just add in the section, call it using getSectionDict
@@ -169,10 +165,8 @@
if len(kv) == 2:
props[kv[0].strip()] = kv[1].strip()
else:
- LOG('FSMetadata',
- ERROR,
- 'Error parsing .properties file',
- error=exc_info())
+ logging.exception('FSMetadata',
+ 'Error parsing .properties file')
return props
@@ -207,10 +201,7 @@
if role:
roles.append(role)
except:
- LOG('DirectoryView',
- ERROR,
- 'Error reading permission from .security file',
- error=exc_info())
- # warning use of exc_info is deprecated
+ logging.exception('DirectoryView',
+ 'Error reading permission from .security file')
prm[permission]=(acquire,roles)
return prm
Modified: CMF/trunk/CMFCore/FSZSQLMethod.py
===================================================================
--- CMF/trunk/CMFCore/FSZSQLMethod.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/FSZSQLMethod.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -14,12 +14,12 @@
$Id$
"""
+import logging
import Globals
from AccessControl import ClassSecurityInfo
from Acquisition import ImplicitAcquisitionWrapper
from Products.ZSQLMethods.SQL import SQL
-from zLOG import LOG, ERROR
from DirectoryView import registerFileExtension
from DirectoryView import registerMetaType
@@ -50,7 +50,10 @@
security.declareObjectProtected(View)
# Make mutators private
- security.declarePrivate('manage_main','manage_edit','manage_advanced','manage_advancedForm')
+ security.declarePrivate('manage_main')
+ security.declarePrivate('manage_edit')
+ security.declarePrivate('manage_advanced')
+ security.declarePrivate('manage_advancedForm')
manage=None
security.declareProtected(ViewManagementScreens, 'manage_customise')
@@ -103,7 +106,8 @@
connection_id = ( parameters.get('connection id', '') or
parameters['connection_id'] )
except KeyError,e:
- raise ValueError,"The '%s' parameter is required but was not supplied" % e
+ raise ValueError("The '%s' parameter is required "
+ "but was not supplied" % e)
# Optional parameters
title = parameters.get('title','')
@@ -137,11 +141,8 @@
self._updateFromFS()
return self
except:
- import sys
- LOG('FS Z SQL Method',
- ERROR,
- 'Error during __of__',
- error=sys.exc_info())
+ logging.exception('FS Z SQL Method',
+ 'Error during __of__')
raise
Globals.InitializeClass(FSZSQLMethod)
Modified: CMF/trunk/CMFCore/MembershipTool.py
===================================================================
--- CMF/trunk/CMFCore/MembershipTool.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/MembershipTool.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -14,6 +14,7 @@
$Id$
"""
+import logging
from AccessControl import ClassSecurityInfo
from AccessControl.User import nobody
@@ -144,13 +145,8 @@
except ConflictError:
raise
except:
- from zLOG import LOG, ERROR
- import sys
- LOG('CMFCore.MembershipTool',
- ERROR,
- 'Error during wrapUser',
- error=sys.exc_info(),
- )
+ logging.exception('CMFCore.MembershipTool',
+ 'Error during wrapUser')
return u
security.declareProtected(ManagePortal, 'getPortalRoles')
Modified: CMF/trunk/CMFCore/Skinnable.py
===================================================================
--- CMF/trunk/CMFCore/Skinnable.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/Skinnable.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -18,7 +18,9 @@
$Id$
"""
+import logging
from thread import get_ident
+
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from Acquisition import ImplicitAcquisitionWrapper
@@ -189,10 +191,7 @@
except:
# This shouldn't happen, even if the requested skin
# does not exist.
- import sys
- from zLOG import LOG, ERROR
- LOG('CMFCore', ERROR, 'Unable to setupCurrentSkin()',
- error=sys.exc_info())
+ logging.exception('CMFCore', 'Unable to setupCurrentSkin()')
return w_self
def _checkId(self, id, allow_dup=0):
Modified: CMF/trunk/CMFCore/TypesTool.py
===================================================================
--- CMF/trunk/CMFCore/TypesTool.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/TypesTool.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -15,7 +15,7 @@
$Id$
"""
-from sys import exc_info
+import logging
from warnings import warn
import Products
@@ -28,7 +28,6 @@
from OFS.Folder import Folder
from OFS.ObjectManager import IFAwareObjectManager
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
-from zLOG import LOG, ERROR
from zope.interface import implements
try:
from zope.i18nmessageid import MessageFactory
@@ -391,8 +390,8 @@
try:
p = dispatcher[self.product]
except AttributeError:
- LOG('Types Tool', ERROR, '_queryFactoryMethod raised an exception',
- error=exc_info())
+ logging.exception('Types Tool',
+ '_queryFactoryMethod raised an exception')
return default
m = getattr(p, self.factory, None)
Modified: CMF/trunk/CMFCore/tests/base/testcase.py
===================================================================
--- CMF/trunk/CMFCore/tests/base/testcase.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/tests/base/testcase.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -2,6 +2,7 @@
import Zope2
Zope2.startup()
+import logging
import sys
import time
from os import chmod, curdir, mkdir, remove, stat, walk
@@ -14,7 +15,6 @@
from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
from Testing.makerequest import makerequest
-import zLOG
import transaction
from dummy import DummyFolder
@@ -54,31 +54,36 @@
class LogInterceptor:
- _old_log_write = None
logged = None
+ installed = False
+ level = 0
- def _catch_log_errors( self, ignored_level=zLOG.PROBLEM ):
+ def _catch_log_errors( self, ignored_level=logging.WARNING ):
- if self._old_log_write is not None:
- return
+ if self.installed:
+ raise ValueError, 'Already installed filter!'
- def log_write(subsystem, severity, summary, detail, error):
- if severity > ignored_level:
- assert 0, "%s(%s): %s" % (subsystem, severity, summary)
- if self.logged is None:
- self.logged = []
- self.logged.append( ( subsystem, severity, summary, detail ) )
+ root_logger = logging.getLogger('')
+ self.installed = True
+ self.level = ignored_level
+ root_logger.addFilter(self)
- self._old_log_write = zLOG.log_write
- zLOG.log_write = log_write
+ def filter(self, record):
+ if record.levelno > self.level:
+ return True
+ if self.logged is None:
+ self.logged = []
+ self.logged.append(record)
+ return False
def _ignore_log_errors( self ):
- if self._old_log_write is None:
+ if not self.installed:
return
- zLOG.log_write = self._old_log_write
- del self._old_log_write
+ root_logger = logging.getLogger('')
+ root_logger.removeFilter(self)
+ self.installed = False
class WarningInterceptor:
Modified: CMF/trunk/CMFCore/tests/test_FSSecurity.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_FSSecurity.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFCore/tests/test_FSSecurity.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -82,8 +82,8 @@
self._checkSettings(self.ob.fake_skin.test4,'Access contents information',0,[])
def test_invalidPermissionNames( self ):
- import zLOG
- self._catch_log_errors(zLOG.ERROR)
+ import logging
+ self._catch_log_errors(logging.ERROR)
# Test for an invalid permission name
# baseline
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
Modified: CMF/trunk/CMFUid/UniqueIdHandlerTool.py
===================================================================
--- CMF/trunk/CMFUid/UniqueIdHandlerTool.py 2006-01-16 18:32:03 UTC (rev 41333)
+++ CMF/trunk/CMFUid/UniqueIdHandlerTool.py 2006-01-16 18:56:22 UTC (rev 41334)
@@ -17,10 +17,10 @@
$Id$
"""
+import logging
import os
import Missing
-import zLOG
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from Globals import InitializeClass
@@ -191,7 +191,7 @@
# print a message to the log if more than one object has
# the same uid (uups!)
if len_result > 1:
- zLOG.LOG("CMUid ASSERT:", zLOG.INFO,
+ logging.info("CMUid ASSERT:",
"Uups, %s objects have '%s' as uid!!!" % \
(len_result, uid))
More information about the CMF-checkins
mailing list