mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #6141 from s0undt3ch/hotfix/pylint-salt.utils.jinja
Fix pylint issues regarding `salt.utils.jinja`
This commit is contained in:
commit
7c61db7260
@ -24,6 +24,7 @@ __all__ = [
|
||||
'SerializerExtension'
|
||||
]
|
||||
|
||||
|
||||
class SaltCacheLoader(BaseLoader):
|
||||
'''
|
||||
A special jinja Template Loader for salt.
|
||||
@ -98,7 +99,7 @@ class SaltCacheLoader(BaseLoader):
|
||||
|
||||
|
||||
class SerializerExtension(Extension):
|
||||
"""
|
||||
'''
|
||||
Serializes variables.
|
||||
|
||||
For example, this dataset:
|
||||
@ -106,10 +107,10 @@ class SerializerExtension(Extension):
|
||||
.. code-block:: python
|
||||
|
||||
data = {
|
||||
"foo": True,
|
||||
"bar": 42,
|
||||
"baz": [1, 2, 3],
|
||||
"qux": 2.0
|
||||
'foo': True,
|
||||
'bar': 42,
|
||||
'baz': [1, 2, 3],
|
||||
'qux': 2.0
|
||||
}
|
||||
|
||||
.. code-block:: jinja
|
||||
@ -122,18 +123,25 @@ class SerializerExtension(Extension):
|
||||
yaml = {bar: 42, baz: [1, 2, 3], foo: true, qux: 2.0}
|
||||
json = {"baz": [1, 2, 3], "foo": true, "bar": 42, "qux": 2.0}
|
||||
|
||||
"""
|
||||
'''
|
||||
|
||||
def __init__(self, environment):
|
||||
self.environment = environment
|
||||
environment.filters.update({
|
||||
super(SerializerExtension, self).__init__(environment)
|
||||
self.environment.filters.update({
|
||||
'yaml': partial(self.format, formatter='yaml'),
|
||||
'json': partial(self.format, formatter='json')
|
||||
})
|
||||
|
||||
def format(self, value, formatter, *args, **kwargs):
|
||||
if formatter == "json":
|
||||
if formatter == 'json':
|
||||
return Markup(json.dumps(value, sort_keys=True))
|
||||
elif formatter == "yaml":
|
||||
elif formatter == 'yaml':
|
||||
return Markup(yaml.dump(value, default_flow_style=True))
|
||||
raise ValueError("Serializer {} is not implemented".format(formatter))
|
||||
raise ValueError('Serializer {0} is not implemented'.format(formatter))
|
||||
|
||||
def parse(self, parser):
|
||||
'''
|
||||
If called this method would throw ``NotImplementedError``.
|
||||
While we don't need to implement this method, we override it so pylint
|
||||
does not complain about an abstract method not implemented
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user