<commit_before>#!/usr/bin/python3

import sys
import re

from signal import signal, SIGPIPE, SIG_DFL
from vyos.configtree import ConfigTree

signal(SIGPIPE,SIG_DFL)


config_string = sys.stdin.read().strip()

if not config_string:
    sys.exit(0)

# When used in conf mode pipe, the config given to the script is likely incomplete
# and breaks the "all top level nodes are neither tag nor leaf"
# invariant, so we wrap it into a fake node.
# Since nodes don't normally start with an underscore,
# __root__ is hygienic enough.
config_string = "__root__ {{ {0} \n }}".format(config_string)

config_re = re.compile("(set|comment)\s+__root__\s+(.*)")

config = ConfigTree(config_string)
commands = config.to_commands()
commands = config_re.sub("\\1 \\2", commands)

print(commands)
<commit_msg>src: commands-pipe: fix bug (no raw string) reported by sonarcube<commit_after>#!/usr/bin/python3

import sys
import re

from signal import signal, SIGPIPE, SIG_DFL
from vyos.configtree import ConfigTree

signal(SIGPIPE,SIG_DFL)

config_string = sys.stdin.read().strip()

if not config_string:
    sys.exit(0)

# When used in conf mode pipe, the config given to the script is likely incomplete
# and breaks the "all top level nodes are neither tag nor leaf"
# invariant, so we wrap it into a fake node.
# Since nodes don't normally start with an underscore,
# __root__ is hygienic enough.
config_string = "__root__ {{ {0} \n }}".format(config_string)

config_re = re.compile(r'(set|comment)\s+__root__\s+(.*)')

config = ConfigTree(config_string)
commands = config.to_commands()
commands = config_re.sub("\\1 \\2", commands)

print(commands)

{'fraction_non_alphanumeric': 0.11213235294117647, 'fraction_numerical': 0.006127450980392157, 'mean_word_length': 4.874100719424461, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3489600', 'n_tokens_mistral': 538, 'n_tokens_neox': 532, 'n_words': 181}