diff options
| author | Jesús Leganés Combarro "Piranna" <jesus.lc@vaelsys.com> | 2012-05-17 17:01:47 +0200 |
|---|---|---|
| committer | Jesús Leganés Combarro "Piranna" <jesus.lc@vaelsys.com> | 2012-05-17 17:01:47 +0200 |
| commit | 0aba698a5275f9c437f3142af1c29b5aab387de0 (patch) | |
| tree | 1037b44de9810032844a2a92f70167025da87b74 /sqlparse | |
| parent | f141b2d344bbd09a7469d5c9ecffb38ed6ccd618 (diff) | |
| download | sqlparse-0aba698a5275f9c437f3142af1c29b5aab387de0.tar.gz | |
Option to embeb exception on recursion limit
Diffstat (limited to 'sqlparse')
| -rw-r--r-- | sqlparse/filters.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py index e17766d..17dc960 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -92,13 +92,13 @@ def StripWhitespace(stream): class IncludeStatement: """Filter that enable a INCLUDE statement""" - def __init__(self, dirpath=".", maxRecursive=10, raiseonload=False): + def __init__(self, dirpath=".", maxRecursive=10, raiseexceptions=False): if maxRecursive <= 0: raise ValueError('Max recursion limit reached') self.dirpath = abspath(dirpath) self.maxRecursive = maxRecursive - self.raiseonload = raiseonload + self.raiseexceptions = raiseexceptions self.detected = False @@ -127,9 +127,11 @@ class IncludeStatement: f = open(path) raw_sql = f.read() f.close() + + # There was a problem loading the include file except IOError, err: # Raise the exception to the interpreter - if self.raiseonload: + if self.raiseexceptions: raise # Put the exception as a comment on the SQL code @@ -138,9 +140,19 @@ class IncludeStatement: else: # Create new FilterStack to parse readed file # and add all its tokens to the main stack recursively - filtr = IncludeStatement(self.dirpath, - self.maxRecursive - 1, - self.raiseonload) + try: + filtr = IncludeStatement(self.dirpath, + self.maxRecursive - 1, + self.raiseexceptions) + + # Max recursion limit reached + except ValueError, err: + # Raise the exception to the interpreter + if self.raiseexceptions: + raise + + # Put the exception as a comment on the SQL code + yield Comment, u'-- ValueError: %s\n' % err stack = FilterStack() stack.preprocess.append(filtr) |
