@@ -526,24 +526,92 @@ def test_flags(self):
526526 self .assertNotEqual (re .compile ('^pattern$' , flag ), None )
527527
528528 def test_sre_character_literals (self ):
529- for i in [0 , 8 , 16 , 32 , 64 , 127 , 128 , 255 ]:
530- self .assertNotEqual (re .match (r"\%03o" % i , chr (i )), None )
531- self .assertNotEqual (re .match (r"\%03o0" % i , chr (i )+ "0" ), None )
532- self .assertNotEqual (re .match (r"\%03o8" % i , chr (i )+ "8" ), None )
533- self .assertNotEqual (re .match (r"\x%02x" % i , chr (i )), None )
534- self .assertNotEqual (re .match (r"\x%02x0" % i , chr (i )+ "0" ), None )
535- self .assertNotEqual (re .match (r"\x%02xz" % i , chr (i )+ "z" ), None )
536- self .assertRaises (re .error , re .match , "\911 " , "" )
529+ for i in [0 , 8 , 16 , 32 , 64 , 127 , 128 , 255 , 256 , 0xFFFF , 0x10000 , 0x10FFFF ]:
530+ if i < 256 :
531+ self .assertIsNotNone (re .match (r"\%03o" % i , chr (i )))
532+ self .assertIsNotNone (re .match (r"\%03o0" % i , chr (i )+ "0" ))
533+ self .assertIsNotNone (re .match (r"\%03o8" % i , chr (i )+ "8" ))
534+ self .assertIsNotNone (re .match (r"\x%02x" % i , chr (i )))
535+ self .assertIsNotNone (re .match (r"\x%02x0" % i , chr (i )+ "0" ))
536+ self .assertIsNotNone (re .match (r"\x%02xz" % i , chr (i )+ "z" ))
537+ if i < 0x10000 :
538+ self .assertIsNotNone (re .match (r"\u%04x" % i , chr (i )))
539+ self .assertIsNotNone (re .match (r"\u%04x0" % i , chr (i )+ "0" ))
540+ self .assertIsNotNone (re .match (r"\u%04xz" % i , chr (i )+ "z" ))
541+ self .assertIsNotNone (re .match (r"\U%08x" % i , chr (i )))
542+ self .assertIsNotNone (re .match (r"\U%08x0" % i , chr (i )+ "0" ))
543+ self .assertIsNotNone (re .match (r"\U%08xz" % i , chr (i )+ "z" ))
544+ self .assertIsNotNone (re .match (r"\0" , "\000 " ))
545+ self .assertIsNotNone (re .match (r"\08" , "\000 8" ))
546+ self .assertIsNotNone (re .match (r"\01" , "\001 " ))
547+ self .assertIsNotNone (re .match (r"\018" , "\001 8" ))
548+ self .assertIsNotNone (re .match (r"\567" , chr (0o167 )))
549+ self .assertRaises (re .error , re .match , r"\911" , "" )
550+ self .assertRaises (re .error , re .match , r"\x1" , "" )
551+ self .assertRaises (re .error , re .match , r"\x1z" , "" )
552+ self .assertRaises (re .error , re .match , r"\u123" , "" )
553+ self .assertRaises (re .error , re .match , r"\u123z" , "" )
554+ self .assertRaises (re .error , re .match , r"\U0001234" , "" )
555+ self .assertRaises (re .error , re .match , r"\U0001234z" , "" )
556+ self .assertRaises (re .error , re .match , r"\U00110000" , "" )
537557
538558 def test_sre_character_class_literals (self ):
559+ for i in [0 , 8 , 16 , 32 , 64 , 127 , 128 , 255 , 256 , 0xFFFF , 0x10000 , 0x10FFFF ]:
560+ if i < 256 :
561+ self .assertIsNotNone (re .match (r"[\%o]" % i , chr (i )))
562+ self .assertIsNotNone (re .match (r"[\%o8]" % i , chr (i )))
563+ self .assertIsNotNone (re .match (r"[\%03o]" % i , chr (i )))
564+ self .assertIsNotNone (re .match (r"[\%03o0]" % i , chr (i )))
565+ self .assertIsNotNone (re .match (r"[\%03o8]" % i , chr (i )))
566+ self .assertIsNotNone (re .match (r"[\x%02x]" % i , chr (i )))
567+ self .assertIsNotNone (re .match (r"[\x%02x0]" % i , chr (i )))
568+ self .assertIsNotNone (re .match (r"[\x%02xz]" % i , chr (i )))
569+ if i < 0x10000 :
570+ self .assertIsNotNone (re .match (r"[\u%04x]" % i , chr (i )))
571+ self .assertIsNotNone (re .match (r"[\u%04x0]" % i , chr (i )))
572+ self .assertIsNotNone (re .match (r"[\u%04xz]" % i , chr (i )))
573+ self .assertIsNotNone (re .match (r"[\U%08x]" % i , chr (i )))
574+ self .assertIsNotNone (re .match (r"[\U%08x0]" % i , chr (i )+ "0" ))
575+ self .assertIsNotNone (re .match (r"[\U%08xz]" % i , chr (i )+ "z" ))
576+ self .assertRaises (re .error , re .match , r"[\911]" , "" )
577+ self .assertRaises (re .error , re .match , r"[\x1z]" , "" )
578+ self .assertRaises (re .error , re .match , r"[\u123z]" , "" )
579+ self .assertRaises (re .error , re .match , r"[\U0001234z]" , "" )
580+ self .assertRaises (re .error , re .match , r"[\U00110000]" , "" )
581+
582+ def test_sre_byte_literals (self ):
583+ for i in [0 , 8 , 16 , 32 , 64 , 127 , 128 , 255 ]:
584+ self .assertIsNotNone (re .match ((r"\%03o" % i ).encode (), bytes ([i ])))
585+ self .assertIsNotNone (re .match ((r"\%03o0" % i ).encode (), bytes ([i ])+ b"0" ))
586+ self .assertIsNotNone (re .match ((r"\%03o8" % i ).encode (), bytes ([i ])+ b"8" ))
587+ self .assertIsNotNone (re .match ((r"\x%02x" % i ).encode (), bytes ([i ])))
588+ self .assertIsNotNone (re .match ((r"\x%02x0" % i ).encode (), bytes ([i ])+ b"0" ))
589+ self .assertIsNotNone (re .match ((r"\x%02xz" % i ).encode (), bytes ([i ])+ b"z" ))
590+ self .assertIsNotNone (re .match (br"\u" , b'u' ))
591+ self .assertIsNotNone (re .match (br"\U" , b'U' ))
592+ self .assertIsNotNone (re .match (br"\0" , b"\000 " ))
593+ self .assertIsNotNone (re .match (br"\08" , b"\000 8" ))
594+ self .assertIsNotNone (re .match (br"\01" , b"\001 " ))
595+ self .assertIsNotNone (re .match (br"\018" , b"\001 8" ))
596+ self .assertIsNotNone (re .match (br"\567" , bytes ([0o167 ])))
597+ self .assertRaises (re .error , re .match , br"\911" , b"" )
598+ self .assertRaises (re .error , re .match , br"\x1" , b"" )
599+ self .assertRaises (re .error , re .match , br"\x1z" , b"" )
600+
601+ def test_sre_byte_class_literals (self ):
539602 for i in [0 , 8 , 16 , 32 , 64 , 127 , 128 , 255 ]:
540- self .assertNotEqual (re .match (r"[\%03o]" % i , chr (i )), None )
541- self .assertNotEqual (re .match (r"[\%03o0]" % i , chr (i )), None )
542- self .assertNotEqual (re .match (r"[\%03o8]" % i , chr (i )), None )
543- self .assertNotEqual (re .match (r"[\x%02x]" % i , chr (i )), None )
544- self .assertNotEqual (re .match (r"[\x%02x0]" % i , chr (i )), None )
545- self .assertNotEqual (re .match (r"[\x%02xz]" % i , chr (i )), None )
546- self .assertRaises (re .error , re .match , "[\911 ]" , "" )
603+ self .assertIsNotNone (re .match ((r"[\%o]" % i ).encode (), bytes ([i ])))
604+ self .assertIsNotNone (re .match ((r"[\%o8]" % i ).encode (), bytes ([i ])))
605+ self .assertIsNotNone (re .match ((r"[\%03o]" % i ).encode (), bytes ([i ])))
606+ self .assertIsNotNone (re .match ((r"[\%03o0]" % i ).encode (), bytes ([i ])))
607+ self .assertIsNotNone (re .match ((r"[\%03o8]" % i ).encode (), bytes ([i ])))
608+ self .assertIsNotNone (re .match ((r"[\x%02x]" % i ).encode (), bytes ([i ])))
609+ self .assertIsNotNone (re .match ((r"[\x%02x0]" % i ).encode (), bytes ([i ])))
610+ self .assertIsNotNone (re .match ((r"[\x%02xz]" % i ).encode (), bytes ([i ])))
611+ self .assertIsNotNone (re .match (br"[\u]" , b'u' ))
612+ self .assertIsNotNone (re .match (br"[\U]" , b'U' ))
613+ self .assertRaises (re .error , re .match , br"[\911]" , "" )
614+ self .assertRaises (re .error , re .match , br"[\x1z]" , "" )
547615
548616 def test_bug_113254 (self ):
549617 self .assertEqual (re .match (r'(a)|(b)' , 'b' ).start (1 ), - 1 )
0 commit comments