Changeset 1266
- Timestamp:
- Mar 20, 2014, 12:41:43 PM (10 years ago)
- Location:
- trunk/genshi
- Files:
-
- 2 edited
-
_speedups.c (modified) (1 diff)
-
tests/core.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/genshi/_speedups.c
r1168 r1266 243 243 { 244 244 static char *kwlist[] = {"seq", "escape_quotes", 0}; 245 PyObject *seq = NULL, *seq2, * tmp, *tmp2;245 PyObject *seq = NULL, *seq2, *it, *tmp, *tmp2; 246 246 char quotes = 1; 247 Py_ssize_t n;248 int i;249 247 250 248 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|b", kwlist, &seq, "es)) { 251 249 return NULL; 252 250 } 253 if (!PySequence_Check(seq)) { 254 return NULL; 255 } 256 n = PySequence_Size(seq); 257 if (n < 0) { 258 return NULL; 259 } 260 seq2 = PyTuple_New(n); 251 it = PyObject_GetIter(seq); 252 if (it == NULL) 253 return NULL; 254 seq2 = PyList_New(0); 261 255 if (seq2 == NULL) { 262 return NULL; 263 } 264 for (i = 0; i < n; i++) { 265 tmp = PySequence_GetItem(seq, i); 266 if (tmp == NULL) { 267 Py_DECREF(seq2); 268 return NULL; 269 } 256 Py_DECREF(it); 257 return NULL; 258 } 259 while ((tmp = PyIter_Next(it))) { 270 260 tmp2 = escape(tmp, quotes); 271 261 if (tmp2 == NULL) { 272 262 Py_DECREF(seq2); 273 return NULL; 274 } 275 PyTuple_SET_ITEM(seq2, i, tmp2); 263 Py_DECREF(it); 264 return NULL; 265 } 266 PyList_Append(seq2, tmp2); 276 267 Py_DECREF(tmp); 268 } 269 Py_DECREF(it); 270 if (PyErr_Occurred()) { 271 Py_DECREF(seq2); 272 return NULL; 277 273 } 278 274 tmp = PyUnicode_Join(self, seq2); -
trunk/genshi/tests/core.py
r1168 r1266 140 140 self.assertEquals('foo<br /><bar /><br /><baz />', markup) 141 141 142 def test_join_over_iter(self): 143 items = ['foo', '<bar />', Markup('<baz />')] 144 markup = Markup('<br />').join(i for i in items) 145 self.assertEquals('foo<br /><bar /><br /><baz />', markup) 146 142 147 def test_stripentities_all(self): 143 148 markup = Markup('& j').stripentities()
Note: See TracChangeset
for help on using the changeset viewer.
