Completed
Push — develop ( 86b58f...0a86d2 )
by Jace
03:19
created

yorm/types/_representers.py (1 issue)

1
"""Custom YAML representers."""
2
3 1
from collections import OrderedDict
4
5 1
import yaml
0 ignored issues
show
The import yaml could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
6
7
8 1
class LiteralString(str):
9
    """Custom type for strings which should be dumped in the literal style."""
10
11
12 1
def represent_none(self, _):
13 1
    return self.represent_scalar('tag:yaml.org,2002:null', '')
14
15
16 1
def represent_literalstring(dumper, data):
17 1
    return dumper.represent_scalar('tag:yaml.org,2002:str', data,
18
                                   style='|' if data else '')
19
20
21 1
def represent_ordereddict(dumper, data):
22 1
    value = []
23
24 1
    for item_key, item_value in data.items():
25 1
        node_key = dumper.represent_data(item_key)
26 1
        node_value = dumper.represent_data(item_value)
27
28 1
        value.append((node_key, node_value))
29
30 1
    return yaml.nodes.MappingNode('tag:yaml.org,2002:map', value)
31
32
33 1
yaml.add_representer(LiteralString, represent_literalstring)
34 1
yaml.add_representer(OrderedDict, represent_ordereddict)
35
yaml.add_representer(type(None), represent_none)
36