@@ -135,9 +135,26 @@ def setup(sre_compiler, error_class, flags_table):
135
135
MAGIC = 20171005
136
136
MAXREPEAT = 4294967295
137
137
MAXGROUPS = 2147483647
138
- FLAG_NAMES = ["re.TEMPLATE" , "re.IGNORECASE" , "re.LOCALE" , "re.MULTILINE" ,
139
- "re.DOTALL" , "re.UNICODE" , "re.VERBOSE" , "re.DEBUG" ,
140
- "re.ASCII" ]
138
+ FLAG_TEMPLATE = 1
139
+ FLAG_IGNORECASE = 2
140
+ FLAG_LOCALE = 4
141
+ FLAG_MULTILINE = 8
142
+ FLAG_DOTALL = 16
143
+ FLAG_UNICODE = 32
144
+ FLAG_VERBOSE = 64
145
+ FLAG_DEBUG = 128
146
+ FLAG_ASCII = 256
147
+ FLAG_NAMES = [
148
+ (FLAG_TEMPLATE , "re.TEMPLATE" ),
149
+ (FLAG_IGNORECASE , "re.IGNORECASE" ),
150
+ (FLAG_LOCALE , "re.LOCALE" ),
151
+ (FLAG_MULTILINE , "re.MULTILINE" ),
152
+ (FLAG_DOTALL , "re.DOTALL" ),
153
+ (FLAG_UNICODE , "re.UNICODE" ),
154
+ (FLAG_VERBOSE , "re.VERBOSE" ),
155
+ (FLAG_DEBUG , "re.DEBUG" ),
156
+ (FLAG_ASCII , "re.ASCII" ),
157
+ ]
141
158
142
159
143
160
class SRE_Match ():
@@ -269,13 +286,15 @@ def __tregex_compile(self, pattern, flags=None):
269
286
raise
270
287
return self .__compiled_regexes [(pattern , flags )]
271
288
272
-
273
289
def __repr__ (self ):
274
290
flags = self .flags
275
291
flag_items = []
276
- for i ,name in enumerate (FLAG_NAMES ):
277
- if flags & (1 << i ):
278
- flags -= (1 << i )
292
+ if not self .__binary :
293
+ if (flags & (FLAG_LOCALE | FLAG_UNICODE | FLAG_ASCII )) == FLAG_UNICODE :
294
+ flags &= ~ FLAG_UNICODE
295
+ for code , name in FLAG_NAMES :
296
+ if flags & code :
297
+ flags -= code
279
298
flag_items .append (name )
280
299
if flags != 0 :
281
300
flag_items .append ("0x%x" % flags )
0 commit comments