handle missing properties in Office file correctly

This commit is contained in:
Helmut Merz 2013-05-06 12:21:50 +02:00
parent 9427b8ccbd
commit d84e8de9a0
2 changed files with 15 additions and 9 deletions

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de # Copyright (c) 2013 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -78,28 +78,28 @@ class OfficeFile(ExternalFileAdapter):
@Lazy @Lazy
def docPropertyDom(self): def docPropertyDom(self):
fn = self.docFilename fn = self.docFilename
dummy = dict(core=[], custom=[]) result = dict(core=[], custom=[])
root, ext = os.path.splitext(fn) root, ext = os.path.splitext(fn)
if not ext.lower() in self.fileExtensions: if not ext.lower() in self.fileExtensions:
return dummy return result
try: try:
zf = ZipFile(fn, 'r') zf = ZipFile(fn, 'r')
except IOError, e: except IOError, e:
from logging import getLogger from logging import getLogger
self.logger.warn(e) self.logger.warn(e)
return dummy return result
if self.corePropFileName not in zf.namelist(): if self.corePropFileName not in zf.namelist():
self.logger.warn('Core properties not found in file %s.' % self.logger.warn('Core properties not found in file %s.' %
self.externalAddress) self.externalAddress)
else:
result['core'] = etree.fromstring(zf.read(self.corePropFileName))
if self.propFileName not in zf.namelist(): if self.propFileName not in zf.namelist():
self.logger.warn('Custom properties not found in file %s.' % self.logger.warn('Custom properties not found in file %s.' %
self.externalAddress) self.externalAddress)
propsXml = zf.read(self.propFileName) else:
corePropsXml = zf.read(self.corePropFileName) result['custom'] = etree.fromstring(zf.read(self.propFileName))
# TODO: read core.xml, return both trees in dictionary
zf.close() zf.close()
return {'custom': etree.fromstring(propsXml), return result
'core': etree.fromstring(corePropsXml)}
def getDocProperty(self, pname): def getDocProperty(self, pname):
for p in self.docPropertyDom['custom']: for p in self.docPropertyDom['custom']:

View file

@ -771,6 +771,12 @@ msgstr "Sie haben Ihr altes Passwort nicht korrekt eingegeben."
msgid "Password and password confirmation do not match." msgid "Password and password confirmation do not match."
msgstr "Die Passwort-Wiederholung stimmt nicht mit dem eingegebenen Passwort überein." msgstr "Die Passwort-Wiederholung stimmt nicht mit dem eingegebenen Passwort überein."
msgid "confirmation_mail_subject"
msgstr "Benutzer-Registrierung"
msgid "confirmation_mail_text."
msgstr "Bitte clicken Sie auf den folgenden Link, um die Anmeldung abzschließen."
msgid "The user account has been created." msgid "The user account has been created."
msgstr "Ihr Benutzerkonto wurde eingerichtet." msgstr "Ihr Benutzerkonto wurde eingerichtet."