本文整理汇总了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
示例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)
示例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
示例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
示例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
示例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