From b36287e573b97c065dee4d5f36a8757ed4f375d9 Mon Sep 17 00:00:00 2001 From: Alex Riina Date: Sun, 8 Mar 2015 00:04:41 -0500 Subject: [PATCH] clean up style and extra imports --- talon/quotations.py | 7 +++---- talon/signature/__init__.py | 16 +++------------- talon/signature/extraction.py | 6 +----- tests/quotations_test.py | 2 -- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/talon/quotations.py b/talon/quotations.py index dc77fd4..cdd22b1 100644 --- a/talon/quotations.py +++ b/talon/quotations.py @@ -12,8 +12,7 @@ from copy import deepcopy from lxml import html, etree import html2text -from talon.constants import RE_DELIMITER -from talon.utils import random_token, get_delimiter +from talon.utils import get_delimiter from talon import html_quotations @@ -151,7 +150,7 @@ def extract_from(msg_body, content_type='text/plain'): return extract_from_plain(msg_body) elif content_type == 'text/html': return extract_from_html(msg_body) - except Exception, e: + except Exception: log.exception('ERROR extracting message') return msg_body @@ -344,7 +343,7 @@ def extract_from_html(msg_body): html_tree_copy = deepcopy(html_tree) number_of_checkpoints = html_quotations.add_checkpoint(html_tree, 0) - quotation_checkpoints = [False for i in xrange(number_of_checkpoints)] + quotation_checkpoints = [False] * number_of_checkpoints msg_with_checkpoints = html.tostring(html_tree) h = html2text.HTML2Text() diff --git a/talon/signature/__init__.py b/talon/signature/__init__.py index d1962f3..a871447 100644 --- a/talon/signature/__init__.py +++ b/talon/signature/__init__.py @@ -21,11 +21,9 @@ trained against, don't forget to regenerate: """ import os -import sys -from cStringIO import StringIO from . import extraction -from . extraction import extract +from . extraction import extract #noqa from . learning import classifier @@ -36,13 +34,5 @@ EXTRACTOR_DATA = os.path.join(DATA_DIR, 'train.data') def initialize(): - try: - # redirect output - so, sys.stdout = sys.stdout, StringIO() - - extraction.EXTRACTOR = classifier.load(EXTRACTOR_FILENAME, - EXTRACTOR_DATA) - sys.stdout = so - except Exception, e: - raise Exception( - "Failed initializing signature parsing with classifiers", e) + extraction.EXTRACTOR = classifier.load(EXTRACTOR_FILENAME, + EXTRACTOR_DATA) diff --git a/talon/signature/extraction.py b/talon/signature/extraction.py index 8c7b74e..58df68d 100644 --- a/talon/signature/extraction.py +++ b/talon/signature/extraction.py @@ -1,14 +1,10 @@ # -*- coding: utf-8 -*- -import os import logging import regex as re from PyML import SparseDataSet -from talon.constants import RE_DELIMITER -from talon.signature.constants import (SIGNATURE_MAX_LINES, - TOO_LONG_SIGNATURE_LINE) from talon.signature.learning.featurespace import features, build_pattern from talon.utils import get_delimiter from talon.signature.bruteforce import get_signature_candidate @@ -61,7 +57,7 @@ def extract(body, sender): text = delimiter.join(text) if text.strip(): return (text, delimiter.join(signature)) - except Exception, e: + except Exception: log.exception('ERROR when extracting signature with classifiers') return (body, None) diff --git a/tests/quotations_test.py b/tests/quotations_test.py index dcc723e..7184368 100644 --- a/tests/quotations_test.py +++ b/tests/quotations_test.py @@ -3,8 +3,6 @@ from . import * from . fixtures import * -from flanker import mime - from talon import quotations