Files
computer-playbook/plugins/filter/dotenv.py
T
kevinveenbirkenbachandClaude Opus 4.7 4c2ce5cc40 chore(plugins): drop stale path-style file header comments
Removed leading `# filter_plugins/...py` / `# lookup_plugins/...py`
comments that referenced the old plugin paths. The plugins now live
under plugins/filter and plugins/lookup, so these headers are both
inaccurate and redundant.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 12:05:45 +02:00

38 lines
850 B
Python

# Dotenv-safe quoting for .env files.
#
# Rules:
# - Always use double quotes
# - Escape backslash and double quote
# - Do NOT do shell-style escaping
#
# Result is safe for:
# - compose --env-file
# - dotenv libraries (PHP, Ruby, Node, Python)
# - passwords containing ', $, spaces, !
#
from __future__ import annotations
class FilterModule:
def filters(self):
return {
"dotenv_quote": self.dotenv_quote,
}
@staticmethod
def dotenv_quote(value):
if value is None:
return '""'
s = str(value)
# Escape for compose env interpolation:
# $VAR would be expanded; $$ becomes literal $
s = s.replace("$", "$$")
# Escape backslash first, then double quotes
s = s.replace("\\", "\\\\")
s = s.replace('"', '\\"')
return f'"{s}"'