MCPcopy Index your code
hub / github.com/bpython/bpython / encode

Function encode

bpython/test/test_line_properties.py:55–77  ·  view source on GitHub ↗

encode(3, 'abdcd', (1, 3, 'bdc')) -> a d' Written for prettier assert error messages

(cursor_offset: int, line: str, result: LinePart | None)

Source from the content-addressed store, hash-verified

53
54
55def encode(cursor_offset: int, line: str, result: LinePart | None) -> str:
56 """encode(3, 'abdcd', (1, 3, 'bdc')) -> a<bd|c>d&#x27;
57
58 Written for prettier assert error messages
59 """
60 encoded_line = line_with_cursor(cursor_offset, line)
61 if result is None:
62 return encoded_line
63 start = result.start
64 end = result.stop
65 value = result.word
66 assert line[start:end] == value
67 if start < cursor_offset:
68 encoded_line = encoded_line[:start] + "<" + encoded_line[start:]
69 else:
70 encoded_line = (
71 encoded_line[: start + 1] + "<" + encoded_line[start + 1 :]
72 )
73 if end < cursor_offset:
74 encoded_line = encoded_line[: end + 1] + ">" + encoded_line[end + 1 :]
75 else:
76 encoded_line = encoded_line[: end + 2] + ">" + encoded_line[end + 2 :]
77 return encoded_line
78
79
80class LineTestCase(unittest.TestCase):

Callers 2

assertAccessMethod · 0.85
test_encodeMethod · 0.85

Calls 1

line_with_cursorFunction · 0.85

Tested by

no test coverage detected