[Zope-CMF] Re: PATCH: Get CMFCore.exportimport.content working with Archetypes

Tres Seaver tseaver at palladion.com
Thu Nov 3 18:08:02 EST 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Brent Hendricks wrote:
> The DAVAwareFileAdapter currently passes the file's string content
> both as BODY and BODYFILE in the FauxDAVRequest.  This causes problems
> in Archetypes' BaseContent.PUT() because it expects BODYFILE to be an
> actual file object.
> 
> This patch against CMFCore/trunk uses cStringIO to make a file object
> for BODYFILE.
> 
> Could someone with permission check this (or something like it) in?
> 
> Thanks,
> Brent
> 
> 
> ------------------------------------------------------------------------
> 
> Index: content.py
> ===================================================================
> --- content.py	(revision 39876)
> +++ content.py	(working copy)
> @@ -319,6 +319,8 @@
>              import_context.note('SGAIFA',
>                                  'no .ini file for %s/%s' % (subdir, cid))
>          else:
> -            request = FauxDAVRequest(BODY=data, BODYFILE=data)
> +            import cStringIO
> +            f = cStringIO.StringIO(data)
> +            request = FauxDAVRequest(BODY=data, BODYFILE=f)
>              response = FauxDAVResponse()
>              self.context.PUT(request, response)
> 
> 
> ------------------------------------------------------------------------

I can check in something like that, yes.  A couple of notss:

 - cStringIO is not Unicode-safe;  I will use the already-imported
   StringIO instead.

 - Archetypes content will likely use the "Marshal" stuff Sidnei and
   Kapil have been working on as their default FS export / import
   adapters, rather than DAVAwareFileAdapter.


I'm checking it in like so (including modifying the tests to ensure that
BODYFILE has a 'read' method):

$ svn diff
Index: CMFCore/exportimport/content.py
===================================================================
- --- CMFCore/exportimport/content.py     (revision 39877)
+++ CMFCore/exportimport/content.py     (working copy)
@@ -319,6 +319,6 @@
             import_context.note('SGAIFA',
                                 'no .ini file for %s/%s' % (subdir, cid))
         else:
- -            request = FauxDAVRequest(BODY=data, BODYFILE=data)
+            request = FauxDAVRequest(BODY=data, BODYFILE=StringIO(data))
             response = FauxDAVResponse()
             self.context.PUT(request, response)
Index: CMFCore/exportimport/tests/test_content.py
===================================================================
- --- CMFCore/exportimport/tests/test_content.py  (revision 39877)
+++ CMFCore/exportimport/tests/test_content.py  (working copy)
@@ -787,6 +787,8 @@

         def PUT(self, REQUEST, RESPONSE):
             self._was_put = REQUEST.get('BODY', '')
+            stream = REQUEST.get('BODYFILE', None)
+            self._was_put_as_read = stream.read()

     aware = _TestDAVAware()
     aware._setId(id)





Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDaphR+gerLs4ltQ4RAgMCAKDT5yXNv+Fp+8GGiUei2Uiw/eynGgCfQgAi
yfYGiDuB34oO3mAxYIpEHmw=
=e6e7
-----END PGP SIGNATURE-----



More information about the Zope-CMF mailing list