Test suite changes for jython, before:
Ran 72 tests in 1.951s
FAILED (failures=19, errors=20)
Ran 72 tests in 3.569s
FAILED (failures=16, errors=18)
This is not as clean as a Python 2.4 run but it is an improvement.
Original attempt at a fix simply converted tokens into unicode, e.g.:
def handle_url(self, t):
- if not protocol_pattern.match(t):
+ if not protocol_pattern.match(unicode(t)):
This fixed plain URLs, for example tests like test_simple_url_1(), but not youtube links, for example tests like test_youtube_embed_1()
Comment from Matt on this original attempt:
matt chisholm Date 2012-03-14
I think I understand this. The variable t is an instance of class Token, which derives from unicode. The re.match method in Jython or Python 2.2 probably fails when passed something that is not an instance of str or unicode, and this probably works in later versions of Python because the built-in types unicode and str didn't both inherit from basestring until 2.3. Casting the Token instance to unicode allows re.match to operate on it.
I think this is the wrong way to fix this for Python 2.2; if I add another pattern match against a token somewhere else, it will break in the same way, require the same process of deduction to figure out what's going on, and then require another similar patch. A better fix would fix it systemwide in one place, although I don't know what that would look like.
PottyMouth was written for 2.4 originally, was never intended to support 2.2, and 2.2 is almost ten years old. I don't want to clutter the code with patches for 2.2.