コード例 #1
0
 def test_namespace_unaware(self):
     # (tag name, expected stripped name)
     test_xp = [
     ('/project/artifactId', "/*[local-name()='project']/*[local-name()='artifactId']"),
     ('/project/properties/projectName', "/*[local-name()='project']/*[local-name()='properties']/*[local-name()='projectName']")]
     ('/project/developers/developer/email', "/*[local-name()='project']/*[local-name()='developers']/*[local-name()='developer']/*[local-name()='email']"),
     for simple_xpath, expected in test_xp:
         assert expected == xmlutils.namespace_unaware(simple_xpath)
コード例 #2
0
ファイル: nuget.py プロジェクト: yudhik11/scancode-toolkit
def _nuget_handler(xdoc):
    tags = {}
    for tag in nuspec_tags:
        xpath = xmlutils.namespace_unaware('/package/metadata/{}'.format(tag))
        values = xmlutils.find_text(xdoc, xpath)
        if values:
            value = u''.join(values)
            tags[tag] = value and value or None
    return tags
コード例 #3
0
ファイル: nuget.py プロジェクト: ocabrisses/scancode-toolkit
def _nuget_handler(xdoc):
    tags = {}
    for tag in nuspec_tags:
        xpath = xmlutils.namespace_unaware('/package/metadata/{}'.format(tag))
        values = xmlutils.find_text(xdoc, xpath)
        if values:
            value = u''.join(values)
            tags[tag] = value and value or None
    return tags
コード例 #4
0
 def test_xpath_with_bare_lxml(self):
     test_file = self.get_test_loc('xmlutils/ant-jai-1.7.0.pom')
     doc = etree.parse(test_file)
     assert None == doc.findtext('//version')
     assert None == doc.findtext('version')
     assert None == doc.findtext('.//version')
     assert '1.7.0' == doc.findtext('//{http://maven.apache.org/POM/4.0.0}version')
     assert '1.7.0' == doc.findtext('{http://maven.apache.org/POM/4.0.0}version')
     assert '1.7.0' == doc.findtext('.//{http://maven.apache.org/POM/4.0.0}version')
     assert ['1.7.0'] == [e.text  for e in doc.xpath(xmlutils.namespace_unaware('/project/version'))]
コード例 #5
0
    def test_find_text_ignoring_namespaces(self):
        test_doc = self.get_test_loc('xmlutils/ant-jai-1.7.0.pom')
        expr = "/*[local-name()='project']/*[local-name()='modelVersion']"
        handler = lambda xdoc: xmlutils.find_text(xdoc, expr)
        test = xmlutils.parse(test_doc, handler)
        assert ['4.0.0'] == test

        expr2 = xmlutils.namespace_unaware("/project/modelVersion")
        handler2 = lambda xdoc: xmlutils.find_text(xdoc, expr2)
        test = xmlutils.parse(test_doc, handler2)
        assert ['4.0.0'] == test
コード例 #6
0
    ('repository_id', '/project/repositories/repository/id'),
    ('repository_layout', '/project/repositories/repository/layout'),
    ('repository_name', '/project/repositories/repository/name'),
    ('repository_url', '/project/repositories/repository/url'),

    ('scm_connection', '/project/scm/connection'),
    ('scm_developer_connection', '/project/scm/developerConnection'),
    ('scm_url', '/project/scm/url'),

    ('distribution_management_group_id', '/project/distributionManagement/relocation/groupId'),
    ('model_version', '/project/modelVersion')
]


MAVEN_FIELDS = [('maven_' + key, xmlutils.namespace_unaware(xpath)) for key, xpath in (MAVEN2_FIELDS + MAVEN1_FIELDS)]


# Common Maven property keys and corresponding XPath to the value

MAVEN_PROPS = [
    ('pom.groupId', '/project/groupId'),
    ('project.groupId', '/project/groupId'),
    ('groupId', '/project/groupId'),
    # fall back to parent
    ('groupId', '/project/parent/groupId'),
    ('pom.groupId', '/project/parent/groupId'),
    ('project.groupId', '/project/parent/groupId'),

    ('artifactId', '/project/artifactId'),
    ('pom.artifactId', '/project/artifactId'),