当前位置: 首页>>代码示例>>Python>>正文


Python yaml.YAMLObject方法代码示例

本文整理汇总了Python中yaml.YAMLObject方法的典型用法代码示例。如果您正苦于以下问题:Python yaml.YAMLObject方法的具体用法?Python yaml.YAMLObject怎么用?Python yaml.YAMLObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yaml的用法示例。


在下文中一共展示了yaml.YAMLObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_help_desc

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import YAMLObject [as 别名]
def get_help_desc(self, module, summary=False):
        self.logger.debug("Getting info on module '"+module.__name__+"'")
        elements = inspect.getmembers(module, lambda l : inspect.isclass(l) and yaml.YAMLObject in inspect.getmro(l))
        desc={}
        for element in elements:
            self.logger.debug("Getting doc of "+element[0])
            # Gets the documentation of the first superclass
            superclass = inspect.getmro(element[1])[1]
            fulldoc=superclass.__doc__

            # Add the doc of the super-super-class if _element_doc is
            if hasattr(inspect.getmro(superclass)[1], "_element_doc") and inspect.getmro(superclass)[1].__doc__  is not None:
                fulldoc = fulldoc + inspect.getmro(superclass)[1].__doc__

            firstline=fulldoc.split(".")[0]
            self.logger.debug(firstline)

            module_name = module.__name__.split('.')[-1]

            if summary:
                desc[element[1].yaml_tag] = [ firstline, module_name ]
            else:
                desc[element[1].yaml_tag] = [ fulldoc, module_name ]
        return desc 
开发者ID:wfrog,项目名称:wfrog,代码行数:26,代码来源:config.py

示例2: test_load_cfg_invalid_type

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import YAMLObject [as 别名]
def test_load_cfg_invalid_type(self):
        class CustomClass(yaml.YAMLObject):
            """A custom class that yaml.safe_load can load."""

            yaml_loader = yaml.SafeLoader
            yaml_tag = u"!CustomClass"

        # FOO.BAR.QUUX will have type CustomClass, which is not allowed
        cfg_string = "FOO:\n BAR:\n  QUUX: !CustomClass {}"
        with self.assertRaises(AssertionError):
            yacs.config.load_cfg(cfg_string) 
开发者ID:rbgirshick,项目名称:yacs,代码行数:13,代码来源:tests.py

示例3: to_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import YAMLObject [as 别名]
def to_yaml(cls, dumper, vividict):
        """Implementation for the abstract method of the base class YAMLObject
        """
        dictionary = cls.vividict_to_dict(vividict, native_strings=True)
        node = dumper.represent_mapping(cls.yaml_tag, dictionary)
        return node 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:8,代码来源:vividict.py

示例4: from_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import YAMLObject [as 别名]
def from_yaml(cls, loader, node):
        """Implementation for the abstract method of the base class YAMLObject
        """
        dict_representation = loader.construct_mapping(node, deep=True)
        vividict = cls.from_dict(dict_representation)
        return vividict 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:8,代码来源:vividict.py

示例5: __new__

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import YAMLObject [as 别名]
def __new__(cls):
        res = yaml.YAMLObject.__new__(cls)
        setattr(res, 'key', 'Menu_Proxy')
        setattr(res, 'label', '')
        setattr(res, 'items', [])
        setattr(res, 'after', None)
        setattr(res, 'options', {})
        setattr(res, 'preMenuCommand', None)
        setattr(res, 'postMenuCommand', '')
        return res 
开发者ID:theodox,项目名称:mGui,代码行数:12,代码来源:menu_loader.py

示例6: setup_settings

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import YAMLObject [as 别名]
def setup_settings(self, settings_def_file, source_file, target_file):
        self.logger.debug('Current settings file: '+str(source_file))
        self.logger.debug('New settings file:'+target_file)
        defs = yaml.load( file(settings_def_file, 'r') )
        if source_file is not None:
            source = yaml.load( file(source_file, 'r') )
        else:
            source = {}
        target = {}
        try:
            os.makedirs(os.path.dirname(target_file))
        except:
            pass
            
        # First question is about the station
        section = {}
        section['name'] = "station"
        section['description'] = "Station information"
        section['type'] = 'dict'
        question = {}
        question['name'] = "driver"
        question['description'] = "the driver for your station model"
        question['type'] = 'choice'
        question['default'] = 'none'
        question['choices'] = {}
        section['children'] =[question]
        
        stations = inspect.getmembers(wfdriver.station, lambda l : inspect.isclass(l) and yaml.YAMLObject in inspect.getmro(l))
        for station in stations:
            station_class = station[1]
            if hasattr(station_class,('name')):
                question['choices'][str(station_class.yaml_tag)[1:]] = station_class.name
        
        defs.insert(0,section)        
            
        self.welcome(target_file)
        self.recurse_create(defs, source, target)
        yaml.dump(target, file(target_file, 'w'), default_flow_style=False)
        self.bye()
        return target_file 
开发者ID:wfrog,项目名称:wfrog,代码行数:42,代码来源:setup.py


注:本文中的yaml.YAMLObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。