SVN: r25354 - in trunk/quixote: . test
Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 14 Oct 2004 15:42:23 -0400
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: nascheme
Date: 2004-10-14 15:42:10 -0400 (Thu, 14 Oct 2004)
New Revision: 25354
Modified:
trunk/quixote/_py_htmltext.py
trunk/quixote/test/utest_html.py
Log:
Fix Python implementation of stringify(). It should get the method
from the type object, not the instance.
Modified: trunk/quixote/_py_htmltext.py
===================================================================
--- trunk/quixote/_py_htmltext.py 2004-10-14 19:12:22 UTC (rev 25353)
+++ trunk/quixote/_py_htmltext.py 2004-10-14 19:42:10 UTC (rev 25354)
@@ -23,15 +23,16 @@
"""Return 'obj' as a string or unicode object. Tries to prevent
turning strings into unicode objects.
"""
- if isinstance(obj, basestring):
+ tp = type(obj)
+ if issubclass(tp, basestring):
return obj
- elif hasattr(obj, '__unicode__'):
- s = obj.__unicode__()
+ elif hasattr(tp, '__unicode__'):
+ s = tp.__unicode__(obj)
if not isinstance(s, basestring):
raise TypeError, '__unicode__ did not return a string'
return s
- elif hasattr(obj, '__str__'):
- s = obj.__str__()
+ elif hasattr(tp, '__str__'):
+ s = tp.__str__(obj)
if not isinstance(s, basestring):
raise TypeError, '__str__ did not return a string'
return s
Modified: trunk/quixote/test/utest_html.py
===================================================================
--- trunk/quixote/test/utest_html.py 2004-10-14 19:12:22 UTC (rev 25353)
+++ trunk/quixote/test/utest_html.py 2004-10-14 19:42:10 UTC (rev 25354)
@@ -1,6 +1,9 @@
from sancho.utest import UTest
from quixote import _py_htmltext
+markupchars = '<>&"'
+quotedchars = '<>&"'
+unicodechars = u'\u1234'
class Wrapper:
def __init__(self, s):
@@ -22,16 +25,14 @@
def __repr__(self):
raise BrokenError, 'eieee'
-markupchars = '<>&"'
-quotedchars = '<>&"'
-unicodechars = u'\u1234'
class HTMLTest (UTest):
def _pre(self):
- global htmltext, escape, htmlescape, TemplateIO
+ global htmltext, escape, htmlescape, TemplateIO, stringify
htmltext = _py_htmltext.htmltext
escape = _py_htmltext._escape_string
+ stringify = _py_htmltext.stringify
htmlescape = _py_htmltext.htmlescape
TemplateIO = _py_htmltext.TemplateIO
@@ -50,6 +51,14 @@
assert 0
except BrokenError: pass
+ def check_stringify(self):
+ assert stringify(markupchars) is markupchars
+ assert stringify(unicodechars) is unicodechars
+ assert stringify(Wrapper(unicodechars)) is unicodechars
+ assert stringify(Wrapper(markupchars)) is markupchars
+ assert stringify(Wrapper) == str(Wrapper)
+ assert stringify(None) == str(None)
+
def check_escape(self):
assert htmlescape(markupchars) == quotedchars
assert isinstance(htmlescape(markupchars), htmltext)
@@ -285,9 +294,10 @@
def _pre(self):
# using globals like this is a bit of a hack since it assumes
# Sancho tests each class individually, oh well
- global htmltext, escape, htmlescape
+ global htmltext, escape, htmlescape, stringify
htmltext = _c_htmltext.htmltext
escape = _c_htmltext._escape_string
+ stringify = _py_htmltext.stringify
htmlescape = _c_htmltext.htmlescape
class CTemplateTest(TemplateTest):