MCPcopy
hub / github.com/qazbnm456/awesome-web-security / yaml_str

Function yaml_str

scripts/migrate.py:98–113  ·  view source on GitHub ↗

Emit a YAML scalar for str/None/bool.

(s)

Source from the content-addressed store, hash-verified

96# ---------------------------------------------------------------------------
97
98def yaml_str(s):
99 """Emit a YAML scalar for str/None/bool."""
100 if s is None:
101 return "null"
102 if isinstance(s, bool):
103 return "true" if s else "false"
104 s = str(s)
105 if s == "":
106 return '""'
107 # quote if contains any YAML special / leading-whitespace / starts-with-digit
108 if (re.search(r'[:#\n"\'{}\[\],&*?|<>=!%@`\\]&#x27;, s)
109 or s != s.strip()
110 or s.lower() in ("null", "true", "false", "yes", "no", "on", "off", "~")
111 or re.match(r'^[\-+\d]', s)):
112 return json.dumps(s, ensure_ascii=False)
113 return s
114
115
116def slugify(text: str, max_len: int = 60) -> str:

Callers 3

to_yamlMethod · 0.85
write_categoriesFunction · 0.85
write_entriesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected