MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / parse_language_value

Function parse_language_value

graphify/rcfile.py:91–115  ·  view source on GitHub ↗

Resolve the right-hand side of ``language. =`` to a canonical suffix. Accepts a name from :data:`LANGUAGE_ALIASES` (case-insensitive) or an explicit dotted extension. Raises ``ValueError`` for anything else.

(value: str)

Source from the content-addressed store, hash-verified

89
90
91def parse_language_value(value: str) -> str:
92 """Resolve the right-hand side of ``language.<ext>=`` to a canonical suffix.
93
94 Accepts a name from :data:`LANGUAGE_ALIASES` (case-insensitive) or an
95 explicit dotted extension. Raises ``ValueError`` for anything else.
96 """
97 v = value.strip()
98 if not v:
99 raise ValueError("empty value")
100 if v.startswith("."):
101 ext = _normalise_ext(v)
102 if len(ext) < 2 or any(ch.isspace() for ch in ext):
103 raise ValueError(f"{value!r} is not an extension")
104 from graphify.detect import CODE_EXTENSIONS, DOC_EXTENSIONS
105 if ext not in CODE_EXTENSIONS and ext not in DOC_EXTENSIONS:
106 raise ValueError(f"unknown extension {value!r}")
107 return ext
108 try:
109 return LANGUAGE_ALIASES[v.lower()]
110 except KeyError:
111 known = ", ".join(sorted(LANGUAGE_ALIASES))
112 raise ValueError(
113 f"unknown language {value!r} (use one of: {known}; "
114 f"or an explicit extension such as .php)"
115 ) from None
116
117
118_BOOL_VALUES = {

Calls 2

_normalise_extFunction · 0.85
joinMethod · 0.45