[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.65,2.66

Fredrik Lundh effbot@users.sourceforge.net
Tue, 18 Sep 2001 13:55:26 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv30223/Modules

Modified Files:
	_sre.c 
Log Message:


fixed #449964: sre.sub raises an exception if the template contains a
\g<x> group reference followed by a character escape

(also restructured a few things on the way to fixing #449000)


Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.65
retrieving revision 2.66
diff -C2 -d -r2.65 -r2.66
*** _sre.c	2001/09/18 18:47:09	2.65
--- _sre.c	2001/09/18 20:55:24	2.66
***************
*** 32,36 ****
   * 2001-05-14 fl  fixes for 1.5.2
   * 2001-07-01 fl  added BIGCHARSET support (from Martin von Loewis)
!  * 2001-09-18 fl  
   *
   * Copyright (c) 1997-2001 by Secret Labs AB.  All rights reserved.
--- 32,36 ----
   * 2001-05-14 fl  fixes for 1.5.2
   * 2001-07-01 fl  added BIGCHARSET support (from Martin von Loewis)
!  * 2001-09-18 fl  added _getliteral helper
   *
   * Copyright (c) 1997-2001 by Secret Labs AB.  All rights reserved.
***************
*** 1960,1982 ****
  
  static PyObject*
! pattern_isliteral(PatternObject* self, PyObject* args)
  {
!     /* internal: return true if pattern consists of literal text only */
  
      SRE_CODE* code;
!     PyObject* isliteral;
  
!     if (!PyArg_ParseTuple(args, ":_isliteral"))
          return NULL;
  
      code = PatternObject_GetCode(self);
  
!     if (code[0] == SRE_OP_INFO && code[2] & SRE_INFO_LITERAL)
!         isliteral = Py_True;
!     else
!         isliteral = Py_False;
  
!     Py_INCREF(isliteral);
!     return isliteral;
  }
  
--- 1960,1986 ----
  
  static PyObject*
! pattern_getliteral(PatternObject* self, PyObject* args)
  {
!     /* internal: if the pattern is a literal string, return that
!        string.  otherwise, return None */
  
      SRE_CODE* code;
!     PyObject* literal;
  
!     if (!PyArg_ParseTuple(args, ":_getliteral"))
          return NULL;
  
      code = PatternObject_GetCode(self);
  
!     if (code[0] == SRE_OP_INFO && code[2] & SRE_INFO_LITERAL) {
!         /* FIXME: extract literal string from code buffer.  we can't
!            use the pattern member, since it may contain untranslated
!            escape codes (see SF bug 449000) */
!         literal = Py_None;
!     } else
!         literal = Py_None; /* no literal */
  
!     Py_INCREF(literal);
!     return literal;
  }
  
***************
*** 1991,1995 ****
      {"__copy__", (PyCFunction) pattern_copy, METH_VARARGS},
      {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_VARARGS},
!     {"_isliteral", (PyCFunction) pattern_isliteral, METH_VARARGS},
      {NULL, NULL}
  };
--- 1995,1999 ----
      {"__copy__", (PyCFunction) pattern_copy, METH_VARARGS},
      {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_VARARGS},
!     {"_getliteral", (PyCFunction) pattern_getliteral, METH_VARARGS},
      {NULL, NULL}
  };