[Checkins] SVN: z3c.form/trunk/src/z3c/form/ modified handling of base64

Roy Mathew roymath at yahoo.com
Mon Sep 29 12:53:31 EDT 2008


Log message for revision 91612:
  modified handling of base64

Changed:
  U   z3c.form/trunk/src/z3c/form/browser/file_testing_input.pt
  U   z3c.form/trunk/src/z3c/form/testing.py

-=-
Modified: z3c.form/trunk/src/z3c/form/browser/file_testing_input.pt
===================================================================
--- z3c.form/trunk/src/z3c/form/browser/file_testing_input.pt	2008-09-29 16:53:27 UTC (rev 91611)
+++ z3c.form/trunk/src/z3c/form/browser/file_testing_input.pt	2008-09-29 16:53:31 UTC (rev 91612)
@@ -30,6 +30,9 @@
                        onselect view/onselect;
                        size view/size;
                        maxlength view/maxlength" />
+
+<input type="hidden" name=""
+       tal:attributes="name string:${view/name}.encoding; value string:plain" />
 <textarea name="" style="display: none;"
        tal:attributes="name string:${view/name}.testing"><!-- nothing here --></textarea>
 </html>

Modified: z3c.form/trunk/src/z3c/form/testing.py
===================================================================
--- z3c.form/trunk/src/z3c/form/testing.py	2008-09-29 16:53:27 UTC (rev 91611)
+++ z3c.form/trunk/src/z3c/form/testing.py	2008-09-29 16:53:31 UTC (rev 91612)
@@ -55,10 +55,13 @@
     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
+            encoding = self.widget.request.get(self.widget.name+'.encoding', 'plain')
+
+            # allow for the case where the file contents are base64 encoded.
+            if encoding!='plain':
+                value = value.decode(encoding)
+            self.widget.request.form[self.widget.name] = value
+
         return super(TestingFileUploadDataConverter, self).toFieldValue(value)
 
 class OutputChecker(lxml.doctestcompare.LHTMLOutputChecker):



More information about the Checkins mailing list