EPUB metadata: When setting metadata in an EPUB, explicitly specify the namespace of the role attribute on the <dc:creator> tag

This commit is contained in:
Kovid Goyal 2012-09-26 18:17:54 +05:30
parent a83f930b92
commit 5399e417da

View File

@ -792,19 +792,16 @@ class OPF(object): # {{{
remove = list(self.authors_path(self.metadata)) remove = list(self.authors_path(self.metadata))
for elem in remove: for elem in remove:
elem.getparent().remove(elem) elem.getparent().remove(elem)
elems = []
for author in val:
attrib = {'{%s}role'%self.NAMESPACES['opf']: 'aut'}
elem = self.create_metadata_element('creator', attrib=attrib)
self.set_text(elem, author.strip())
# Ensure new author element is at the top of the list # Ensure new author element is at the top of the list
# for broken implementations that always use the first # for broken implementations that always use the first
# <dc:creator> element with no attention to the role # <dc:creator> element with no attention to the role
elems.append(elem) for author in reversed(val):
for elem in reversed(elems): elem = self.metadata.makeelement('{%s}creator'%
parent = elem.getparent() self.NAMESPACES['dc'], nsmap=self.NAMESPACES)
parent.remove(elem) elem.tail = '\n'
parent.insert(0, elem) self.metadata.insert(0, elem)
elem.set('{%s}role'%self.NAMESPACES['opf'], 'aut')
self.set_text(elem, author.strip())
return property(fget=fget, fset=fset) return property(fget=fget, fset=fset)