Exemplo n.º 1
0
def iter_environments(premis_elem):
    """Iterate all PREMIS environments from starting element.

    :param premis_elem: ElementTree element
    :return: Iterable of premis environments
    """
    for _environment in iter_elements(premis_elem, 'environment'):
        yield _environment
Exemplo n.º 2
0
def parse_dependency(premis_elem):
    """
    :param premis_elem:
    :return: String
    """
    try:
        return list(iter_elements(premis_elem, 'dependency'))
    except IndexError:
        return ""
Exemplo n.º 3
0
def iter_events(premis):
    """Iterate all PREMIS events from starting element.

    :starting_element: Element where matching elements are searched
    :returns: Generator object for iterating all elements

    """
    for elem in iter_elements(premis, 'event'):
        yield elem
def test_iter_elements():
    """Test iter_elements"""
    obj1 = o.object(p.identifier('local', 'id01'), original_name='nimi1')
    obj2 = o.object(p.identifier('local', 'id02'), original_name='nimi2')
    obj3 = o.object(p.identifier('local', 'id03'), original_name='nimi3')
    xml = p.premis(child_elements=[obj1, obj2, obj3])
    i = 0
    for name in p.iter_elements(xml, 'originalName'):
        i = i + 1
        assert name.text == 'nimi' + str(i)
    assert i == 3
Exemplo n.º 5
0
def environments_with_purpose(environments, purpose):
    """Finds the premis environment sections with a specific purpose.
    The function yields only the environments with the given purpose in
    the premis:environmentPurpose contents.

    :param environments: Iterable of premis environments
    :param purpose: The environment purpose as a string
    :return: Iterable of premis environments
    """
    for _environment in environments:
        for purpose_elem in iter_elements(_environment, 'environmentPurpose'):
            if purpose_elem.text == purpose:
                yield _environment
Exemplo n.º 6
0
def contains_object(object_element, search_from_element):
    """Return True if `search_from_element` contains the `object_element`
    object or objectIdentifier.

    :object_element: PREMIS object or identifier
    :search_from_element: PREMIS object to search from
    :returns: Boolean

    """

    key_identifier_value = next(
        iter_elements(object_element, 'objectIdentifierValue'))

    # Unfortunately Python 2.6 ElementTree does not support xpath search by
    # element value so we have to search with for-loop

    identifiers = iter_elements(search_from_element, 'objectIdentifierValue')

    for identifier_value in identifiers:
        if identifier_value.text == key_identifier_value.text:
            return True

    return False