diff options
author | Jesús Leganés Combarro "Piranna" <jesus.lc@vaelsys.com> | 2012-05-18 11:47:38 +0200 |
---|---|---|
committer | Jesús Leganés Combarro "Piranna" <jesus.lc@vaelsys.com> | 2012-05-18 11:47:38 +0200 |
commit | 9424d8177020db5fd15e48e95226e9e53ef7ce34 (patch) | |
tree | ee5aeecbfdbdc77c024db7f73d93f90de20bea0c | |
parent | 363e0f711f8662dadc0ec1d98d0f3bbd4d105768 (diff) | |
download | sqlparse-9424d8177020db5fd15e48e95226e9e53ef7ce34.tar.gz |
Added comments to separate each option
-rw-r--r-- | sqlparse/formatter.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sqlparse/formatter.py b/sqlparse/formatter.py index 5be6652..f8563a6 100644 --- a/sqlparse/formatter.py +++ b/sqlparse/formatter.py @@ -11,34 +11,43 @@ from sqlparse import filters def validate_options(options): """Validates options.""" + + # keyword_case kwcase = options.get('keyword_case', None) if kwcase not in [None, 'upper', 'lower', 'capitalize']: raise SQLParseError('Invalid value for keyword_case: %r' % kwcase) + # identifier_case idcase = options.get('identifier_case', None) if idcase not in [None, 'upper', 'lower', 'capitalize']: raise SQLParseError('Invalid value for identifier_case: %r' % idcase) + # output_format ofrmt = options.get('output_format', None) if ofrmt not in [None, 'sql', 'python', 'php']: raise SQLParseError('Unknown output format: %r' % ofrmt) + # strip_comments strip_comments = options.get('strip_comments', False) if strip_comments not in [True, False]: raise SQLParseError('Invalid value for strip_comments: %r' % strip_comments) + # strip_whitespace strip_ws = options.get('strip_whitespace', False) if strip_ws not in [True, False]: raise SQLParseError('Invalid value for strip_whitespace: %r' % strip_ws) + # reindent reindent = options.get('reindent', False) if reindent not in [True, False]: raise SQLParseError('Invalid value for reindent: %r' % reindent) elif reindent: options['strip_whitespace'] = True + + # indent_tabs indent_tabs = options.get('indent_tabs', False) if indent_tabs not in [True, False]: raise SQLParseError('Invalid value for indent_tabs: %r' % indent_tabs) @@ -46,15 +55,20 @@ def validate_options(options): options['indent_char'] = '\t' else: options['indent_char'] = ' ' + + # indent_width indent_width = options.get('indent_width', 2) try: indent_width = int(indent_width) except (TypeError, ValueError): raise SQLParseError('indent_width requires an integer') + if indent_width < 1: raise SQLParseError('indent_width requires an positive integer') + options['indent_width'] = indent_width + # right_margin right_margin = options.get('right_margin', None) if right_margin is not None: try: @@ -65,6 +79,7 @@ def validate_options(options): raise SQLParseError('right_margin requires an integer > 10') options['right_margin'] = right_margin + # return the processed options return options |