feat: sync Python Qwen Code hook integration
This commit is contained in:
1 parent
52863399d5
commit
e19c33fc2d
17 files changed
+1761
-275
No files matched your search
@@ -0,0 +1,32 @@
|
||||
"""Read-only parser for the dotenv grammar used by Qwen Code."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Dict
|
||||
|
||||
|
||||
_LINE = re.compile(
|
||||
r"^\s*(?:export\s+)?([\w.-]+)"
|
||||
r"(?:\s*=\s*?|:\s+?)"
|
||||
r"(\s*'(?:\\'|[^'])*'|\s*\"(?:\\\"|[^\"])*\"|"
|
||||
r"\s*`(?:\\`|[^`])*`|[^#\r\n]+)?"
|
||||
r"\s*(?:#.*)?$",
|
||||
re.ASCII | re.MULTILINE,
|
||||
)
|
||||
|
||||
|
||||
def parse_dotenv(source: str) -> Dict[str, str]:
|
||||
"""Parse values with the same read-only rules as Node dotenv 17."""
|
||||
values: Dict[str, str] = {}
|
||||
normalized = source.replace("\r\n", "\n").replace("\r", "\n")
|
||||
for match in _LINE.finditer(normalized):
|
||||
key = match.group(1)
|
||||
value = (match.group(2) or "").strip()
|
||||
quote = value[0] if value else ""
|
||||
if len(value) >= 2 and quote in {"'", '"', "`"} and value[-1] == quote:
|
||||
value = value[1:-1]
|
||||
if quote == '"':
|
||||
value = value.replace(r"\n", "\n").replace(r"\r", "\r")
|
||||
values[key] = value
|
||||
return values
|
||||
Reference in new issue
Block a user