| Server IP : 199.250.200.62 / Your IP : 216.73.216.15 Web Server : Apache System : Linux vps37394.inmotionhosting.com 3.10.0-1160.119.1.vz7.224.4 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : jasonp18 ( 1000) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/cwd/proc/2/cwd/proc/self/root/opt/imh-python/lib/python3.9/site-packages/rads/ |
Upload File : |
"""Helpers for yaml parsing"""
import yaml
class DumbYamlConstructor(yaml.constructor.SafeConstructor):
"""Subclass of SafeYamlConstructor that leaves bool/null/int as strs"""
ignored_tags = [
'tag:yaml.org,2002:bool',
'tag:yaml.org,2002:null',
'tag:yaml.org,2002:int',
]
def __init__(self):
super().__init__()
for tag in self.ignored_tags:
self.add_constructor(tag, DumbYamlConstructor.return_unchanged)
def return_unchanged(self, node):
"""Handler for scalars that shouldn't be converted"""
return self.construct_scalar(node)
class DumbYamlLoader(
yaml.reader.Reader,
yaml.scanner.Scanner,
yaml.parser.Parser,
yaml.composer.Composer,
DumbYamlConstructor,
yaml.resolver.Resolver,
):
"""Custom YAML loader that leaves bool/null/int as strs, for use
parsing cPanel's /etc/ YAML files
Example:
yaml.load(file_handle, rads.DumbYamlLoader)
"""
__module__ = 'rads'
def __init__(self, stream):
yaml.reader.Reader.__init__(self, stream)
yaml.scanner.Scanner.__init__(self)
yaml.parser.Parser.__init__(self)
yaml.composer.Composer.__init__(self)
DumbYamlConstructor.__init__(self)
yaml.resolver.Resolver.__init__(self)