[Checkins] SVN: z3c.form/trunk/ - Bug: ``createId`` could not
handle arbitrary unicode input. Thanks to
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Nov 11 21:44:02 EST 2007
Log message for revision 81759:
- Bug: ``createId`` could not handle arbitrary unicode input. Thanks to
Andreas Reuleaux for reporting the bug and a patch for it. (Added
descriptive doctests for the function in the process.)
Changed:
U z3c.form/trunk/CHANGES.txt
U z3c.form/trunk/src/z3c/form/util.py
U z3c.form/trunk/src/z3c/form/util.txt
-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt 2007-11-11 15:35:13 UTC (rev 81758)
+++ z3c.form/trunk/CHANGES.txt 2007-11-12 02:44:00 UTC (rev 81759)
@@ -6,6 +6,10 @@
After Version 1.7.0
-------------------
+- Bug: ``createId`` could not handle arbitrary unicode input. Thanks to
+ Andreas Reuleaux for reporting the bug and a patch for it. (Added
+ descriptive doctests for the function in the process.)
+
- Bug: Interface invariants where not working when not all fields
needed for computing the invariant are in the submitted form.
Modified: z3c.form/trunk/src/z3c/form/util.py
===================================================================
--- z3c.form/trunk/src/z3c/form/util.py 2007-11-11 15:35:13 UTC (rev 81758)
+++ z3c.form/trunk/src/z3c/form/util.py 2007-11-12 02:44:00 UTC (rev 81759)
@@ -30,7 +30,7 @@
def createId(name):
if _identifier.match(name):
return str(name).lower()
- return name.encode('hex')
+ return name.encode('utf-8').encode('hex')
classTypes = type, types.ClassType
Modified: z3c.form/trunk/src/z3c/form/util.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/util.txt 2007-11-11 15:35:13 UTC (rev 81758)
+++ z3c.form/trunk/src/z3c/form/util.txt 2007-11-12 02:44:00 UTC (rev 81759)
@@ -2,12 +2,36 @@
Utility Functions and Classes
=============================
-This file documents the utility functiona and classes that are otherwise not
+This file documents the utility functions and classes that are otherwise not
tested.
>>> from z3c.form import util
+``creeateId(name)`` Function
+----------------------------
+
+This function converts an arbitrary unicode string into a valid Python
+identifier. If the name is a valid identifier, then it is just returned, but
+all upper case letters are lowered:
+
+ >>> util.createId(u'Change')
+ 'change'
+
+ >>> util.createId(u'Change_2')
+ 'change_2'
+
+If a name is not a valid identifier, a hex code of the string is created:
+
+ >>> util.createId(u'Change 3')
+ '4368616e67652033'
+
+The function can also handle non-ASCII characters:
+
+ >>> util.createId(u'Ãndern')
+ 'c383c2846e6465726e'
+
+
``getWidgetById(form, id)`` Function
------------------------------------
@@ -49,15 +73,15 @@
True
-extractFileName
----------------
+``extractFileName(form, id, cleanup=True, allowEmtpyPostFix=False)`` Function
+-----------------------------------------------------------------------------
Test the filename extraction method:
>>> class IDocument(zope.interface.Interface):
... data = zope.schema.Bytes(title=u'Data')
-Define a widgets stub and a upload widget stub class and setup them as a
+Define a widgets stub and a upload widget stub class and setup them as a
faked form:
>>> class FileUploadWidgetStub(object):
@@ -74,12 +98,12 @@
>>> class FileUploadFormStub(form.AddForm):
... def __init__(self):
... self.widgets = WidgetsStub()
- ...
+ ...
... def setFakeFileName(self, filename):
... self.widgets.data.filename = filename
-Now we can setup the stub form. Note this form is just a fake it's not a real
-implementation. We just provide a form like class which simulates the
+Now we can setup the stub form. Note this form is just a fake it's not a real
+implementation. We just provide a form like class which simulates the
FileUpload object in the a widget. See z3c.form.browser.file.txt for a real
file upload test uscase:
@@ -133,7 +157,7 @@
>>> util.extractFileName(uploadForm, 'form.widgets.data', cleanup=True)
u'foo-bar.v.0.1.txt'
-Test optional keyword arguments. But remember it's hard for Zope to guess the
+Test optional keyword arguments. But remember it's hard for Zope to guess the
content type for filenames without extensions:
>>> uploadForm.setFakeFileName(u'minimal')
@@ -184,8 +208,8 @@
ValueError: Missing filename extension.
-extractContentType
-------------------
+``extractContentType(form, id)`` Function
+-----------------------------------------
there s alos a method which is able to extract the content type for a given
file upload. We can use the stub form form the previous test.
More information about the Checkins
mailing list