@@ -245,54 +245,6 @@ template_iter(PyObject *op)
245245 return (PyObject * )iter ;
246246}
247247
248- static PyObject *
249- template_strings_append_str (PyObject * strings , PyObject * str )
250- {
251- Py_ssize_t stringslen = PyTuple_GET_SIZE (strings );
252- PyObject * string = PyTuple_GET_ITEM (strings , stringslen - 1 );
253- PyObject * concat = PyUnicode_Concat (string , str );
254- if (concat == NULL ) {
255- return NULL ;
256- }
257-
258- PyObject * newstrings = PyTuple_New (stringslen );
259- if (newstrings == NULL ) {
260- Py_DECREF (concat );
261- return NULL ;
262- }
263-
264- for (Py_ssize_t i = 0 ; i < stringslen - 1 ; i ++ ) {
265- PyTuple_SET_ITEM (newstrings , i , Py_NewRef (PyTuple_GET_ITEM (strings , i )));
266- }
267- PyTuple_SET_ITEM (newstrings , stringslen - 1 , concat );
268-
269- return newstrings ;
270- }
271-
272- static PyObject *
273- template_strings_prepend_str (PyObject * strings , PyObject * str )
274- {
275- Py_ssize_t stringslen = PyTuple_GET_SIZE (strings );
276- PyObject * string = PyTuple_GET_ITEM (strings , 0 );
277- PyObject * concat = PyUnicode_Concat (str , string );
278- if (concat == NULL ) {
279- return NULL ;
280- }
281-
282- PyObject * newstrings = PyTuple_New (stringslen );
283- if (newstrings == NULL ) {
284- Py_DECREF (concat );
285- return NULL ;
286- }
287-
288- PyTuple_SET_ITEM (newstrings , 0 , concat );
289- for (Py_ssize_t i = 1 ; i < stringslen ; i ++ ) {
290- PyTuple_SET_ITEM (newstrings , i , Py_NewRef (PyTuple_GET_ITEM (strings , i )));
291- }
292-
293- return newstrings ;
294- }
295-
296248static PyObject *
297249template_strings_concat (PyObject * left , PyObject * right )
298250{
@@ -344,46 +296,16 @@ template_concat_templates(templateobject *self, templateobject *other)
344296 return newtemplate ;
345297}
346298
347- static PyObject *
348- template_concat_template_str (templateobject * self , PyObject * other )
349- {
350- PyObject * newstrings = template_strings_append_str (self -> strings , other );
351- if (newstrings == NULL ) {
352- return NULL ;
353- }
354-
355- PyObject * newtemplate = _PyTemplate_Build (newstrings , self -> interpolations );
356- Py_DECREF (newstrings );
357- return newtemplate ;
358- }
359-
360- static PyObject *
361- template_concat_str_template (templateobject * self , PyObject * other )
362- {
363- PyObject * newstrings = template_strings_prepend_str (self -> strings , other );
364- if (newstrings == NULL ) {
365- return NULL ;
366- }
367-
368- PyObject * newtemplate = _PyTemplate_Build (newstrings , self -> interpolations );
369- Py_DECREF (newstrings );
370- return newtemplate ;
371- }
372-
373299PyObject *
374300_PyTemplate_Concat (PyObject * self , PyObject * other )
375301{
376302 if (_PyTemplate_CheckExact (self ) && _PyTemplate_CheckExact (other )) {
377303 return template_concat_templates ((templateobject * ) self , (templateobject * ) other );
378- }
379- else if ((_PyTemplate_CheckExact (self )) && PyUnicode_Check (other )) {
380- return template_concat_template_str ((templateobject * ) self , other );
381- }
382- else if (PyUnicode_Check (self ) && (_PyTemplate_CheckExact (other ))) {
383- return template_concat_str_template ((templateobject * ) other , self );
384- }
385- else {
386- Py_RETURN_NOTIMPLEMENTED ;
304+ } else {
305+ PyErr_Format (PyExc_TypeError ,
306+ "can only concatenate Template (not \"%.200s\") to Template" ,
307+ Py_TYPE (other )-> tp_name );
308+ return NULL ;
387309 }
388310}
389311
0 commit comments