コード例 #1
0
 def test_scan(self):
     #doc1 for only one txt file. 
     doc1 = amara.parse(self.parser1.scan().xml())
     #doc2 for all other 14 types of files. It also included two types of cmd files.
     doc2 = amara.parse(self.parser2.scan().xml())
     
     # doc1's test verifies all the information the xml comment provides.
     self.assertEquals(doc1.commentLog.branchInfo.originator, "sanummel")
     self.assertEquals(doc1.commentLog.branchInfo.category, "")
     self.assertEquals(doc1.commentLog.branchInfo.since, "07-03-22")
     self.assertEquals(doc1.commentLog.branchInfo.file, os.environ['TEST_DATA'] + '/data/comments_test.txt')
     self.assertEquals(doc1.commentLog.branchInfo.error, "kkk")
     self.assertEquals(str(doc1.commentLog.branchInfo).strip(),"Add rofsfiles for usage in paged images")
     # s = (str(doc1.commentLog.xml()))
     # print s
     # doc2's test only verifies the main comment content.
     self.assertEquals(str(doc2.commentLog.branchInfo[0]).strip(), "We need TwistOpen and TwistClose to cause display to change between\n landscape and portrait, but SysAp is consuming the key events.  Try\n treating them as Flip events are handled already by SysAp.")
     self.assertEquals(str(doc2.commentLog.branchInfo[1]).strip(), "Testing if it's good~~~")
     self.assertEquals(str(doc2.commentLog.branchInfo[2]).strip(), "We need TwistOpen and TwistClose to cause display to change between\n landscape and portrait, but SysAp is consuming the key events.  Try\n treating them as Flip events are handled already by SysAp.")
     self.assertEquals(str(doc2.commentLog.branchInfo[3]).strip(), "puikko ME SCD DeSW: wk21 Flag fix")
     self.assertEquals(str(doc2.commentLog.branchInfo[4]).strip(), "Since Catalogs is not compiling at this point, and we are not building it, don't try to\n pull it into the rom.  Also, tfxserver is crashing, so don't build or pull it in either.")
     self.assertEquals(str(doc2.commentLog.branchInfo[5]).strip(), "Fix target export, which cause issue when cleanexport.")
     self.assertEquals(str(doc2.commentLog.branchInfo[6]).strip(), "Move command to makmake as EBS does not call abld build")
     self.assertEquals(str(doc2.commentLog.branchInfo[7]).strip(), "Activate PCFW for Screensaver")
     self.assertEquals(str(doc2.commentLog.branchInfo[8]).strip(), "Support SPP mechanism for flags support.")
     self.assertEquals(str(doc2.commentLog.branchInfo[9]).strip(), "Enabling all the HWRM light zones target for product")
     self.assertEquals(str(doc2.commentLog.branchInfo[10]).strip(), "Again, it is just a test")
     self.assertEquals(str(doc2.commentLog.branchInfo[11]).strip(), "Test info, so whatever~")
     self.assertEquals(str(doc2.commentLog.branchInfo[12]).strip(), "k")
     self.assertEquals(str(doc2.commentLog.branchInfo[13]).strip(), "")
コード例 #2
0
def test_attr_setnode4():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="1"/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    doc2 = parse('<a xmlns:ns="urn:bogus:x"/>')
    attr_x = doc.xml_first_child.xml_attributes.getnode(BOGUS_X_NS, u'x')
    doc2.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc2.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #3
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode4():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="1"/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    doc2 = parse('<a xmlns:ns="urn:bogus:x"/>')
    attr_x = doc.xml_first_child.xml_attributes.getnode(BOGUS_X_NS, u'x')
    doc2.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc2.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #4
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode1():
    EXPECTED = """<a x="1"/>"""
    doc = parse('<a x="1"/>')
    doc2 = parse('<a/>')
    #x = doc.xml_first_child.xml_attributes[None, u'x']
    attr_x = doc.xml_first_child.xml_attributes.getnode(None, u'x')
    #doc.xml_first_child.xml_attributes[None, u'y'] = attr_x
    doc2.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc2.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #5
0
def test_attr_setnode1():
    EXPECTED = """<a x="1"/>"""
    doc = parse('<a x="1"/>')
    doc2 = parse('<a/>')
    #x = doc.xml_first_child.xml_attributes[None, u'x']
    attr_x = doc.xml_first_child.xml_attributes.getnode(None, u'x')
    #doc.xml_first_child.xml_attributes[None, u'y'] = attr_x
    doc2.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc2.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #6
0
def amara_parse(source, uri=None, rules=None, binderobj=None,
                prefixes=None):
    """Convenience function for parsing XML.
    
    Works just as amara.parse, except that if source is '-' then
    it reads from standard input.
    """
    if source == '-':
        return amara.parse(sys.stdin, uri=uri, rules=rules,
                           binderobj=binderobj, prefixes=prefixes)
    else:
        return amara.parse(source, uri=uri, rules=rules,
                           binderobj=binderobj, prefixes=prefixes)
コード例 #7
0
def amara_parse(source, uri=None, rules=None, binderobj=None,
                prefixes=None):
    """Convenience function for parsing XML.
    
    Works just as amara.parse, except that if source is '-' then
    it reads from standard input.
    """
    if source == '-':
        return amara.parse(sys.stdin, uri=uri, rules=rules,
                           binderobj=binderobj, prefixes=prefixes)
    else:
        return amara.parse(source, uri=uri, rules=rules,
                           binderobj=binderobj, prefixes=prefixes)
コード例 #8
0
ファイル: model.py プロジェクト: fedor4ever/linux_build
 def _capture_icd_icfs(self):
     prep_xml_path = self.config['prep.xml']
     if prep_xml_path is not None and os.path.exists(prep_xml_path):
         prep_doc = amara.parse(open(prep_xml_path,'r'))
         if hasattr(prep_doc.prepSpec, u'source'):
             for source in prep_doc.prepSpec.source:
                 if hasattr(source, u'unzipicds'):
                     for  unzipicds in source.unzipicds:
                         if hasattr(unzipicds, u'location'):
                             for location in unzipicds.location:
                                 excludes = []
                                 excluded = False
                                 if hasattr(location, 'exclude'):
                                     for exclude in location.exclude:
                                         _logger.debug('Exclude added: %s' % str(exclude.name))
                                         excludes.append(str(exclude.name))                                
                                         excluded = False
                                 path = str(location.name)                                    
                                 if os.path.exists(path):
                                     files = os.listdir(str(location.name))
                                     for file_ in files:
                                         for exclude in excludes:
                                             if file_.endswith(exclude):
                                                 excluded = True
                                         if file_.endswith('.zip') and not excluded:
                                             self._icd_icfs.append(file_)
                                             self._icd_icfs.sort(key=str)
コード例 #9
0
ファイル: test_two.py プロジェクト: abed-hawa/amara
    def test_tree(self):
        #Node types use string rather than numerical constants now
        #The root node type is called entity
        doc = amara.parse(self.MONTY_XML)

        self.assertEqual(doc.xml_type, tree.entity.xml_type)
        m = doc.xml_children[0] #xml_children is a sequence of child nodes
        self.assertEqual(m.xml_local, u'monty') #local name, i.e. without any prefix
        self.assertEqual (m.xml_qname, u'monty') #qualified name, e.g. includes prefix
        self.assertEqual(m.xml_prefix, None)
        self.assertEqual(m.xml_qname, u'monty') #qualified name, e.g. includes prefix
        self.assertEqual(m.xml_namespace, None)
        self.assertEqual(m.xml_name,  (None, u'monty')) #The "universal name" or "expanded name"
        self.assertEqual(m.xml_parent, doc)
        
        p1 = m.xml_children[1]
        XML_output = '<python spam="eggs">What do you mean "bleh"</python>'
        output = cStringIO.StringIO()
        xml_print(p1, stream=output)
        self.assertEqual(output.getvalue(), XML_output)
        
        self.assertEqual(p1.xml_attributes[(None, u'spam')], u"eggs")
        #Some manipulation
        p1.xml_attributes[(None, u'spam')] = u"greeneggs"
        self.assertEqual(p1.xml_attributes[(None, u'spam')], u"greeneggs")
        p1.xml_children[0].xml_value = u"Close to the edit"
        output = cStringIO.StringIO()
        xml_print(p1, stream=output)
        self.assertEqual(output.getvalue(),
                         '<python spam="greeneggs">Close to the edit</python>')
コード例 #10
0
ファイル: test_whatsnew.py プロジェクト: abed-hawa/amara
 def test_ids(self):
     DOC = '<!DOCTYPE xsa PUBLIC "-//LM Garshol//DTD XML Software Autoupdate 1.0//EN//XML" "http://www.garshol.priv.no/download/xsa/xsa.dtd">\n<xsa/>'
     doc = amara.parse(DOC, standalone=True)
     self.assertEqual(doc.xml_system_id, 
                      u'http://www.garshol.priv.no/download/xsa/xsa.dtd')
     self.assertEqual(doc.xml_public_id, 
                      u'-//LM Garshol//DTD XML Software Autoupdate 1.0//EN//XML')        
コード例 #11
0
ファイル: test_predicates.py プロジェクト: mredar/amara
def test_simple_attr_update3():
    import amara
    doc = amara.parse(PLACES)
    ns = doc.xml_select(
        u'/places/place[@name="Santiago, Regi\xf3n Metro De Santiago"]')
    assert len(ns) == 1, (len(ns), 1)
    ns = doc.xml_select(
        u'/places/*[@name="Santiago, Regi\xf3n Metro De Santiago"]')
    assert len(ns) == 1, (len(ns), 1)
    ns = doc.xml_select(
        u'/*/place[@name="Santiago, Regi\xf3n Metro De Santiago"]')
    assert len(ns) == 1, (len(ns), 1)
    ns = doc.xml_select(u'/*/*[@name="Santiago, Regi\xf3n Metro De Santiago"]')
    assert len(ns) == 1, (len(ns), 1)
    ns = doc.xml_select(
        u'places/place[@name="Santiago, Regi\xf3n Metro De Santiago"]')
    assert len(ns) == 1, (len(ns), 1)
    ns = doc.xml_select(
        u'places/*[@name="Santiago, Regi\xf3n Metro De Santiago"]')
    assert len(ns) == 1, (len(ns), 1)
    ns = doc.xml_select(
        u'*/place[@name="Santiago, Regi\xf3n Metro De Santiago"]')
    assert len(ns) == 1, (len(ns), 1)
    ns = doc.xml_select(u'*/*[@name="Santiago, Regi\xf3n Metro De Santiago"]')
    assert len(ns) == 1, (len(ns), 1)
    return
コード例 #12
0
def srewrite(source, **kwargs):
    doc = amara.parse(source)

    def handle_node(node, indent=0):
        empty = True
        if isinstance(node, tree.text):
            yield repr(node.xml_value)
        elif isinstance(node, tree.entity):
            yield INDENT_STR * indent + 'ROOT('
            for child in node.xml_children:
                empty = False
                yield '\n'
                for chunk in handle_node(child, indent + 1):
                    yield chunk
            yield (not empty) * INDENT_STR * indent + ')\n'
        elif isinstance(node, tree.element):
            yield INDENT_STR * indent + 'E('
            yield repr((node.xml_namespace,
                        node.xml_local)) if node.xml_namespace else repr(
                            node.xml_local)
            if node.xml_attributes:
                yield repr(dict(node.xml_attributes))
            for child in node.xml_children:
                empty = False
                yield '\n'
                for chunk in handle_node(child, indent + 1):
                    yield chunk
            yield (not empty) * INDENT_STR * indent + ')\n'

    for chunk in handle_node(doc):
        yield chunk
    return
コード例 #13
0
ファイル: test_util.py プロジェクト: abed-hawa/amara
 def test_nested_doc(self):
     'Input doc with text in nested elements'
     x = amara.parse('<a>one two <b>three four </b><c>five <d>six seven</d> eight</c> nine</a>')
     for i in range(1, 11):
         trimmed_tree = util.trim_word_count(x, i)
         word_count = len(trimmed_tree.xml_select(u'string(.)').split())
         self.assertEquals(word_count, min(i, 9))
コード例 #14
0
ファイル: test_util.py プロジェクト: abed-hawa/amara
 def test_flat_doc(self):
     'Input doc with just top-level text'
     x = amara.parse('<a>one two three four five six seven eight nine</a>')
     for i in range(1, 11):
         trimmed_tree = util.trim_word_count(x, i)
         word_count = len(trimmed_tree.xml_select(u'string(.)').split())
         self.assertEquals(word_count, min(i, 9))
コード例 #15
0
 def test_flat_doc(self):
     'Input doc with just top-level text'
     x = amara.parse('<a>one two three four five six seven eight nine</a>')
     for i in range(1, 11):
         trimmed_tree = util.trim_word_count(x, i)
         word_count = len(trimmed_tree.xml_select(u'string(.)').split())
         self.assertEquals(word_count, min(i, 9))
コード例 #16
0
    def test_bom_delta(self):
        """ Testing BOM delta creation... """
        delta = build.model.BOMDeltaXMLWriter(BOMMock(), os.path.join(os.environ['TEST_DATA'], 'data/bom/build_model_bom.xml'))
        (_, filename) = tempfile.mkstemp()
        delta.write(filename)
        xml = amara.parse(open(filename))
        self.assert_(xml.bomDelta[0].buildFrom[0] == "ido_raptor_mcl_abs_MCL.52.57")
        self.assert_(xml.bomDelta[0].buildTo[0] == "mock")

        print "baselines: ", len(xml.bomDelta.content.baseline)
        print "folders: ", len(xml.bomDelta.content.folder)
        print "tasks: ", len(xml.bomDelta.content.task)
        print "baseline[@overridden='false']:", len(xml.bomDelta.content.xml_xpath("baseline[@overridden='false']"))
        print "baseline[@overridden='true']: ", len(xml.bomDelta.content.xml_xpath("baseline[@overridden='true']"))
        print "folder[@status='deleted']: ", len(xml.bomDelta.content.xml_xpath("folder[@status='deleted']"))
        print "task[@status='deleted']: ", len(xml.bomDelta.content.xml_xpath("task[@status='deleted']"))

        self.assert_(len(xml.bomDelta.content.baseline) == 156)
        self.assert_(len(xml.bomDelta.content.folder) == 1)
        self.assert_(len(xml.bomDelta.content.task) == 1)
        self.assert_(len(xml.bomDelta.content.xml_xpath("baseline[@overridden='false']")) == 155)
        self.assert_(len(xml.bomDelta.content.xml_xpath("baseline[@overridden='true']")) == 1)

        self.assert_(len(xml.bomDelta.content.xml_xpath("folder[@status='deleted']")) == 1)

        self.assert_(len(xml.bomDelta.content.xml_xpath("task[@status='deleted']")) == 1)
コード例 #17
0
ファイル: index.py プロジェクト: dpla/akara
def simple_xpath_index(self, content, patterns):
    results = {}
    doc = content if isinstance(content, node) else amara.parse(source)
    for pname, xpath in patterns.iteritems():
        result = doc.xml_select(pattern)
        results[pname] = simplify(result)
    return results
コード例 #18
0
ファイル: test_services.py プロジェクト: mredar/akara
def test_templates():
    url = server()
    f = urlopen(url)
    tree = amara.parse(f)
    nodes = tree.xml_select("//service[@ident='urn:akara.test:template-1']")
    template = (tree.xml_select(
        "//service[@ident='urn:akara.test:template-1']/path/@template")
                [0].xml_value)
    assert template.endswith(
        "/test.template1?name={name}&language={lang?}"), template

    template = (tree.xml_select(
        "//service[@ident='urn:akara.test:template-2']/path/@template")
                [0].xml_value)
    assert template.endswith(
        "/test.template2?language={language?}&name={name}&os={os?}"), template

    nodes = (tree.xml_select(
        "//service[@ident='urn:akara.test:template-3']/path/@template"))
    assert len(nodes) == 0, nodes

    template = (tree.xml_select(
        "//service[@ident='urn:akara.test:template-4']/path/@template")
                [0].xml_value)
    assert template.endswith("/test.template4"), template
コード例 #19
0
ファイル: kekule.py プロジェクト: abed-hawa/amara
def srewrite(source, **kwargs):
    doc = amara.parse(source)
    def handle_node(node, indent=0):
        empty = True
        if isinstance(node, tree.text):
            yield repr(node.xml_value)
        elif isinstance(node, tree.entity):
            yield  INDENT_STR*indent + 'ROOT('
            for child in node.xml_children:
                empty = False
                yield '\n'
                for chunk in handle_node(child, indent+1):
                    yield chunk
            yield (not empty)*INDENT_STR*indent + ')\n'
        elif isinstance(node, tree.element):
            yield  INDENT_STR*indent + 'E('
            yield repr((node.xml_namespace, node.xml_local)) if node.xml_namespace else repr(node.xml_local)
            if node.xml_attributes:
                yield repr(dict(node.xml_attributes))
            for child in node.xml_children:
                empty = False
                yield '\n'
                for chunk in handle_node(child, indent+1):
                    yield chunk
            yield (not empty)*INDENT_STR*indent + ')\n'
    for chunk in handle_node(doc): yield chunk
    return
コード例 #20
0
    def test_iterator(self):
        doc = amara.parse(self.XML)
        output = cStringIO.StringIO()
        XML_groupby="""\
<?xml version="1.0" encoding="utf-8"?>
<env>
  <a-wrapper>
    <a id="1"/>
    <a id="2"/>
    <a id="3"/>
  </a-wrapper>
  <b-wrapper>
    <b id="1.1"/>
    <b id="2.1"/>
    <b id="3.1"/>
  </b-wrapper>
  <c-wrapper>
    <c id="1.2"/>
    <c id="2.2"/>
    <c id="3.2"/>
  </c-wrapper>
</env>"""
        leaves = sorted(doc.xml_select(u'/env/*'), key=operator.attrgetter('xml_name'))
        
        w = structwriter(indent=u"yes", stream=output)
        w.feed(
            ROOT(
                E(u'env',
                  ( E(ename + u'-wrapper',
                      ( E(ename, e.xml_attributes.copy(), e.xml_children) for e in elems )
                      ) for ename, elems in itertools.groupby(leaves, lambda x: x.xml_qname) ),
                  )
            ))
        self.assertEqual(output.getvalue(), XML_groupby)
コード例 #21
0
 def __init__(self, modelpath):
     """ Initialization. """
     doc = amara.parse(open(modelpath, 'r'))
     
     self.properties = {}
     self.required_props = []
     for property_ in doc.heliumDataModel.property:
         self.properties[str(property_.name)] = PropertyDef(property_)
                
     self.nongroupedproperties = copy.copy(self.properties)
     self.groups = {}
     for group in doc.heliumDataModel.group:
         groupobj = GroupDef(group)
         self.groups[str(group.name)] = groupobj
         
         for prop in groupobj.properties:
             groupobj.propref.append(self.properties[prop])
             if prop in self.nongroupedproperties:
                 del self.nongroupedproperties[prop]
                 
         groupobj.propref.sort()
         
         required_props_in_group = [p for p in group.propertyRef if p.usage == 'required']
         
         for required_prop in required_props_in_group:
             self.required_props.append(required_prop)
             if not self.properties.has_key(str(required_prop)):
                 raise Exception("Required property " + str(required_prop) + " is not defined!")
コード例 #22
0
ファイル: test_whatsnew.py プロジェクト: abed-hawa/amara
 def test_chardata_no_longer(self):
     doc = amara.parse('<A>Spam</A><!--eggs-->')
     A = doc.xml_children[0]
     spam = A.xml_children[0]
     for old_method in ['length', 'substringData', 'insertData', 'replaceData',
                        'appendData', 'deleteData']:
         self.assertRaises(AttributeError, getattr, spam, "%s" % old_method)
コード例 #23
0
ファイル: test_whatsnew.py プロジェクト: abed-hawa/amara
 def test_attr_no_longer(self):
     doc = amara.parse('<A a="b"/>')
     A = doc.xml_children[0]
     attr_a = A.xml_attributes.getnode(None, u'a')
     for old_method in ['nodeName', 'nodeValue', 'qualifiedName', 'value', 'namespaceURI', 
                        'localName', 'prefix', 'specified']:
         self.assertRaises(AttributeError, getattr, attr_a, "%s" % old_method)
コード例 #24
0
ファイル: test_namespaces.py プロジェクト: abed-hawa/amara
 def test_auto_xml_namespace(self):
     '''Automatic recognition of XML namespace'''
     doc = amara.parse('<a/>')
     self.assertEqual(doc.xml_first_child.xml_namespaces[u'xml'], XML_NAMESPACE)
     doc.xml_first_child.xml_attributes[XML_NAMESPACE, u'xml:base'] = u'urn:bogus'
     self.assertEqual(doc.xml_first_child.xml_attributes[XML_NAMESPACE, u'xml:base'], u'urn:bogus')
     return
コード例 #25
0
    def process_file(self, file):
        """Process a WXP file. Store results in our parser objects"""

        doc = amara.parse(file)

        items = []
        for item in doc.xml_xpath('*//item'):

            get_node = lambda x: item.xml_xpath(x).pop()

            info = _to_unicode({
                'id': get_node('wp:post_id'),
                'status': get_node('wp:status'),
                'slug': get_node('wp:post_name'),
                'title': item.title,
                'type': get_node('wp:post_type'),
                'link': item.link,
                'creator': get_node('dc:creator'),
                'pub_date': item.pubDate,
                'guid': item.guid,
                'content': get_node('content:encoded')})

            info['pub_date'] = self._parse_date(info['pub_date'])
            info['id'] = int(info['id'])

            cat_tags = item.xml_xpath('category')
            info['categories'] = self._get_categories(cat_tags)
            info['tags'] = self._get_tags(cat_tags)

            info['comments'] = self._get_comments(item)

            self.items.append(info)
コード例 #26
0
ファイル: docs.py プロジェクト: fedor4ever/linux_build
def find_python_dependencies(setpath, dbPath, dbPrj):
    """ Search python dependencies """
    for root, dirs, files in os.walk(setpath, topdown=False):
        for fname in files:
            filePattern = re.compile('.ant.xml$')
            fileMatch = filePattern.search(fname)
            modulelist = []
            if (fileMatch):
                filePath = os.path.abspath(os.path.join(root, fname))
                with open(filePath) as f:
                    filePathAmara = 'file:///'+ filePath.replace('\\','/')
                    curPrj=amara.parse(filePathAmara)
                    for line in f:
                        linePattern = re.compile('^import')
                        lineMatch = linePattern.search(line)
                        if ((lineMatch) and (line.find('.')==-1)):
                            newLine = line.replace('import','')
                            newLine = newLine.replace(',','')
                            moduleArray = newLine.split()
                            for curModule in moduleArray:
                                try:
                                    importModule = __import__(curModule)
                                    if hasattr(importModule, '__file__'):
                                        modulePath=importModule.__file__
                                        if 'helium' in modulePath:
                                            for projectList in dbPrj.antDatabase.project:
                                                if (projectList.name == curPrj.project.name):
                                                    if not (curModule in modulelist):
                                                        print " Python module : " + curModule
                                                        moduleElement = projectList.pythonDependency.xml_create_element(u'module', content=u''+curModule)
                                                        projectList.pythonDependency.xml_append(moduleElement)
                                                    modulelist = modulelist + [curModule]
                                except ImportError, e:
                                    pass
コード例 #27
0
def test_last_function_low_level():
    '''
    '''
    doc = amara.parse(XML)
    last_url = doc.xml_select(u'/listitem/para/ulink[position() = last()]/@url')
    EXPECTED = nodeset([u'http://www.ncbi.nlm.nih.gov/pubmed/16785838'])
    assert last_url == EXPECTED, (EXPECTED, last_url)
コード例 #28
0
def simple_xpath_index(self, content, patterns):
    results = {}
    doc = content if isinstance(content, node) else amara.parse(source)
    for pname, xpath in patterns.iteritems():
        result = doc.xml_select(pattern)
        results[pname] = simplify(result)
    return results
コード例 #29
0
ファイル: test_whatsnew.py プロジェクト: abed-hawa/amara
 def test_no_longer(self):
     doc = amara.parse('<A/>')
     A = doc.xml_children[0]
     for old_method in ['nodeName', 'nodeValue', 'namespaceURI', 'localName', 
                        'prefix', 'childNodes', 'isSameNode', 'xpath', 'rootNode',
                        'baseURI', 'xmlBase', 'documentURI']:
         self.assertRaises(AttributeError, getattr, A, "%s" % old_method)
コード例 #30
0
 def test_parse_with_file_path(self):
     """Parse with file path"""
     fname = tempfile.mktemp('.xml')
     fout = open(fname, 'w')
     fout.write(MONTY_XML)
     fout.close()
     doc = parse(fname)
     self.run_checks(doc)
コード例 #31
0
ファイル: test_basics.py プロジェクト: abed-hawa/amara
 def Xtest_parse_with_url(self):
     doc = parse(TEST_URL)
     #Minimal node testing
     self.assertEqual(len(doc.xml_children), 1)
     self.assertEqual(doc.xml_children[0].xml_type, tree.element.xml_type)
     self.assertEqual(doc.xml_children[0].xml_qname, 'disclaimer')
     self.assertEqual(doc.xml_children[0].xml_namespace, None)
     self.assertEqual(doc.xml_children[0].xml_prefix, None)
コード例 #32
0
ファイル: test_basics.py プロジェクト: abed-hawa/amara
 def test_parse_with_file_path(self):
     """Parse with file path"""
     fname = tempfile.mktemp('.xml')
     fout = open(fname, 'w')
     fout.write(MONTY_XML)
     fout.close()
     doc = parse(fname)
     self.run_checks(doc)
コード例 #33
0
ファイル: test_whatsnew.py プロジェクト: mredar/amara
 def test_ids(self):
     DOC = '<!DOCTYPE xsa PUBLIC "-//LM Garshol//DTD XML Software Autoupdate 1.0//EN//XML" "http://www.garshol.priv.no/download/xsa/xsa.dtd">\n<xsa/>'
     doc = amara.parse(DOC, standalone=True)
     self.assertEqual(doc.xml_system_id,
                      u'http://www.garshol.priv.no/download/xsa/xsa.dtd')
     self.assertEqual(
         doc.xml_public_id,
         u'-//LM Garshol//DTD XML Software Autoupdate 1.0//EN//XML')
コード例 #34
0
ファイル: test_indiana_usecases.py プロジェクト: mredar/amara
def test_last_function_low_level():
    '''
    '''
    doc = amara.parse(XML)
    last_url = doc.xml_select(
        u'/listitem/para/ulink[position() = last()]/@url')
    EXPECTED = nodeset([u'http://www.ncbi.nlm.nih.gov/pubmed/16785838'])
    assert last_url == EXPECTED, (EXPECTED, last_url)
コード例 #35
0
ファイル: registry.py プロジェクト: dpla/akara
def _register_services(uri):
    new_templates = {}
    tree = amara.parse(uri)
    for path in tree.xml_select("//service[@ident]/path[@template]"):
        ident = path.xml_parent.xml_attributes["ident"]
        template = path.xml_attributes["template"]
        new_templates[ident] = opensearch.make_template(template)
    return new_templates
コード例 #36
0
 def Xtest_parse_with_url(self):
     doc = parse(TEST_URL)
     #Minimal node testing
     self.assertEqual(len(doc.xml_children), 1)
     self.assertEqual(doc.xml_children[0].xml_type, tree.element.xml_type)
     self.assertEqual(doc.xml_children[0].xml_qname, 'disclaimer')
     self.assertEqual(doc.xml_children[0].xml_namespace, None)
     self.assertEqual(doc.xml_children[0].xml_prefix, None)
コード例 #37
0
 def test_single_xpath(self):
     doc = amara.parse(XML)
     b_els = doc.xml_select(u"//b")
     self.assertEqual(len(b_els), 2)
     self.assertEqual(doc.xml_select(u"count(//b)"), 2)
     self.assertEqual(doc.xml_select(u"/a/@x")[0].xml_value , u'1')
     self.assertEqual(doc.xml_select(u'string(/a/b)'), u'i')
     return
コード例 #38
0
ファイル: get_clouds.py プロジェクト: hep-gc/cloud-scheduler
    def _lookupCloudsXML(self):

        # Query the Redis DB for the complete, aggregated XML file
        cloudsXML = self.db.get(ConfigMapping[CLOUDS_KEY])
        # amDoc will contain a data structure that mirrors the public XML Schema, allowing for direct access via name.name2.name3 style
        amDoc = amara.parse(str(cloudsXML)) 

        return amDoc
コード例 #39
0
def _register_services(uri):
    new_templates = {}
    tree = amara.parse(uri)
    for path in tree.xml_select("//service[@ident]/path[@template]"):
        ident = path.xml_parent.xml_attributes["ident"]
        template = path.xml_attributes["template"]
        new_templates[ident] = opensearch.make_template(template)
    return new_templates
コード例 #40
0
ファイル: test_whatsnew.py プロジェクト: abed-hawa/amara
 def test_root(self):
     doc = amara.parse('<A><B><C/></B></A>')
     C = doc.xml_select(u'//C').pop()
     self.assertEqual(C.xml_root, doc)
     mynode = C
     while mynode.xml_parent: 
         mynode = mynode.xml_parent
     self.assertEqual(mynode, doc)
コード例 #41
0
 def test_single_xpath(self):
     doc = amara.parse(XML)
     b_els = doc.xml_select(u"//b")
     self.assertEqual(len(b_els), 2)
     self.assertEqual(doc.xml_select(u"count(//b)"), 2)
     self.assertEqual(doc.xml_select(u"/a/@x")[0].xml_value, u'1')
     self.assertEqual(doc.xml_select(u'string(/a/b)'), u'i')
     return
コード例 #42
0
    def _lookupCloudsXML(self):

        # Query the Redis DB for the complete, aggregated XML file
        cloudsXML = self.db.get(ConfigMapping[CLOUDS_KEY])
        # amDoc will contain a data structure that mirrors the public XML Schema, allowing for direct access via name.name2.name3 style
        amDoc = amara.parse(str(cloudsXML))

        return amDoc
コード例 #43
0
ファイル: test_whatsnew.py プロジェクト: mredar/amara
 def test_root(self):
     doc = amara.parse('<A><B><C/></B></A>')
     C = doc.xml_select(u'//C').pop()
     self.assertEqual(C.xml_root, doc)
     mynode = C
     while mynode.xml_parent:
         mynode = mynode.xml_parent
     self.assertEqual(mynode, doc)
コード例 #44
0
ファイル: test_whatsnew.py プロジェクト: abed-hawa/amara
 def test_chardata(self):
     doc = amara.parse('<A>Spam</A><!--eggs-->')
     A = doc.xml_children[0]
     spam = A.xml_children[0]
     self.assertEqual(spam.xml_value, u'Spam')
     self.assertEqual(len(spam.xml_value), 4)
     self.assertEqual(spam.xml_value[1:3], u'pa')
     spam.xml_value += u' eggs'
     self.assertEqual(spam.xml_value, u'Spam eggs')
コード例 #45
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode5():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="1" ns:y="1" ns:z=""/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    attr_y = tree.attribute(BOGUS_X_NS, u'ns:y', u'1')
    doc.xml_first_child.xml_attributes.setnode(attr_y)
    attr_z = tree.attribute(BOGUS_X_NS, u'ns:z')
    doc.xml_first_child.xml_attributes.setnode(attr_z)
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #46
0
ファイル: test_whatsnew.py プロジェクト: mredar/amara
 def test_no_longer(self):
     doc = amara.parse('<A/>')
     A = doc.xml_children[0]
     for old_method in [
             'nodeName', 'nodeValue', 'namespaceURI', 'localName', 'prefix',
             'childNodes', 'isSameNode', 'xpath', 'rootNode', 'baseURI',
             'xmlBase', 'documentURI'
     ]:
         self.assertRaises(AttributeError, getattr, A, "%s" % old_method)
コード例 #47
0
ファイル: test_whatsnew.py プロジェクト: mredar/amara
 def test_chardata_no_longer(self):
     doc = amara.parse('<A>Spam</A><!--eggs-->')
     A = doc.xml_children[0]
     spam = A.xml_children[0]
     for old_method in [
             'length', 'substringData', 'insertData', 'replaceData',
             'appendData', 'deleteData'
     ]:
         self.assertRaises(AttributeError, getattr, spam, "%s" % old_method)
コード例 #48
0
ファイル: test_whatsnew.py プロジェクト: mredar/amara
 def test_chardata(self):
     doc = amara.parse('<A>Spam</A><!--eggs-->')
     A = doc.xml_children[0]
     spam = A.xml_children[0]
     self.assertEqual(spam.xml_value, u'Spam')
     self.assertEqual(len(spam.xml_value), 4)
     self.assertEqual(spam.xml_value[1:3], u'pa')
     spam.xml_value += u' eggs'
     self.assertEqual(spam.xml_value, u'Spam eggs')
コード例 #49
0
ファイル: __init__.py プロジェクト: xblaster/scrutator
 def read_object_defs(self):
     self.logger.debug("==============================================================")
     objects = []
     for config in self.config_location:
         self.logger.debug("* Parsing %s" % config)
         doc = amara.parse(config)
         objects.extend([self._convert_component(component) for component in doc.components.component])
     self.logger.debug("==============================================================")
     return objects
コード例 #50
0
 def test_nested_doc(self):
     'Input doc with text in nested elements'
     x = amara.parse(
         '<a>one two <b>three four </b><c>five <d>six seven</d> eight</c> nine</a>'
     )
     for i in range(1, 11):
         trimmed_tree = util.trim_word_count(x, i)
         word_count = len(trimmed_tree.xml_select(u'string(.)').split())
         self.assertEquals(word_count, min(i, 9))
コード例 #51
0
ファイル: Parser.py プロジェクト: backtosource/EnSuite
	def parseServer(self):
		try:
			doc = amara.parse('file:%s/config.xml'%(C.YENCAP_MAN_CONF_HOME))
			self.host = ''
			self.port = int(str(doc.server.port))
			self.ip_version = str(doc.server.ip_version)
		except Exception, exp:
			print 'Check configuration file of the server : config.xml'
			print str(exp)
コード例 #52
0
 def setUp(self):
     self.bigdoc1 = ["<A>"]
     self.bigdoc1.extend(["<B/>"]*(SCALE*100))
     self.bigdoc1.extend(["</A>"])
     self.bigdoc1 = ''.join(self.bigdoc1)
     #len(self.bigdoc1) is 400007 for SCALE = 1000
     self.doc = amara.parse(self.bigdoc1)
     gc.enable()
     return
コード例 #53
0
def test_405_error_message():
    url = server()
    try:
        f = urlopen(url, "The server ignores this text")
        raise AssertionError("/ is not supposed to allow a POST")
    except urllib2.HTTPError, err:
        assert err.code == 405, err.code
        assert err.headers["Content-Type"] == "text/html", err.headers["Content-Type"]
        tree = amara.parse(err.fp, standalone=True)
コード例 #54
0
def test_404_error_message():
    url = server() + "this_does_not_exist/I_mean_it/Anybody_want_a_peanut?"
    try:
        urlopen(url)
        raise AssertionError("that URL should not be present")
    except urllib2.HTTPError, err:
        assert err.code == 404
        assert err.headers["Content-Type"] == "text/html", err.headers["Content-Type"]
        tree = amara.parse(err.fp, standalone=True)
コード例 #55
0
def test_attr_setnode5():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="1" ns:y="1" ns:z=""/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    attr_y = tree.attribute(BOGUS_X_NS, u'ns:y', u'1')
    doc.xml_first_child.xml_attributes.setnode(attr_y)
    attr_z = tree.attribute(BOGUS_X_NS, u'ns:z')
    doc.xml_first_child.xml_attributes.setnode(attr_z)
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #56
0
def test_attr_setnode3():
    EXPECTED = """<a x="1"/>"""
    doc = parse('<a x="1"/>')
    #x = doc.xml_first_child.xml_attributes[None, u'x']
    attr_x = copy.copy(doc.xml_first_child.xml_attributes.getnode(None, u'x'))
    del doc.xml_first_child.xml_attributes[None, u'x']
    doc.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #57
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode3():
    EXPECTED = """<a x="1"/>"""
    doc = parse('<a x="1"/>')
    #x = doc.xml_first_child.xml_attributes[None, u'x']
    attr_x = copy.copy(doc.xml_first_child.xml_attributes.getnode(None, u'x'))
    del doc.xml_first_child.xml_attributes[None, u'x']
    doc.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #58
0
def test_attr_setnode2():
    EXPECTED = """<a x="1" y="1" z=""/>"""
    doc = parse('<a x="1"/>')
    attr_y = tree.attribute(None, u'y', u'1')
    doc.xml_first_child.xml_attributes.setnode(attr_y)
    attr_z = tree.attribute(None, u'z')
    doc.xml_first_child.xml_attributes.setnode(attr_z)
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #59
0
    def readModules(self):
        moduleDescrList = []
        try:
            self.doc = amara.parse("file:" + C.YENCAP_CONF_HOME +
                                   "/modules.xml")

            for elem in self.doc.modules.module:

                yanguri = None

                try:
                    yanguri = str(elem.yanguri)
                except Exception, exp:
                    pass

                if yanguri != None:
                    i_nom = yanguri.find('?')
                    if i_nom != -1:
                        i_rev = yanguri.find('&')
                        if i_rev == -1:
                            i_rev = len(yanguri)

                        moduleDefName = yanguri[i_nom + 1:i_rev]
                        i_equal = moduleDefName.find('=')

                        name = moduleDefName[i_equal + 1:len(moduleDefName)]
                        xpath = '/'
                        pref = ''

                        namespace = yanguri[0:i_nom]
                    else:
                        raise Exception, "yang uri not conform : " + yanguri
                else:
                    name = str(elem.name)
                    xpath = str(elem.xpath)
                    namespace = str(elem.namespace)
                    pref = str(elem.namespace.pref)

                cachelifetime = int(str(elem.cachelifetime))
                parameters = {}
                try:
                    for param in elem.parameters.parameter:
                        parameters[param.name] = str(param.value)
                except Exception, exp:
                    pass

                moduleDescr = {
                    "yanguri": yanguri,
                    "name": name,
                    "xpath": xpath,
                    "namespace": namespace,
                    "pref": pref,
                    "cachelifetime": cachelifetime,
                    "parameters": parameters
                }
                moduleDescrList.append(moduleDescr)
コード例 #60
0
def launch(*args, **kwargs):
    import pprint
    from amara.xpath.util import simplify
    source = args[0]
    expr = args[1]
    import amara
    doc = amara.parse(source)
    result = doc.xml_select(expr.decode('utf-8'))
    pprint.pprint(simplify(result))
    return