[CMF-checkins] CVS: CMF/CMFSetup - actions.py:1.4 context.py:1.7
interfaces.py:1.8 registry.py:1.9 utils.py:1.5
Tres Seaver
tseaver at zope.com
Tue May 25 08:49:25 EDT 2004
Update of /cvs-repository/CMF/CMFSetup
In directory cvs.zope.org:/tmp/cvs-serv4982
Modified Files:
actions.py context.py interfaces.py registry.py utils.py
Log Message:
- Unicode tidying:
o Move knowledge of the encoding being used out of the utility code,
and into the import context.
o Use HandlerBase everywhere in which it might be necessary to encode
unicode.
o Note that all 'parseXML' methods (and isomorphs) now default the
encoding to None; this may be painful for some kinds of configuration.
=== CMF/CMFSetup/actions.py 1.3 => 1.4 ===
--- CMF/CMFSetup/actions.py:1.3 Tue May 25 08:22:07 2004
+++ CMF/CMFSetup/actions.py Tue May 25 08:48:53 2004
@@ -24,7 +24,7 @@
class _ActionProviderParser( HandlerBase ):
- def __init__( self, site, encoding='latin-1' ):
+ def __init__( self, site, encoding ):
self._site = site
self._encoding = encoding
@@ -156,7 +156,7 @@
return self._providers()
security.declareProtected( ManagePortal, 'parseXML' )
- def parseXML( self, text ):
+ def parseXML( self, text, encoding=None ):
""" Pseudo API.
"""
@@ -165,7 +165,7 @@
if reader is not None:
text = reader()
- parseString( text, _ActionProviderParser( self._site ) )
+ parseString( text, _ActionProviderParser( self._site, encoding ) )
InitializeClass( ActionProvidersConfigurator )
@@ -204,6 +204,7 @@
"""
site = context.getSite()
+ encoding = context.getEncoding()
if context.shouldPurge():
@@ -216,7 +217,7 @@
if text is not None:
apc = ActionProvidersConfigurator( site ).__of__( site )
- apc.parseXML( text )
+ apc.parseXML( text, encoding )
return 'Action providers imported.'
=== CMF/CMFSetup/context.py 1.6 => 1.7 ===
--- CMF/CMFSetup/context.py:1.6 Mon May 24 15:13:09 2004
+++ CMF/CMFSetup/context.py Tue May 25 08:48:53 2004
@@ -32,11 +32,17 @@
security = ClassSecurityInfo()
- def __init__( self, tool, profile_path, should_purge=False ):
+ def __init__( self
+ , tool
+ , profile_path
+ , should_purge=False
+ , encoding=None
+ ):
self._site = aq_parent( aq_inner( tool ) )
self._profile_path = profile_path
self._should_purge = bool( should_purge )
+ self._encoding = encoding
security.declareProtected( ManagePortal, 'getSite' )
def getSite( self ):
@@ -44,6 +50,14 @@
""" See ISetupContext.
"""
return self._site
+
+ def getEncoding( self ):
+
+ """ Return the encoding used in data files.
+
+ o Return None if the data should not be encoded.
+ """
+ return self._encoding
security.declareProtected( ManagePortal, 'readDataFile' )
def readDataFile( self, filename, subdir=None ):
=== CMF/CMFSetup/interfaces.py 1.7 => 1.8 ===
--- CMF/CMFSetup/interfaces.py:1.7 Sun May 23 21:52:43 2004
+++ CMF/CMFSetup/interfaces.py Tue May 25 08:48:53 2004
@@ -21,6 +21,13 @@
class IImportContext( ISetupContext ):
+ def getEncoding():
+
+ """ Return the encoding used in data files.
+
+ o Return None if the data should not be encoded.
+ """
+
def readDataFile( filename, subdir=None ):
""" Search the current configuration for the requested file.
=== CMF/CMFSetup/registry.py 1.8 => 1.9 ===
--- CMF/CMFSetup/registry.py:1.8 Sun May 23 14:57:38 2004
+++ CMF/CMFSetup/registry.py Tue May 25 08:48:53 2004
@@ -14,6 +14,7 @@
from interfaces import IImportStepRegistry
from interfaces import IExportStepRegistry
from permissions import ManagePortal
+from utils import HandlerBase
from utils import _xmldir
from utils import _getDottedName
from utils import _resolveDottedName
@@ -190,7 +191,7 @@
self._registered[ id ] = info
security.declarePrivate( 'importFromXML' )
- def importFromXML( self, text ):
+ def importFromXML( self, text, encoding=None ):
""" Parse 'text' into a clean registry.
"""
@@ -201,7 +202,7 @@
if reader is not None:
text = reader()
- parseString( text, _ImportStepRegistryParser( self ) )
+ parseString( text, _ImportStepRegistryParser( self, None ) )
#
# Helper methods
@@ -237,13 +238,13 @@
InitializeClass( ImportStepRegistry )
-class _ImportStepRegistryParser( ContentHandler ):
+class _ImportStepRegistryParser( HandlerBase ):
security = ClassSecurityInfo()
security.declareObjectPrivate()
security.setDefaultAccess( 'deny' )
- def __init__( self, registry, encoding='latin-1' ):
+ def __init__( self, registry, encoding ):
self._registry = registry
self._encoding = encoding
@@ -264,15 +265,15 @@
if self._pending is not None:
raise ValueError, 'Cannot nest setup-step elements'
- self._pending = dict( [ ( k, v.encode( self._encoding ) )
- for k, v in attrs.items() ] )
+ self._pending = dict( [ ( k, self._extract( attrs, k ) )
+ for k in attrs.keys() ] )
elif name == 'dependency':
if not self._pending:
raise ValueError, 'Dependency outside of step'
- depended = attrs['step'].encode('latin-1')
+ depended = self._extract( attrs, 'step' )
self._pending.setdefault( 'dependencies', [] ).append( depended )
else:
@@ -281,7 +282,7 @@
def characters( self, content ):
if self._pending is not None:
- content = content.encode( self._encoding )
+ content = self._encode( content )
self._pending.setdefault( 'description', [] ).append( content )
def endElement(self, name):
@@ -436,7 +437,7 @@
self._registered[ id ] = info
security.declarePrivate( 'importFromXML' )
- def importFromXML( self, text ):
+ def importFromXML( self, text, encoding=None ):
""" Parse 'text' into a clean registry.
"""
@@ -447,7 +448,7 @@
if reader is not None:
text = reader()
- parseString( text, _ExportStepRegistryParser( self ) )
+ parseString( text, _ExportStepRegistryParser( self, encoding ) )
#
# Helper methods
@@ -462,13 +463,13 @@
InitializeClass( ExportStepRegistry )
-class _ExportStepRegistryParser( ContentHandler ):
+class _ExportStepRegistryParser( HandlerBase ):
security = ClassSecurityInfo()
security.declareObjectPrivate()
security.setDefaultAccess( 'deny' )
- def __init__( self, registry, encoding='latin-1' ):
+ def __init__( self, registry, encoding ):
self._registry = registry
self._encoding = encoding
@@ -489,8 +490,8 @@
if self._pending is not None:
raise ValueError, 'Cannot nest export-step elements'
- self._pending = dict( [ ( k, v.encode( self._encoding ) )
- for k, v in attrs.items() ] )
+ self._pending = dict( [ ( k, self._extract( attrs, k ) )
+ for k in attrs.keys() ] )
else:
raise ValueError, 'Unknown element %s' % name
@@ -498,7 +499,7 @@
def characters( self, content ):
if self._pending is not None:
- content = content.encode( self._encoding )
+ content = self._encode( content )
self._pending.setdefault( 'description', [] ).append( content )
def endElement(self, name):
=== CMF/CMFSetup/utils.py 1.4 => 1.5 ===
--- CMF/CMFSetup/utils.py:1.4 Tue May 25 00:12:33 2004
+++ CMF/CMFSetup/utils.py Tue May 25 08:48:53 2004
@@ -77,7 +77,16 @@
class HandlerBase( ContentHandler ):
+ _encoding = None
+
def _extract( self, attrs, key ):
- return attrs[ key ].encode( self._encoding )
+ return self._encode( attrs[ key ] )
+
+ def _encode( self, content ):
+
+ if self._encoding is None:
+ return content
+
+ return content.encode( self._encoding )
More information about the CMF-checkins
mailing list