[Python-checkins] CVS: python/dist/src/Lib sre_parse.py,1.32,1.33

Fredrik Lundh python-dev@python.org
Sat, 2 Sep 2000 04:03:37 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv32410/Lib

Modified Files:
	sre_parse.py 
Log Message:


-- tightened up parsing of octal numbers

-- improved the SRE test harness: don't use asserts, test a few more
   things (including more boundary conditions)


Index: sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -r1.32 -r1.33
*** sre_parse.py	2000/09/02 07:44:32	1.32
--- sre_parse.py	2000/09/02 11:03:33	1.33
***************
*** 16,20 ****
  
  SPECIAL_CHARS = ".\\[{()*+?^$|"
! REPEAT_CHARS  = "*+?{"
  
  DIGITS = tuple("0123456789")
--- 16,20 ----
  
  SPECIAL_CHARS = ".\\[{()*+?^$|"
! REPEAT_CHARS = "*+?{"
  
  DIGITS = tuple("0123456789")
***************
*** 260,270 ****
              while source.next in HEXDIGITS and len(escape) < 4:
                  escape = escape + source.get()
!             escape = escape[2:]
!             if len(escape) != 2:
!                 raise error, "bogus escape: %s" % repr("\\" + escape)
!             return LITERAL, int(escape, 16) & 0xff
          elif escape[1:2] == "0":
              # octal escape
!             while source.next in OCTDIGITS and len(escape) < 5:
                  escape = escape + source.get()
              return LITERAL, int(escape[1:], 8) & 0xff
--- 260,269 ----
              while source.next in HEXDIGITS and len(escape) < 4:
                  escape = escape + source.get()
!             if len(escape) != 4:
!                 raise ValueError
!             return LITERAL, int(escape[2:], 16) & 0xff
          elif escape[1:2] == "0":
              # octal escape
!             while source.next in OCTDIGITS and len(escape) < 4:
                  escape = escape + source.get()
              return LITERAL, int(escape[1:], 8) & 0xff
***************
*** 274,278 ****
              if source.next in DIGITS:
                  escape = escape + source.get()
!                 if escape[2] in OCTDIGITS and source.next in OCTDIGITS:
                      # got three octal digits; this is an octal escape
                      escape = escape + source.get()
--- 273,278 ----
              if source.next in DIGITS:
                  escape = escape + source.get()
!                 if (escape[1] in OCTDIGITS and escape[2] in OCTDIGITS and
!                     source.next in OCTDIGITS):
                      # got three octal digits; this is an octal escape
                      escape = escape + source.get()
***************
*** 282,286 ****
              if group:
                  return GROUPREF, group
!             raise error, "bogus escape: %s" % repr(escape)
          if len(escape) == 2:
              return LITERAL, ord(escape[1])
--- 282,286 ----
              if group:
                  return GROUPREF, group
!             raise ValueError
          if len(escape) == 2:
              return LITERAL, ord(escape[1])