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


Python xmlbuilder.XMLBuilder类代码示例

本文整理汇总了Python中xmlbuilder.XMLBuilder的典型用法代码示例。如果您正苦于以下问题:Python XMLBuilder类的具体用法?Python XMLBuilder怎么用?Python XMLBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: makeXML

    def makeXML(cls, name, memory, vcpu, *devices):
        
        if cls.domain_type is None:
            raise libvirt.libvirtError("%r can't be instanciated - no domain type" \
                                % cls)
            
        
        cfg = DomainConfig(name, memory, vcpu, devices)
        
        root = XMLBuilder('domain', type=cls.domain_type)

        cls.commonFields(root, cfg)
                    
        with root.os:
            cls.generateOS(root, cfg)
        
        root.clock(sync='localtime')
        
        cls.powerFeatures(root, cfg)
        
        with root.devices:
            cls.emulator(root, cfg)
            
            for dev in devices: 
                dev.toxml(root)
            
            cls.commonDevices(root, cfg)

        return root
开发者ID:koder-ua,项目名称:vm_ut,代码行数:29,代码来源:connection.py

示例2: pipeline_to_xml

def pipeline_to_xml(p):
    """ Convert a Pipeline to XML

    :type p: Pipeline
    :param p:
    :return:
    """
    root = XMLBuilder(Constants.WORKFLOW_TEMPLATE_ROOT, id=p.idx)
    with getattr(root, Constants.ENTRY_POINTS):
        for eid, bid in p.entry_bindings:
            _d = {"id": eid, "in": bid}
            getattr(root, Constants.ENTRY_POINT)(**_d)
    with getattr(root, Constants.BINDINGS):
        for bout, bin_ in p.bindings:
            _d = {"out": bout, "in": bin_}
            getattr(root, Constants.BINDING)(**_d)

    # Engine level Options
    # for completeness write this element
    getattr(root, "options")

    # Task Options
    with getattr(root, "task-options"):
        for key, value in p.task_options.iteritems():
            _d = {"id": key}
            with getattr(root, 'option')(**_d):
                root.value(str(value))

    return root
开发者ID:pb-cdunn,项目名称:pbsmrtpipe,代码行数:29,代码来源:pb_io.py

示例3: _generate_xml

 def _generate_xml(self, exception,message = ""):
     _,_,trace = sys.exc_info()
     
     xml = XMLBuilder()
     
     tb_dict = {}
     tb = traceback.extract_tb(trace)
     
     with xml.notice(version = 2.0):
         xml << ('api-key', self.environment.api_key)
         with xml.notifier:
             xml << ('name', self.environment.name)
             xml << ('version', self.environment.version)
             xml << ('url', self.environment.url)
         with xml('server-environment'):
             xml << ('environment-name', self.environment.environment_name)
         with xml.error:
             xml << ('class', exception.__class__.__name__)
             if message == "":
                 xml << ('message', str(exception))
             else:
                 xml << ('message', str(exception) + '\n\n' + message)
             with xml.backtrace:
                 for trace in tb:
                     tb_dict['filename'] = trace[0]
                     tb_dict['line_number'] = trace[1]
                     tb_dict['function_name'] = trace[2]
                     xml << ('line', {
                         'file':tb_dict.get('filename', 'unknown'),
                         'number':tb_dict.get('line_number', 'unknown'),
                         'method':tb_dict.get('function_name', 'unknown')
                     })
             
     return str(xml)
开发者ID:someones,项目名称:Pytoad,代码行数:34,代码来源:connection.py

示例4: to_xml

    def to_xml(self):
        """Return an XML instance of the suite"""

        x = XMLBuilder('testsuite', name=self.name, tests=str(self.ntests), errors=str(self.nerrors), failures=str(self.nfailure), skip=str(self.nskipped))

        for test_case in self.tests:
            classname = test_case.classname
            # sanitize for XML
            text = "" if test_case.text is None else test_case.text
            etype = "" if test_case.etype is None else test_case.etype

            with x.testcase(classname=classname, name=test_case.name,
                            result=test_case.result, etype=etype,
                            text=text):

                if test_case.result == 'failures':
                    x.error(type=test_case.etype, message=test_case.message)
                elif test_case.result == 'failure':
                    x.failure(type=test_case.etype, message=test_case.message)
                elif test_case.result == 'skipped':
                    x.skipped(type=test_case.etype, message=test_case.message)
                elif test_case.result == 'error':
                    x.error(type=test_case.etype, message=test_case.message)
                else:
                    # Successful testcase
                    pass
        return x
开发者ID:bnbowman,项目名称:pbsmrtpipe,代码行数:27,代码来源:xunit.py

示例5: checkstyle_xml

def checkstyle_xml(diags_set):

    def converted_severity(fauxpas_severity):
        # checkstyle severities: ignore, info, warning, error
        if (9 <= fauxpas_severity):
            return 'error'
        elif (5 <= fauxpas_severity):
            return 'warning'
        return 'info'

    x = XMLBuilder('checkstyle')
    diags_by_file = diags_set.grouped_diagnostics(by_property='file')
    for filepath, diags in diags_by_file.items():
        with x.file(name=filepath or diags_set.pbxproj_path):
            for diag in diags:
                message = diag.info
                if 0 < len(message):
                    message += ' '
                message += '(%s - %s)' % (diag.ruleName, diag.ruleDescription)
                x.error(severity=converted_severity(diag.severity),
                        source=diag.ruleShortName,
                        message=message,
                        line=str(diag.extent.start.line),
                        column=str(diag.extent.start.utf16Column)
                        )
    return str(x)
开发者ID:mapedd,项目名称:fauxpas-converter,代码行数:26,代码来源:fauxpas_convert.py

示例6: testWith

 def testWith(self):
     xml = XMLBuilder()
     with xml.root(lenght = 12):
         pass
     self.assertEqual(str(xml),'<root lenght="12" />')
     
     xml = XMLBuilder()
     with xml.root():
         xml << "text1" << "text2" << ('some_node',)
     self.assertEqual(str(xml),"<root>text1text2<some_node /></root>")
开发者ID:aquila,项目名称:sfa,代码行数:10,代码来源:__init__.py

示例7: build_snapshot_xml

 def build_snapshot_xml(self, name=None, description=None):
     """
     :rtype : String
     :type name: String
     :type description: String
     """
     xml_builder = XMLBuilder('domainsnapshot')
     if not (name is None):
         xml_builder.name(name)
     if not (description is None):
         xml_builder.description(description)
     return str(xml_builder)
开发者ID:korshenin,项目名称:devops,代码行数:12,代码来源:libvirt_xml_builder.py

示例8: tree_to_xml

def tree_to_xml(root):
    xml = XMLBuilder('map', version='0.9.0')
 
    def rec_tree(tree, xnode):
        if tree == {}:
            return
        xnode['folded'] = 'true'
        for key, subtree in tree.iteritems():
            rec_tree(subtree, xnode.node(text=key))
    xroot = xml.node(text='Categories')
    rec_tree(root, xroot)
    xroot['folded'] = 'false'
    return str(xml)
开发者ID:mojolab,项目名称:livingdata,代码行数:13,代码来源:livdatfreemind.py

示例9: testFormat

 def testFormat(self):
     x = XMLBuilder('utf-8',format = True)
     with x.root():
         x << ('array',)
         with x.array(len = 10):
             with x.el(val = 0):
                 pass
             with x.el('xyz',val = 1):
                 pass
             x << ("el","abc",{'val':2}) << ('el',dict(val=3))
             x << ('el',dict(val=4)) << ('el',dict(val='5'))
             with x('sup-el',val = 23):
                 x << "test  "
     self.assertEqual(str(x),result1)
开发者ID:aquila,项目名称:sfa,代码行数:14,代码来源:__init__.py

示例10: schema_options_to_xml

def schema_options_to_xml(option_type_name, schema_options_d):
    """Option type name is the task-option or option"""

    x = XMLBuilder(Constants.WORKFLOW_TEMPLATE_PRESET_ROOT)

    # Need to do this getattr to get around how the API works
    with getattr(x, option_type_name):
        for option_id, schema in schema_options_d.iteritems():
            default_value = schema["properties"][option_id]["default"]
            if default_value is not None:
                with x.option(id=option_id):
                    default_value = schema["properties"][option_id]["default"]
                    x.value(str(default_value))

    return x
开发者ID:skinner,项目名称:pbsmrtpipe,代码行数:15,代码来源:pb_io.py

示例11: toxml

    def toxml(self, hrn = None):
        xml = XMLBuilder(format = True, tab_step = "  ")
        with xml.RSpec(type="VINI"):
            if hrn:
                element = xml.network(name="Public_VINI", slice=hrn)
            else:
                element = xml.network(name="Public_VINI")
                
            with element:
                for site in self.getSites():
                    site.toxml(xml, hrn, self.nodes)
                for link in self.sitelinks:
                    link.toxml(xml)

        header = '<?xml version="1.0"?>\n'
        return header + str(xml)
开发者ID:planetlab,项目名称:sfa,代码行数:16,代码来源:utils.py

示例12: toxml

    def toxml(self):
        xml = XMLBuilder(format = True, tab_step = "  ")
        with xml.RSpec(type=self.type):
            if self.slice:
                element = xml.network(name=self.api.hrn, slice=self.slice.hrn)
            else:
                element = xml.network(name=self.api.hrn)

            with element:
                if self.slice:
                    self.slice.toxml(xml)
                for site in self.getSites():
                    site.toxml(xml)
                for link in self.sitelinks:
                    link.toxml(xml)

        header = '<?xml version="1.0"?>\n'
        return header + str(xml)
开发者ID:planetlab,项目名称:sfa,代码行数:18,代码来源:vini_network.py

示例13: toxml

    def toxml(self):
        """
        Produce XML directly from the topology specification.
        """
        xml = XMLBuilder(format = True, tab_step = "  ")
        with xml.RSpec(type=self.type):
            if self.slice:
                element = xml.network(name=self.api.hrn, slice=self.slice.hrn)
            else:
                element = xml.network(name=self.api.hrn)
                
            with element:
                if self.slice:
                    self.slice.toxml(xml)
                for site in self.getSites():
                    site.toxml(xml)

        header = '<?xml version="1.0"?>\n'
        return header + str(xml)
开发者ID:planetlab,项目名称:sfa,代码行数:19,代码来源:network.py

示例14: export_to_xml

def export_to_xml(people, questions_to_export, user_id, can_view_email):
    response = HttpResponse(content_type = "application/xml")
    response['Content-Disposition'] = 'attachment; filename="sc4g-people.xml"'
    xml = XMLBuilder('volunteers')
    for person in people:
        with xml.volunteer:
            xml.firstName(person.user.first_name)
            xml.lastName(person.user.last_name)
            if (can_view_email):
                xml.email(person.user.email)
            with xml.form_responses:
                for key, value in get_card_fields_with_icons_together(person, user_id).items():
                    xml.form_response(value, question=key)

    response.content = str(xml)
    return response
开发者ID:JakubBielecki,项目名称:oh-mainline,代码行数:16,代码来源:views.py

示例15: create_snapshot

    def create_snapshot(self, domain, snapshot_name, \
                        snapshot_description):
        """Create VM snapshot
           connection: object with a connection to the Hypervisor
           domain: VM name
           snapshot_name
           snapshot_description
        """
        try:
            libvirt_domain = self.libvirt_connection.lookupByName(domain)
            xml_base = XMLBuilder('domainsnapshot')
            xml_base.name(snapshot_name)
            xml_base.description(snapshot_description)
            xml = str(xml_base)
            libvirt_domain.snapshotCreateXML(xml)
        except:
            print 'Unable to create snapshot'
            sys.exit(1)

        print 'Snapshot has been created successfully.'
开发者ID:tlzr,项目名称:vm-tools,代码行数:20,代码来源:create_snapshot.py


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