From dafc5132365a18408b81d6603533b1671fba8825 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Wed, 17 May 2017 11:44:46 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20exception=20para=20extens=C3=A3o=20n?= =?UTF-8?q?=C3=A3o=20suportada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luciano Almeida --- sapl/base/search_indexes.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sapl/base/search_indexes.py b/sapl/base/search_indexes.py index c85be523b..e41dac3bf 100644 --- a/sapl/base/search_indexes.py +++ b/sapl/base/search_indexes.py @@ -7,6 +7,8 @@ from haystack import indexes from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa from sapl.norma.models import NormaJuridica +from textract.exceptions import ExtensionNotSupported + class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) @@ -32,15 +34,19 @@ class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): if arquivo: try: arquivo.open() + arquivo.close() except OSError: return self.prepared_data if not os.path.splitext(arquivo.path)[1][:1]: return self.prepared_data - extracted_data = textract.process( - arquivo.path).decode( - 'utf-8').replace('\n', ' ') + try: + extracted_data = textract.process( + arquivo.path).decode( + 'utf-8').replace('\n', ' ') + except ExtensionNotSupported: + return self.prepared_data extracted_data = extracted_data.replace('\t', ' ')