mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add code to resolve octal integers in sls files
This commit is contained in:
parent
6dc2ca1f06
commit
75c5ea1243
1 changed files with 18 additions and 0 deletions
|
@ -22,6 +22,13 @@ class DuplicateKeyWarning(RuntimeWarning):
|
|||
warnings.simplefilter('always', category=DuplicateKeyWarning)
|
||||
|
||||
|
||||
class OctalYAMLUnt(int):
|
||||
'''
|
||||
Stub class for loading octal integers as strings
|
||||
'''
|
||||
__slots__ = ()
|
||||
|
||||
|
||||
class CustomeConstructor(yaml.constructor.SafeConstructor):
|
||||
'''
|
||||
Create a custom constructor for manageging YAML
|
||||
|
@ -49,6 +56,17 @@ class CustomeConstructor(yaml.constructor.SafeConstructor):
|
|||
mapping[key] = value
|
||||
return mapping
|
||||
|
||||
def construct_yaml_int(self, node):
|
||||
'''
|
||||
Detect if an integer is octal and return a string for non explicit
|
||||
octal declarations
|
||||
'''
|
||||
rv_ = SafeConstructor.construct_yaml_int(self, node)
|
||||
sval = str(self.construct_scalar(node))
|
||||
if sval.startswith('0') and not sval.startswith(('0b', '0x')):
|
||||
rv_ = OctalYAMLInt(rv_)
|
||||
return rv_
|
||||
|
||||
|
||||
class CustomLoader(yaml.reader.Reader, yaml.scanner.Scanner, yaml.parser.Parser,
|
||||
yaml.composer.Composer, CustomeConstructor, yaml.resolver.Resolver):
|
||||
|
|
Loading…
Add table
Reference in a new issue