MCPcopy Index your code
hub / github.com/RustPython/RustPython / restore

Function restore

Lib/difflib.py:2034–2064  ·  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

2032
2033
2034def restore(delta, which):
2035 r"""
2036 Generate one of the two sequences that generated a delta.
2037
2038 Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract
2039 lines originating from file 1 or 2 (parameter `which`), stripping off line
2040 prefixes.
2041
2042 Examples:
2043
2044 >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
2045 ... 'ore\ntree\nemu\n'.splitlines(keepends=True))
2046 >>> diff = list(diff)
2047 >>> print(''.join(restore(diff, 1)), end="")
2048 one
2049 two
2050 three
2051 >>> print(''.join(restore(diff, 2)), end="")
2052 ore
2053 tree
2054 emu
2055 """
2056 try:
2057 tag = {1: "- ", 2: "+ "}[int(which)]
2058 except KeyError:
2059 raise ValueError('unknown delta choice (must be 1 or 2): %r'
2060 % which) from None
2061 prefixes = (" ", tag)
2062 for line in delta:
2063 if line[:2] in prefixes:
2064 yield line[2:]

Callers 1

__exit__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected