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

Function restore

Lib/difflib.py:2073–2103  ·  view source on GitHub ↗

r""" Generate one of the two sequences that generated a delta. Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract lines originating from file 1 or 2 (parameter `which`), stripping off line prefixes. Examples: >>> diff = ndiff('one\ntwo\nthree\n'.splitline

(delta, which)

Source from the content-addressed store, hash-verified

2071
2072
2073def restore(delta, which):
2074 r"""
2075 Generate one of the two sequences that generated a delta.
2076
2077 Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract
2078 lines originating from file 1 or 2 (parameter `which`), stripping off line
2079 prefixes.
2080
2081 Examples:
2082
2083 >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
2084 ... 'ore\ntree\nemu\n'.splitlines(keepends=True))
2085 >>> diff = list(diff)
2086 >>> print(''.join(restore(diff, 1)), end="")
2087 one
2088 two
2089 three
2090 >>> print(''.join(restore(diff, 2)), end="")
2091 ore
2092 tree
2093 emu
2094 """
2095 try:
2096 tag = {1: "- ", 2: "+ "}[int(which)]
2097 except KeyError:
2098 raise ValueError('unknown delta choice (must be 1 or 2): %r'
2099 % which) from None
2100 prefixes = (" ", tag)
2101 for line in delta:
2102 if line[:2] in prefixes:
2103 yield line[2:]

Callers 1

__exit__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…