1818 Deque ,
1919 Dict ,
2020 Iterable ,
21+ Iterator ,
2122 List ,
2223 Optional ,
2324 Sequence ,
@@ -98,29 +99,31 @@ def get_rules(parsers: List[str], regexes: Optional[io.IOBase]) -> Matchers:
9899
99100
100101def parse_item (item : str , all : list [str ] | None ) -> list [str ]:
101- if item == '*' :
102+ if item == "*" :
102103 assert all
103104 return all
104- elif item .startswith ('{' ):
105- assert item .endswith ('}' )
106- return item [1 :- 1 ].split (',' )
105+ elif item .startswith ("{" ):
106+ assert item .endswith ("}" )
107+ return item [1 :- 1 ].split ("," )
107108 else :
108109 return [item ]
109110
111+
110112def rules_to_parsers (args : argparse .Namespace ) -> Iterator [tuple [str , str , int ]]:
111113 seen = set ()
112114 for selector in args .selector :
113- p , c , s = selector .split (':' )
115+ p , c , s = selector .split (":" )
114116 for triplet in (
115- (pp , ' none' if ss == 0 else cc , ss )
116- for pp in parse_item (p , [' basic' , ' re2' , ' regex' , ' legacy' ])
117- for cc in (parse_item (c , list (CACHES )) if CACHEABLE [pp ] else [' none' ])
118- for ss in (map (int , parse_item (s , None )) if cc != ' none' else [0 ])
117+ (pp , " none" if ss == 0 else cc , ss )
118+ for pp in parse_item (p , [" basic" , " re2" , " regex" , " legacy" ])
119+ for cc in (parse_item (c , list (CACHES )) if CACHEABLE [pp ] else [" none" ])
120+ for ss in (map (int , parse_item (s , None )) if cc != " none" else [0 ])
119121 ):
120122 if triplet not in seen :
121123 seen .add (triplet )
122124 yield triplet
123125
126+
124127def run_stdout (args : argparse .Namespace ) -> None :
125128 lines = list (map (sys .intern , args .file ))
126129 count = len (lines )
@@ -132,15 +135,14 @@ def run_stdout(args: argparse.Namespace) -> None:
132135 rules = get_rules ([* {p for p , _ , _ in parsers }], args .regexes )
133136
134137 w = max (
135- math .ceil (3 + len (p ) + len (c ) + (s and math .log10 (s )))
136- for p , c , s in parsers
138+ math .ceil (3 + len (p ) + len (c ) + (s and math .log10 (s ))) for p , c , s in parsers
137139 )
138140 for p , c , n in parsers :
139141 name = "-" .join (map (str , filter (None , (p , c != "none" and c , n ))))
140142 print (f"{ name :{w }} " , end = ": " , flush = True )
141143
142- p = get_parser (p , c , n , rules )
143- t = run (p , lines )
144+ parser = get_parser (p , c , n , rules )
145+ t = run (parser , lines )
144146
145147 secs = t / 1e9
146148 tpl = t / 1000 / len (lines )
@@ -159,8 +161,7 @@ def run_csv(args: argparse.Namespace) -> None:
159161 rules = get_rules ([* {p for p , _ , _ in parsers }], args .regexes )
160162 columns = {"size" : "" }
161163 columns .update (
162- (f"{ p } -{ c } " , p if c == "none" else f"{ p } -{ c } " )
163- for p , c , _ in parsers
164+ (f"{ p } -{ c } " , p if c == "none" else f"{ p } -{ c } " ) for p , c , _ in parsers
164165 )
165166 w = csv .DictWriter (
166167 sys .stdout ,
@@ -183,13 +184,15 @@ def run_csv(args: argparse.Namespace) -> None:
183184 # cache could be ignored as it should always be `"none"`
184185 for parser , cache , _ in ps :
185186 p = get_parser (parser , cache , 0 , rules )
186- zeroes [f"{ parser } -{ cache } " ] = run (p , linges ) // LEN
187+ zeroes [f"{ parser } -{ cache } " ] = run (p , lines ) // LEN
187188
188189 # special cases for configurations where we can't have
189190 # cachesize lines, write the template row out directly
190- if all (p == 'legacy' for p , _ , _ in parsers )\
191- or all (c == 'none' for _ , c , _ in parsers )\
192- or all (s == 0 for _ , _ , s in parsers ):
191+ if (
192+ all (p == "legacy" for p , _ , _ in parsers )
193+ or all (c == "none" for _ , c , _ in parsers )
194+ or all (s == 0 for _ , _ , s in parsers )
195+ ):
193196 zeroes ["size" ] = 0
194197 w .writerow (zeroes )
195198 return
@@ -475,10 +478,10 @@ def __call__(
475478 nargs = "*" ,
476479 default = ["*:*:{10,20,50,100,200,500,1000,2000,5000}" ],
477480 help = f"""A generative selector expression, composed of 3 parts: 1.
478- the parser (base), 2. the cache implementation ({ ', ' .join (CACHES )} )
481+ the parser (base), 2. the cache implementation ({ ", " .join (CACHES )} )
479482and 3. the cache size. For parser and cache `*` is an alias for stands
480483in for "every value", a bracketed expression for an enumeration, and
481- the selector can be repeated to explicitly list each configuration """
484+ the selector can be repeated to explicitly list each configuration """ ,
482485)
483486
484487hitrates = sub .add_parser (
0 commit comments