[dots] Add test to odtdocument.py. try/except odt translation. Show error when extraction fails.
- From: Fernando Herrera de las Heras <fherrera src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dots] Add test to odtdocument.py. try/except odt translation. Show error when extraction fails.
- Date: Tue, 20 Jul 2010 05:11:39 +0000 (UTC)
commit 9ead50deb020bd661b749cf850f691feb0cf51c2
Author: Fernando Herrera <fherrera onirica com>
Date: Fri Jul 16 02:22:00 2010 +0200
Add test to odtdocument.py. try/except odt translation. Show error when extraction fails.
TODO | 3 ---
dots/odtdocument.py | 22 +++++++++++++++++++---
2 files changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/TODO b/TODO
index ceee84e..9d89f5c 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,4 @@
- Put cursor at beginning of textviews when they are exposed.
-- Nice error handling:
- when importing odt documents.
- when pdf has no text
- Edit the text
- basic packaging
- Escape file names when building uris
diff --git a/dots/odtdocument.py b/dots/odtdocument.py
index c1fdd52..1c7f7aa 100644
--- a/dots/odtdocument.py
+++ b/dots/odtdocument.py
@@ -23,11 +23,27 @@ from odf.odf2xhtml import ODF2XHTML
class OdtDocument(Document):
+ def _get_text(sefl, file):
+ odhandler = ODF2XHTML (False, False)
+ odhandler.elements[(TEXTNS, u"changed-region")] = (odhandler.s_ignorexml,None)
+ try:
+ result = odhandler.odf2xhtml(file).encode('UTF-8','xmlcharrefreplace')
+ except:
+ result = ""
+ pass
+ return result
+
def translate(self, config):
config['outputFormat']['inputTextEncoding'] = "UTF8"
self.translator = Translator(config)
- odhandler = ODF2XHTML (False, False)
- odhandler.elements[(TEXTNS, u"changed-region")] = (odhandler.s_ignorexml,None)
- result = odhandler.odf2xhtml(self.input_file).encode('UTF-8','xmlcharrefreplace')
+ result = self._get_text (self.input_file)
self.braille_text = self.translator.translate_string (result)
+if __name__ == "__main__":
+ import sys
+
+ if len(sys.argv) > 1:
+ document = OdtDocument(sys.argv[1])
+ print document._get_text(sys.argv[1])
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]