[Checkins] SVN: z3c.form/trunk/ - Feature: Added support in the file upload widget's testing flavor to specify

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Sep 29 10:18:46 EDT 2008


Log message for revision 91596:
  - Feature: Added support in the file upload widget's testing flavor to specify
    'base64'-encoded strings in the hidden text area, so that binary data can be
    uploaded as well.
  

Changed:
  U   z3c.form/trunk/CHANGES.txt
  U   z3c.form/trunk/src/z3c/form/testing.py

-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt	2008-09-29 13:42:04 UTC (rev 91595)
+++ z3c.form/trunk/CHANGES.txt	2008-09-29 14:18:45 UTC (rev 91596)
@@ -5,6 +5,10 @@
 Version 2.0.0 (2008-??-??)
 --------------------------
 
+- Feature: Added support in the file upload widget's testing flavor to specify
+  'base64'-encoded strings in the hidden text area, so that binary data can be
+  uploaded as well.
+
 - Feature: Allow overriding the "required" widget attribute using IValue adapter
   just like it's done for "label" and "name" attributes.
 

Modified: z3c.form/trunk/src/z3c/form/testing.py
===================================================================
--- z3c.form/trunk/src/z3c/form/testing.py	2008-09-29 13:42:04 UTC (rev 91595)
+++ z3c.form/trunk/src/z3c/form/testing.py	2008-09-29 14:18:45 UTC (rev 91596)
@@ -16,9 +16,10 @@
 $Id$
 """
 __docformat__ = 'restructuredtext'
+import binascii
+import doctest
 import os
 import re
-import doctest
 import xml.parsers.expat
 
 import zope.component
@@ -54,6 +55,10 @@
     def toFieldValue(self, value):
         if value is None or value == '':
             value = self.widget.request.get(self.widget.name+'.testing', '')
+            try:
+                value = value.decode('base64')
+            except binascii.error:
+                pass
         return super(TestingFileUploadDataConverter, self).toFieldValue(value)
 
 class OutputChecker(lxml.doctestcompare.LHTMLOutputChecker):
@@ -61,9 +66,9 @@
     HTML markup than the checker from the ``lxml.doctestcompare``
     module. It also uses the text comparison function from the
     built-in ``doctest`` module to allow the use of ellipsis."""
-    
+
     _repr_re = re.compile(r'^<([A-Z]|[^>]+ (at|object) |[a-z]+ \'[A-Za-z0-9_.]+\'>)')
-    
+
     def _looks_like_markup(self, s):
         s = s.replace('<BLANKLINE>', '\n').strip()
         return (s.startswith('<')
@@ -75,7 +80,7 @@
         checker = doctest.OutputChecker()
         return checker.check_output(
             want, got, doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
-        
+
 class TestRequest(TestRequest):
     zope.interface.implements(interfaces.IFormLayer)
 
@@ -118,7 +123,7 @@
         root = lxml.etree.fromstring(string)
     except lxml.etree.XMLSyntaxError:
         root = lxml.html.fromstring(string)
-        
+
     output = ""
     for node in root.xpath(
         xpath, namespaces={'xmlns': 'http://www.w3.org/1999/xhtml'}):
@@ -128,7 +133,7 @@
 
     if not output:
         raise ValueError("No elements matched by %s." % repr(xpath))
-        
+
     # let's get rid of blank lines
     output = output.replace('\n\n', '\n')
 
@@ -147,7 +152,7 @@
 def setUpZPT(suite):
     z3c.pt.compat.config.disable()
     setUp(suite)
-    
+
 def setUpZ3CPT(suite):
     z3c.pt.compat.config.enable()
     setUp(suite)



More information about the Checkins mailing list