當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。