Zope-2.7 compatibility issue

Clemens Robbenhaar <robbenhaar-WaVJUzJ3u31Wk0Htik3J/[email protected]> Sat, 21 Aug 2004 21:42:10 +0200
Newsgroups gmane.comp.web.zope.formulator.devel
Message-ID <[email protected]>
Hi,

 there seems to be a compatibility issue with Zope 2.7 / python2.3.4.

 No StringFiled and TextAreaField will validate successfully in Zope2.7 is
the user enters a "<" and whitespace preservation has been swiched
off. 
 Instead one gets an ugly error on validation, with a traceback
looking like:

 [snip]
   File "INSTANCE_HOME/Products/Formulator/Field.py", line 317, in validate
    return self._validate_helper(
  File "INSTANCE_HOME/Products/Formulator/Field.py", line 306, in _validate_helper
    value = self.validator.validate(self, key, REQUEST)
  File "INSTANCE_HOME/_test/Products/Formulator/Validator.py", line 136, in validate
    value = StringBaseValidator.validate(self, field, key, REQUEST)
  File "INSTANCE_HOME/Products/Formulator/Validator.py", line 97, in validate
    value = string.strip(value)
  File "PYTHON_HOME/lib/python2.3/string.py", line 86, in strip
    return s.strip(chars)
  File "SOFTWARE_HOME/lib/python/ZPublisher/TaintedString.py", line 129, in <lambda>
    return lambda s, f=func: s.__class__(getattr(s._value, f)())
TypeError: getattr(): attribute name must be string


 The reason is a simple bug in the "TaintedString" implementation; it
assumes "strip" to accept no parameters, while calling instances of this
class via the python module "string" as "string.strip(value)" 
passes an additional parameter "chars", as the implementation of
string.strip simply dispatches to "value.strip(chars)".
 This leads to the error above.

 The fix for this is quite simple, but as Zope2.7.2 is already released
and may have a wider user audinence, we maybe should consider trying to
work around this in Formulator.
 I already filed a zope collector issue for this; see
 http://zope.org/Collectors/Zope/1477

 It seems the workaround is indeed simple; instead of using 
"string.spilt(value)" one could use "value.split()" and both work around
the bug and have more elegant code.
 The downhill of this change is that the current usage of string.split()
is quite all over the place and would require several changes;
overviewing one of them would keeping the bug haunting Formulator.

 Is there some reason why the string module is used instead of the
string object methods? Any other opinions on the subject?

Cheers,
Clemens