Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 85383) +++ Misc/NEWS (working copy) @@ -315,6 +315,9 @@ - Issue #9315: Fix for the trace module to record correct class name for tracing methods. +- Issue #10076: Fix regression in 2.5 that prevented compiled regex patterns + from being copied. + Extension Modules ----------------- Index: Lib/test/test_re.py =================================================================== --- Lib/test/test_re.py (revision 85383) +++ Lib/test/test_re.py (working copy) @@ -1,4 +1,5 @@ from test.test_support import verbose, run_unittest, import_module +import copy import re from re import Scanner import sys, traceback @@ -711,6 +712,14 @@ self.assertRaises(TypeError, re.finditer, "a", {}) self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow]) + def test_copy(self): + pattern1 = re.compile('a.c') + self.assertTrue(pattern1.match('abc')) + pattern2 = copy.copy(pattern1) + self.assertTrue(pattern2.match('abc')) + pattern3 = copy.deepcopy(pattern1) + self.assertTrue(pattern3.match('abc')) + def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR if verbose: Index: Modules/_sre.c =================================================================== --- Modules/_sre.c (revision 85383) +++ Modules/_sre.c (working copy) @@ -2488,10 +2488,10 @@ return pattern_subx(self, ptemplate, string, count, 1); } +#ifdef USE_BUILTIN_COPY static PyObject* pattern_copy(PatternObject* self, PyObject *unused) { -#ifdef USE_BUILTIN_COPY PatternObject* copy; int offset; @@ -2510,16 +2510,13 @@ copy->weakreflist = NULL; return (PyObject*) copy; -#else - PyErr_SetString(PyExc_TypeError, "cannot copy this pattern object"); - return NULL; -#endif } +#endif +#ifdef USE_BUILTIN_COPY static PyObject* pattern_deepcopy(PatternObject* self, PyObject* memo) { -#ifdef USE_BUILTIN_COPY PatternObject* copy; copy = (PatternObject*) pattern_copy(self); @@ -2532,12 +2529,8 @@ Py_DECREF(copy); return NULL; } - -#else - PyErr_SetString(PyExc_TypeError, "cannot deepcopy this pattern object"); - return NULL; -#endif } +#endif PyDoc_STRVAR(pattern_match_doc, "match(string[, pos[, endpos]]) --> match object or None.\n\ @@ -2593,8 +2586,10 @@ pattern_finditer_doc}, #endif {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS}, +#ifdef USE_BUILTIN_COPY {"__copy__", (PyCFunction) pattern_copy, METH_NOARGS}, {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O}, +#endif {NULL, NULL} };