Beispiel #1
0
def fptr(fileid=None):
    """Return the fptr element"""

    _fptr = _element('fptr')
    _fptr.set('FILEID', decode_utf8(fileid))

    return _fptr
Beispiel #2
0
def xmldata(child_elements=None):
    """Create an xmlData element and append the child elements to
    the element.
    """
    xmldata_e = _element('xmlData')
    if child_elements:
        for elem in child_elements:
            xmldata_e.append(elem)
    return xmldata_e
Beispiel #3
0
def filesec(child_elements=None):
    """Return the fileSec element"""

    _filesec = _element('fileSec')
    if child_elements:
        for elem in child_elements:
            _filesec.append(elem)

    return _filesec
Beispiel #4
0
def mptr(loctype=None, xlink_href=None, xlink_type=None):
    """Return the fptr element"""

    _mptr = _element('mptr', ns={'xlink': XLINK_NS})
    _mptr.set('LOCTYPE', decode_utf8(loctype))
    _mptr.set(xlink_ns('href'), decode_utf8(xlink_href))
    _mptr.set(xlink_ns('type'), decode_utf8(xlink_type))

    return _mptr
def amdsec(child_elements=None):
    """Return the amdSec element"""

    _amdsec = _element('amdSec')

    if child_elements:
        for elem in child_elements:
            _amdsec.append(elem)

    return _amdsec
Beispiel #6
0
def filegrp(use=None, child_elements=None):
    """Return the fileGrp element"""

    _filegrp = _element('fileGrp')
    if use:
        _filegrp.set('USE', decode_utf8(use))
    if child_elements:
        for elem in child_elements:
            _filegrp.append(elem)

    return _filegrp
Beispiel #7
0
def structmap(type_attr=None, label=None):
    """Return the structmap element"""

    _structmap = _element('structMap')
    # _structMap.append(div_element)
    if type_attr:
        _structmap.set('TYPE', decode_utf8(type_attr))
    if label:
        _structmap.set('LABEL', decode_utf8(label))

    return _structmap
Beispiel #8
0
def file_elem(file_id=None, admid_elements=None, loctype=None,
              xlink_href=None, xlink_type=None, groupid=None,
              use=None):
    """Return the file element"""

    _file = _element('file')
    _file.set('ID', decode_utf8(file_id))
    admids = ' '.join([decode_utf8(a) for a in admid_elements])
    _file.set('ADMID', decode_utf8(admids))
    if groupid:
        _file.set('GROUPID', decode_utf8(groupid))
    if use:
        _file.set('USE', decode_utf8(use))

    _flocat = _element('FLocat', ns={'xlink': XLINK_NS})
    _flocat.set('LOCTYPE', decode_utf8(loctype))
    _flocat.set(xlink_ns('href'), decode_utf8(xlink_href))
    _flocat.set(xlink_ns('type'), decode_utf8(xlink_type))
    _file.append(_flocat)

    return _file
def dmdsec(element_id, child_elements=None, created_date=None):
    """Return the dmdSec element"""

    if created_date is None:
        created_date = current_iso_datetime()

    dmdsec_elem = _element('dmdSec')
    dmdsec_elem.set('ID', decode_utf8(element_id))
    dmdsec_elem.set('CREATED', decode_utf8(created_date))
    if child_elements:
        for elem in child_elements:
            dmdsec_elem.append(elem)

    return dmdsec_elem
def techmd(element_id, created_date=None, child_elements=None):
    """Return the techMD element"""

    if created_date is None:
        created_date = current_iso_datetime()

    _techmd = _element('techMD')
    _techmd.set('ID', decode_utf8(element_id))
    _techmd.set('CREATED', decode_utf8(created_date))

    if child_elements:
        for elem in child_elements:
            _techmd.append(elem)

    return _techmd
Beispiel #11
0
def mdwrap(mdtype, mdtypeversion, othermdtype="", child_elements=None):
    """Create an mdWrap element with the mandatory
    attributes and append the child elements to the element.

    :mdtype: value for the MDTYPE attribute
    :mdtypeversion: value for the MDTYPEVERSION attribute
    :othermdtype: value for the optional OTHERMDTYPE attribute (use
                  if MDTYPE='OTHER')
    :child_elements: the child elements as a list

    :returns: the mets:mdWrap element as XML
    """
    mdwrap_e = _element('mdWrap')
    mdwrap_e.set('MDTYPE', decode_utf8(mdtype))
    mdwrap_e.set('MDTYPEVERSION', decode_utf8(mdtypeversion))
    if mdtype == 'OTHER':
        mdwrap_e.set('OTHERMDTYPE', decode_utf8(othermdtype))
    if child_elements:
        for elem in child_elements:
            mdwrap_e.append(elem)
    return mdwrap_e
Beispiel #12
0
def div(type_attr=None,
        order=None,
        contentids=None,
        label=None,
        orderlabel=None,
        dmdid=None,
        admid=None,
        div_elements=None,
        fptr_elements=None,
        mptr_elements=None):
    """Return the div element"""

    _div = _element('div')
    _div.set('TYPE', decode_utf8(type_attr))
    if order:
        _div.set('ORDER', decode_utf8(order))
    if contentids:
        _div.set('CONTENTIDS', decode_utf8(contentids))
    if label:
        _div.set('LABEL', decode_utf8(label))
    if orderlabel:
        _div.set('ORDERLABEL', decode_utf8(orderlabel))
    if dmdid:
        _div.set('DMDID', ' '.join([decode_utf8(d) for d in dmdid]))
    if admid:
        _div.set('ADMID', ' '.join([decode_utf8(a) for a in admid]))

    if div_elements:
        for elem in div_elements:
            _div.append(elem)
    if fptr_elements:
        for elem in fptr_elements:
            _div.append(elem)
    if mptr_elements:
        for elem in mptr_elements:
            _div.append(elem)

    return _div
def test_element():
    """Test METS _element"""
    xml = """<mets:xxx xmlns:mets="http://www.loc.gov/METS/"/>"""
    assert u.compare_trees(m._element('xxx'), ET.fromstring(xml)) is True
Beispiel #14
0
def stream(admid_elements=None):
    """Return the stream element"""
    stream = _element('stream')
    admids = ' '.join([decode_utf8(a) for a in admid_elements])
    stream.set('ADMID', admids)
    return stream