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