Skip to content

Commit

Permalink
parsing !<str> tags correctly when load yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
wzdnzd committed Jul 16, 2024
1 parent 75f633f commit 98e03e8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions subscribe/airport.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def clean_text(document: str) -> str:
reader.seek(0, 0)
yaml.add_multi_constructor(
"str",
lambda loader, suffix, node: None,
lambda loader, suffix, node: str(node.value),
Loader=yaml.SafeLoader,
)
config = yaml.load(reader, Loader=yaml.SafeLoader)
Expand All @@ -715,7 +715,7 @@ def clean_text(document: str) -> str:
text = clean_text(document=text)
nodes = yaml.load(text, Loader=yaml.SafeLoader).get("proxies", [])
except yaml.constructor.ConstructorError:
yaml.add_multi_constructor("str", lambda loader, suffix, node: None, Loader=yaml.SafeLoader)
yaml.add_multi_constructor("str", lambda loader, suffix, node: str(node.value), Loader=yaml.SafeLoader)
nodes = yaml.load(text, Loader=yaml.FullLoader).get("proxies", [])
except Exception as e:
if throw:
Expand Down
2 changes: 1 addition & 1 deletion subscribe/crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ def check_status(
try:
proxies = yaml.load(content, Loader=yaml.SafeLoader).get("proxies", [])
except ConstructorError:
yaml.add_multi_constructor("str", lambda loader, suffix, node: None, Loader=yaml.SafeLoader)
yaml.add_multi_constructor("str", lambda loader, suffix, node: str(node.value), Loader=yaml.SafeLoader)
proxies = yaml.load(content, Loader=yaml.FullLoader).get("proxies", [])
except:
proxies = []
Expand Down
3 changes: 2 additions & 1 deletion subscribe/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ def aggregate(args: argparse.Namespace) -> None:
push_conf = group_configs.get(k, {})
target = utils.trim(push_conf.get("target", "")) or "clash"
mixed = target in ["v2ray", "mixed"]
emoji = push_conf.get("emoji", True)

regularize = push_conf.get("regularize", {})
if regularize and isinstance(regularize, dict) and regularize.get("enable", False):
Expand Down Expand Up @@ -579,7 +580,7 @@ def aggregate(args: argparse.Namespace) -> None:
if os.path.exists(generate_conf) and os.path.isfile(generate_conf):
os.remove(generate_conf)

success = subconverter.generate_conf(generate_conf, artifact, source_file, dest_file, target)
success = subconverter.generate_conf(generate_conf, artifact, source_file, dest_file, target, emoji)
if not success:
logger.error(f"cannot generate subconverter config file, group=[{k}]")
continue
Expand Down
5 changes: 3 additions & 2 deletions tools/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def main(args: argparse.Namespace) -> None:
try:
nodes = yaml.load(f, Loader=yaml.SafeLoader).get("proxies", [])
except yaml.constructor.ConstructorError:
yaml.add_multi_constructor("str", lambda loader, suffix, node: None, Loader=yaml.SafeLoader)
nodes = yaml.load(f, Loader=yaml.FullLoader).get("proxies", [])
f.seek(0, 0)
yaml.add_multi_constructor("str", lambda loader, suffix, node: str(node.value), Loader=yaml.SafeLoader)
nodes = yaml.load(f, Loader=yaml.SafeLoader).get("proxies", [])
except:
nodes = []

Expand Down
2 changes: 1 addition & 1 deletion tools/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def process(
try:
nodes = yaml.load(f, Loader=yaml.SafeLoader).get("proxies", [])
except yaml.constructor.ConstructorError:
yaml.add_multi_constructor("str", lambda loader, suffix, node: None, Loader=yaml.SafeLoader)
yaml.add_multi_constructor("str", lambda loader, suffix, node: str(node.value), Loader=yaml.SafeLoader)
nodes = yaml.load(f, Loader=yaml.FullLoader).get("proxies", [])

proxies = [x for x in nodes if x.get("name", "") not in names]
Expand Down

0 comments on commit 98e03e8

Please sign in to comment.