python类org()的实例源码

base_entity.py 文件源码 项目:v20-python 作者: oanda 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def yaml(self, verbose=False):
        yaml.SafeDumper.add_representer(
            OrderedDict,
            lambda dumper, value: represent_odict(
                dumper, u'tag:yaml.org,2002:map', value
            )
        )

        return yaml.safe_dump(
            self.ordered_dict(verbose=verbose),
            default_flow_style=False,
            indent=2
        ).strip()
editor.py 文件源码 项目:holo 作者: TheEnigmaBlade 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def represent_ordereddict(dumper, data):
    value = []
    for item_key, item_value in data.items():
        node_key = dumper.represent_data(item_key)
        node_value = dumper.represent_data(item_value)
        value.append((node_key, node_value))
    return yaml.nodes.MappingNode("tag:yaml.org,2002:map", value)
confit.py 文件源码 项目:flinck 作者: Kraymer 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def represent_bool(self, data):
        """Represent bool as 'yes' or 'no' instead of 'true' or 'false'.
        """
        if data:
            value = u'yes'
        else:
            value = u'no'
        return self.represent_scalar('tag:yaml.org,2002:bool', value)
confit.py 文件源码 项目:flinck 作者: Kraymer 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def represent_none(self, data):
        """Represent a None value with nothing instead of 'none'.
        """
        return self.represent_scalar('tag:yaml.org,2002:null', '')
readers.py 文件源码 项目:central 作者: viniciuschiele 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __init__(self):
        if not toml:
            raise LibraryRequiredError('toml', 'https://pypi.python.org/pypi/toml')
readers.py 文件源码 项目:central 作者: viniciuschiele 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self):
        if not yaml:
            raise LibraryRequiredError('PyYAML', 'https://pypi.python.org/pypi/PyYAML')
__init__.py 文件源码 项目:review-rot 作者: nirzari 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def load_ordered_config(config_path):
    """
      Loads the configuration in the same order as it's defined in yaml file,
      so that, while saving it in new format, order is maintained
      Args:
            config_path (str): Path to the configuration file
      Returns:
            config(dict): Returns the configurations in the defined ordered
    """

    #  To load data from yaml in ordered dict format
    _mapping_tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG

    def dict_representer(dumper, data):
        return dumper.represent_mapping(_mapping_tag, data.iteritems())

    def dict_constructor(loader, node):
        return collections.OrderedDict(loader.construct_pairs(node))

    yaml.add_representer(collections.OrderedDict, dict_representer)
    yaml.add_constructor(_mapping_tag, dict_constructor)

    #  format the output to print a blank scalar rather than null
    def represent_none(self, _):
        return self.represent_scalar('tag:yaml.org,2002:null', u'')

    yaml.add_representer(type(None), represent_none)

    # read input from home directory for pull requests
    with open(config_path, 'r') as f:
        config = yaml.load(f)
    return config
generate_specs.py 文件源码 项目:analytics-platform-ops 作者: ministryofjustice 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def multiline_str_representer(dumper, data):
    style = None
    if len(data.splitlines()) > 1:
        style = '|'
    return dumper.represent_scalar('tag:yaml.org,2002:str', data, style=style)
__init__.py 文件源码 项目:analytics-platform-ops 作者: ministryofjustice 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def represent_odict(dumper, data):
        value = list()
        node = yaml.nodes.MappingNode(
            'tag:yaml.org,2002:map', value, flow_style=None )
        if dumper.alias_key is not None:
            dumper.represented_objects[dumper.alias_key] = node
        for item_key, item_value in data.items():
            node_key = dumper.represent_data(item_key)
            node_value = dumper.represent_data(item_value)
            value.append((node_key, node_value))
        node.flow_style = False
        return node
schema.py 文件源码 项目:airflow-declarative 作者: rambler-digital-solutions 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def represent_timedelta(self, delta):
        seconds = delta.seconds
        if not seconds:
            value = '%dd' % delta.days
        elif seconds % 86400 == 0:
            value = '%dd' % (seconds / 86400)
        elif seconds % 3600 == 0:
            value = '%dh' % (seconds / 3600)
        elif seconds % 60 == 0:
            value = '%dm' % (seconds / 60)
        else:
            value = '%ds' % seconds
        return self.represent_scalar('tag:yaml.org,2002:str', value)
schema.py 文件源码 项目:airflow-declarative 作者: rambler-digital-solutions 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def represent_callable(self, obj):
        value = '%s:%s' % (obj.__module__, obj.__name__)
        return self.represent_scalar('tag:yaml.org,2002:str', value)
pyyaml.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def represent_decimal(self, data):
        return self.represent_scalar('tag:yaml.org,2002:str', str(data))
pyyaml.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def represent_ordered_dict(self, data):
        return self.represent_mapping('tag:yaml.org,2002:map', data.items())
yml_utils.py 文件源码 项目:acspec 作者: retresco 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def str_node_representer(dumper, str_node):
    node = yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=str(str_node))
    return node
yml_utils.py 文件源码 项目:acspec 作者: retresco 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def dict_node_representer(dumper, dict_node):
    items = dict_node.items()
    items = sorted(items, key=lambda x: x[0])
    return dumper.represent_mapping('tag:yaml.org,2002:map', items)
yml_utils.py 文件源码 项目:acspec 作者: retresco 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def list_node_representer(dumper, list_node):
    items = sorted(list_node)
    return dumper.represent_mapping('tag:yaml.org,2002:seq', items)
yaml_ordered_dict.py 文件源码 项目:env-switcher-gui 作者: smarie 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def represent_ordereddict(dumper, data):
    value = []

    for item_key, item_value in data.items():
        node_key = dumper.represent_data(item_key)
        node_value = dumper.represent_data(item_value)

        value.append((node_key, node_value))

    return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', value)

# make ordered dicts dump as normal dicts
yaml_ordered_dict.py 文件源码 项目:env-switcher-gui 作者: smarie 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
        yaml.SafeLoader.__init__(self, *args, **kwargs)

        self.add_constructor(u'tag:yaml.org,2002:map', type(self).construct_yaml_map)
        self.add_constructor(u'tag:yaml.org,2002:omap', type(self).construct_yaml_map)
pyyaml.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def represent_decimal(self, data):
        return self.represent_scalar('tag:yaml.org,2002:str', str(data))
yaml_ordered_dict.py 文件源码 项目:alquist 作者: AlquistManager 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
        yaml.Loader.__init__(self, *args, **kwargs)

        self.add_constructor(u'tag:yaml.org,2002:map', type(self).construct_yaml_map)
        self.add_constructor(u'tag:yaml.org,2002:omap', type(self).construct_yaml_map)


问题


面经


文章

微信
公众号

扫码关注公众号