85 expected_identity: str |
None =
None,
87 """Return the line index where file content begins.
89 Scans at most the first 5 lines of *lines*, in strict order:
90 shebang → encoding → file-identity comment → blank line.
95 Source file split by newlines (as returned by ``str.splitlines()``).
97 The file's path; its basename is used as the fallback identity
98 match when *expected_identity* is not provided.
99 expected_identity : str | None, optional
100 The exact expected file-identity comment (e.g.
101 ``"# oct/core/parsing.py"``). When supplied the match is strict
102 against this string; otherwise any ``"# ...<path.name>"`` line
105 func =
"header_boundary"
106 _dbg(
"OCT-CORE", func, f
"locating header boundary in {path}", 4)
107 limit = min(len(lines), 5)
111 if i < limit
and lines[i].strip().startswith(
"#!"):
115 if i < limit
and _ENCODING_RE.match(lines[i].strip()):
120 stripped = lines[i].strip()
121 if expected_identity
is not None:
123 stripped == expected_identity
124 or (stripped.startswith(
"# ")
and stripped.endswith(path.name))
128 stripped.startswith(
"# ")
and stripped.endswith(path.name)
134 if i > 0
and i < limit
and lines[i].strip() ==
"":