INNER CODE UNIT · Python
transform
kejilion/sh · site_access_config.py:16
def transform(content):
try:
source = content.decode('utf-8')
except UnicodeDecodeError as exc:
raise ConfigError('site configuration is not UTF-8') from exc
tree = parse(source)
targets = [select_context(tree, index, scope, location, modifier) for index in server_indices]
for target in targets:
if any(d.words[0] in ('auth_basic', 'auth_basic_user_file') for d in target.directives):
raise ConfigError('a password rule already exists in this context')
for target in sorted(targets, key=lambda block: block.start, reverse=True):
source = replace_auth(source, target, realm, user_file, enforce_satisfy_all=True)
parse(source)
return source.encode('utf-8')
return replace_existing(directory, name, expected_sha256, transform, validate, reload_config,
before_exchange=assert_context)