@@ -101,8 +101,6 @@ def _compile(code, pattern, flags):
101101 else :
102102 emit (ANY )
103103 elif op in REPEATING_CODES :
104- if flags & SRE_FLAG_TEMPLATE :
105- raise error ("internal: unsupported template operator %r" % (op ,))
106104 if _simple (av [2 ]):
107105 emit (REPEATING_CODES [op ][2 ])
108106 skip = _len (code ); emit (0 )
@@ -152,7 +150,7 @@ def _compile(code, pattern, flags):
152150 if lo > MAXCODE :
153151 raise error ("looks too much behind" )
154152 if lo != hi :
155- raise error ("look-behind requires fixed-width pattern" )
153+ raise PatternError ("look-behind requires fixed-width pattern" )
156154 emit (lo ) # look behind
157155 _compile (code , av [1 ], flags )
158156 emit (SUCCESS )
@@ -211,7 +209,7 @@ def _compile(code, pattern, flags):
211209 else :
212210 code [skipyes ] = _len (code ) - skipyes + 1
213211 else :
214- raise error ( "internal: unsupported operand type %r" % ( op ,) )
212+ raise PatternError ( f "internal: unsupported operand type { op !r } " )
215213
216214def _compile_charset (charset , flags , code ):
217215 # compile charset subprogram
@@ -237,7 +235,7 @@ def _compile_charset(charset, flags, code):
237235 else :
238236 emit (av )
239237 else :
240- raise error ( "internal: unsupported set operator %r" % ( op ,) )
238+ raise PatternError ( f "internal: unsupported set operator { op !r } " )
241239 emit (FAILURE )
242240
243241def _optimize_charset (charset , iscased = None , fixup = None , fixes = None ):
@@ -250,19 +248,19 @@ def _optimize_charset(charset, iscased=None, fixup=None, fixes=None):
250248 while True :
251249 try :
252250 if op is LITERAL :
253- if fixup :
254- lo = fixup (av )
255- charmap [lo ] = 1
256- if fixes and lo in fixes :
257- for k in fixes [lo ]:
251+ if fixup : # IGNORECASE and not LOCALE
252+ av = fixup (av )
253+ charmap [av ] = 1
254+ if fixes and av in fixes :
255+ for k in fixes [av ]:
258256 charmap [k ] = 1
259257 if not hascased and iscased (av ):
260258 hascased = True
261259 else :
262260 charmap [av ] = 1
263261 elif op is RANGE :
264262 r = range (av [0 ], av [1 ]+ 1 )
265- if fixup :
263+ if fixup : # IGNORECASE and not LOCALE
266264 if fixes :
267265 for i in map (fixup , r ):
268266 charmap [i ] = 1
@@ -289,8 +287,7 @@ def _optimize_charset(charset, iscased=None, fixup=None, fixes=None):
289287 # Character set contains non-BMP character codes.
290288 # For range, all BMP characters in the range are already
291289 # proceeded.
292- if fixup :
293- hascased = True
290+ if fixup : # IGNORECASE and not LOCALE
294291 # For now, IN_UNI_IGNORE+LITERAL and
295292 # IN_UNI_IGNORE+RANGE_UNI_IGNORE work for all non-BMP
296293 # characters, because two characters (at least one of
@@ -301,7 +298,13 @@ def _optimize_charset(charset, iscased=None, fixup=None, fixes=None):
301298 # Also, both c.lower() and c.lower().upper() are single
302299 # characters for every non-BMP character.
303300 if op is RANGE :
304- op = RANGE_UNI_IGNORE
301+ if fixes : # not ASCII
302+ op = RANGE_UNI_IGNORE
303+ hascased = True
304+ else :
305+ assert op is LITERAL
306+ if not hascased and iscased (av ):
307+ hascased = True
305308 tail .append ((op , av ))
306309 break
307310
@@ -763,4 +766,3 @@ def compile(p, flags=0):
763766 p .state .groups - 1 ,
764767 groupindex , tuple (indexgroup )
765768 )
766-
0 commit comments