SVN: r24373 - in trunk/quixote: src test
Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 3 Jun 2004 10:28:51 -0400
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: nascheme
Date: 2004-06-03 10:26:46 -0400 (Thu, 03 Jun 2004)
New Revision: 24373
Modified:
trunk/quixote/src/_c_htmltext.c
trunk/quixote/test/test_html.py
Log:
Don't use quote_wrapper object for ints, longs, floats, and htmltext
objects. It's simpler and has the side effect of making the %d code
work for longs.
Modified: trunk/quixote/src/_c_htmltext.c
===================================================================
--- trunk/quixote/src/_c_htmltext.c 2004-06-03 14:23:38 UTC (rev 24372)
+++ trunk/quixote/src/_c_htmltext.c 2004-06-03 14:26:46 UTC (rev 24373)
@@ -130,6 +130,14 @@
quote_wrapper_new(PyObject *o)
{
QuoteWrapperObject *self;
+ if (htmltextObject_Check(o) ||
+ PyInt_Check(o) ||
+ PyFloat_Check(o) ||
+ PyLong_Check(o)) {
+ /* no need for wrapper */
+ Py_INCREF(o);
+ return o;
+ }
self = PyObject_New(QuoteWrapperObject, &QuoteWrapper_Type);
if (self == NULL)
return NULL;
@@ -148,48 +156,28 @@
static PyObject *
quote_wrapper_repr(QuoteWrapperObject *self)
{
+ PyObject *qs;
PyObject *s = PyObject_Repr(self->obj);
if (s == NULL)
return NULL;
- if (htmltextObject_Check(self->obj)) {
- return s;
- }
- else {
- PyObject *qs = escape_string(s);
- Py_DECREF(s);
- return qs;
- }
+ qs = escape_string(s);
+ Py_DECREF(s);
+ return qs;
}
static PyObject *
quote_wrapper_str(QuoteWrapperObject *self)
{
+ PyObject *qs;
PyObject *s = PyObject_Str(self->obj);
if (s == NULL)
return NULL;
- if (htmltextObject_Check(self->obj)) {
- return s;
- }
- else {
- PyObject *qs = escape_string(s);
- Py_DECREF(s);
- return qs;
- }
+ qs = escape_string(s);
+ Py_DECREF(s);
+ return qs;
}
static PyObject *
-quote_wrapper_int(QuoteWrapperObject *self)
-{
- return PyNumber_Int(self->obj);
-}
-
-static PyObject *
-quote_wrapper_float(QuoteWrapperObject *self)
-{
- return PyNumber_Float(self->obj);
-}
-
-static PyObject *
dict_wrapper_new(PyObject *o)
{
DictWrapperObject *self;
@@ -813,9 +801,9 @@
0, /*nb_xor*/
0, /*nb_or*/
0, /*nb_coerce*/
- (unaryfunc)quote_wrapper_int, /*nb_int*/
+ 0, /*nb_int*/
0, /*nb_long*/
- (unaryfunc)quote_wrapper_float, /*nb_float*/
+ 0, /*nb_float*/
};
static PyTypeObject QuoteWrapper_Type = {
Modified: trunk/quixote/test/test_html.py
===================================================================
--- trunk/quixote/test/test_html.py 2004-06-03 14:23:38 UTC (rev 24372)
+++ trunk/quixote/test/test_html.py 2004-06-03 14:26:46 UTC (rev 24373)
@@ -104,6 +104,8 @@
self.test_exc("s_fmt % Broken()", RuntimeError)
self.test_exc("htmltext('%r') % Broken()", RuntimeError)
self.test_exc("s_fmt % (1, 2)", TypeError)
+ self.test_val("htmltext('%d') % 12300000000000000000L",
+ "12300000000000000000")
def check_dict_format (self):
self.test_val("htmltext('%(a)s %(a)r %(b)s') % "