MCPcopy
hub / github.com/psf/black / replace

Function replace

src/black/strings.py:316–335  ·  view source on GitHub ↗
(m: Match[str])

Source from the content-addressed store, hash-verified

314 return
315
316 def replace(m: Match[str]) -> str:
317 groups = m.groupdict()
318 back_slashes = groups["backslashes"]
319
320 if len(back_slashes) % 2 == 0:
321 return back_slashes + groups["body"]
322
323 if groups["u"]:
324 # \u
325 return back_slashes + "u" + groups["u"].lower()
326 elif groups["U"]:
327 # \U
328 return back_slashes + "U" + groups["U"].lower()
329 elif groups["x"]:
330 # \x
331 return back_slashes + "x" + groups["x"].lower()
332 else:
333 assert groups["N"], f"Unexpected match: {m}"
334 # \N{}
335 return back_slashes + "N{" + groups["N"].upper() + "}"
336
337 leaf.value = re.sub(UNICODE_ESCAPE_RE, replace, text)
338

Calls

no outgoing calls