Create an Atom entry tag and embed the passed XML within it

def wrapAtom(xml, id, title, author=None, updated=None, author_uri=None,
             alt=None, alt_type="text/html"):
    """
    Create an Atom entry tag and embed the passed XML within it
    """

    entryTag = etree.Element(ATOM + "entry", nsmap=ATOM_NSMAP)
    titleTag = etree.SubElement(entryTag, ATOM + "title")
    titleTag.text = title
    idTag = etree.SubElement(entryTag, ATOM + "id")
    idTag.text = id
    updatedTag = etree.SubElement(entryTag, ATOM + "updated")

    if alt:
        etree.SubElement(
            entryTag,
            ATOM + "link",
            rel='alternate',
            href=alt,
            type=alt_type)

    if updated is not None:
        # If updated is a naive datetime, set its timezone to the local one
        # So the xs:datetime value will include an explicit offset
        if updated.tzinfo is None:
            updated = localize_datetime(updated)
        updatedTag.text = xsDateTime_format(updated)
    else:
        updatedTag.text = xsDateTime_format(localize_datetime(datetime.now()))
    if author or author_uri:
        authorTag = etree.SubElement(entryTag, ATOM + "author")
        if author:
            nameTag = etree.SubElement(authorTag, ATOM + "name")
            nameTag.text = author
        if author_uri:
            nameUriTag = etree.SubElement(authorTag, ATOM + "uri")
            nameUriTag.text = author_uri
    contentTag = etree.SubElement(entryTag, ATOM + "content")
    contentTag.set("type", "application/xml")
    contentTag.append(xml)
    return entryTag