[Zope-CMF] Re: SVN: CMF/trunk/GenericSetup/ Improved unicode handling by adding 'getEncoding' to all contexts, export as well as import.

Florent Guillaume fg at nuxeo.com
Wed Sep 28 11:37:50 EDT 2005


If I understand, the goal is to specify the file encoding for the export. Do 
we really need this? Isn't UTF-8 good enough in all cases?

Florent

Tres Seaver wrote:
> Log message for revision 38662:
>   Improved unicode handling by adding 'getEncoding' to all contexts, export as well as import.
> 
> Changed:
>   U   CMF/trunk/GenericSetup/context.py
>   U   CMF/trunk/GenericSetup/interfaces.py
>   U   CMF/trunk/GenericSetup/tests/test_context.py
> 
> -=-
> Modified: CMF/trunk/GenericSetup/context.py
> ===================================================================
> --- CMF/trunk/GenericSetup/context.py	2005-09-28 10:35:29 UTC (rev 38661)
> +++ CMF/trunk/GenericSetup/context.py	2005-09-28 11:16:22 UTC (rev 38662)
> @@ -46,11 +46,12 @@
>  
>      security = ClassSecurityInfo()
>  
> -    def __init__( self, tool ):
> +    def __init__( self, tool, encoding ):
>  
[...]
> +    def test_writeDataFile_simple_plain_text_unicode( self ):
> +
> +        from string import digits
> +        from OFS.Image import File
> +        FILENAME = 'simple.txt'
> +        CONTENT_TYPE = 'text/plain'
> +        CONTENT = u'Unicode, with non-ASCII: %s.' % unichr(150)
> +
> +        site = DummySite( 'site' ).__of__( self.root )
> +        site.setup_tool = DummyTool( 'setup_tool' )
> +        tool = site.setup_tool
> +        ctx = self._makeOne( tool, 'simple', 'latin_1' )
> +
> +        ctx.writeDataFile( FILENAME, CONTENT, CONTENT_TYPE )
> +
> +        snapshot = tool.snapshots._getOb( 'simple' )
> +
> +        self.assertEqual( len( snapshot.objectIds() ), 1 )
> +        self.failUnless( FILENAME in snapshot.objectIds() )
> +
> +        fileobj = snapshot._getOb( FILENAME )
> +
> +        self.assertEqual( fileobj.getId(), FILENAME )
> +        self.assertEqual( fileobj.meta_type, File.meta_type )
> +        self.assertEqual( fileobj.getContentType(), CONTENT_TYPE )
> +        saved = fileobj.manage_FTPget().decode('latin_1')
> +        self.assertEqual( saved, CONTENT )
> +

-- 
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com


More information about the Zope-CMF mailing list