| 184 | |
| 185 | |
| 186 | def _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' |