MCPcopy Index your code
hub / github.com/python/cpython / _join_translated_parts

Function _join_translated_parts

Lib/fnmatch.py:186–209  ·  view source on GitHub ↗
(parts, star_indices)

Source from the content-addressed store, hash-verified

184
185
186def _join_translated_parts(parts, star_indices):
187 if not star_indices:
188 return fr'(?s:{"".join(parts)})\z'
189 iter_star_indices = iter(star_indices)
190 j = next(iter_star_indices)
191 buffer = parts[:j] # fixed pieces at the start
192 append, extend = buffer.append, buffer.extend
193 i = j + 1
194 for j in iter_star_indices:
195 # Now deal with STAR fixed STAR fixed ...
196 # For an interior `STAR fixed` pairing, we want to do a minimal
197 # .*? match followed by `fixed`, with no possibility of backtracking.
198 # Atomic groups ("(?>...)") allow us to spell that directly.
199 # Note: people rely on the undocumented ability to join multiple
200 # translate() results together via "|" to build large regexps matching
201 # "one of many" shell patterns.
202 append('(?>.*?')
203 extend(parts[i:j])
204 append(')')
205 i = j + 1
206 append('.*')
207 extend(parts[i:])
208 res = ''.join(buffer)
209 return fr'(?s:{res})\z'

Callers 1

translateFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…