From f141b2d344bbd09a7469d5c9ecffb38ed6ccd618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22Piranna=22?= Date: Thu, 17 May 2012 16:52:01 +0200 Subject: Raise exception on INCLUDE loading failure --- sqlparse/filters.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/filters.py b/sqlparse/filters.py index 8430687..e17766d 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -92,12 +92,13 @@ def StripWhitespace(stream): class IncludeStatement: """Filter that enable a INCLUDE statement""" - def __init__(self, dirpath=".", maxRecursive=10): + def __init__(self, dirpath=".", maxRecursive=10, raiseonload=False): if maxRecursive <= 0: raise ValueError('Max recursion limit reached') self.dirpath = abspath(dirpath) self.maxRecursive = maxRecursive + self.raiseonload = raiseonload self.detected = False @@ -127,15 +128,22 @@ class IncludeStatement: raw_sql = f.read() f.close() except IOError, err: + # Raise the exception to the interpreter + if self.raiseonload: + raise + + # Put the exception as a comment on the SQL code yield Comment, u'-- IOError: %s\n' % err else: # Create new FilterStack to parse readed file # and add all its tokens to the main stack recursively - # [ToDo] Add maximum recursive iteration value + filtr = IncludeStatement(self.dirpath, + self.maxRecursive - 1, + self.raiseonload) + stack = FilterStack() - stack.preprocess.append(IncludeStatement(self.dirpath, - self.maxRecursive - 1)) + stack.preprocess.append(filtr) for tv in stack.run(raw_sql): yield tv -- cgit v1.2.1