Validates options.
(options)
| 12 | |
| 13 | |
| 14 | def validate_options(options): # noqa: C901 |
| 15 | """Validates options.""" |
| 16 | kwcase = options.get('keyword_case') |
| 17 | if kwcase not in [None, 'upper', 'lower', 'capitalize']: |
| 18 | raise SQLParseError('Invalid value for keyword_case: ' |
| 19 | '{!r}'.format(kwcase)) |
| 20 | |
| 21 | idcase = options.get('identifier_case') |
| 22 | if idcase not in [None, 'upper', 'lower', 'capitalize']: |
| 23 | raise SQLParseError('Invalid value for identifier_case: ' |
| 24 | '{!r}'.format(idcase)) |
| 25 | |
| 26 | ofrmt = options.get('output_format') |
| 27 | if ofrmt not in [None, 'sql', 'python', 'php']: |
| 28 | raise SQLParseError('Unknown output format: ' |
| 29 | '{!r}'.format(ofrmt)) |
| 30 | |
| 31 | strip_comments = options.get('strip_comments', False) |
| 32 | if strip_comments not in [True, False]: |
| 33 | raise SQLParseError('Invalid value for strip_comments: ' |
| 34 | '{!r}'.format(strip_comments)) |
| 35 | |
| 36 | space_around_operators = options.get('use_space_around_operators', False) |
| 37 | if space_around_operators not in [True, False]: |
| 38 | raise SQLParseError('Invalid value for use_space_around_operators: ' |
| 39 | '{!r}'.format(space_around_operators)) |
| 40 | |
| 41 | strip_ws = options.get('strip_whitespace', False) |
| 42 | if strip_ws not in [True, False]: |
| 43 | raise SQLParseError('Invalid value for strip_whitespace: ' |
| 44 | '{!r}'.format(strip_ws)) |
| 45 | |
| 46 | truncate_strings = options.get('truncate_strings') |
| 47 | if truncate_strings is not None: |
| 48 | try: |
| 49 | truncate_strings = int(truncate_strings) |
| 50 | except (ValueError, TypeError): |
| 51 | raise SQLParseError('Invalid value for truncate_strings: ' |
| 52 | '{!r}'.format(truncate_strings)) |
| 53 | if truncate_strings <= 1: |
| 54 | raise SQLParseError('Invalid value for truncate_strings: ' |
| 55 | '{!r}'.format(truncate_strings)) |
| 56 | options['truncate_strings'] = truncate_strings |
| 57 | options['truncate_char'] = options.get('truncate_char', '[...]') |
| 58 | |
| 59 | indent_columns = options.get('indent_columns', False) |
| 60 | if indent_columns not in [True, False]: |
| 61 | raise SQLParseError('Invalid value for indent_columns: ' |
| 62 | '{!r}'.format(indent_columns)) |
| 63 | elif indent_columns: |
| 64 | options['reindent'] = True # enforce reindent |
| 65 | options['indent_columns'] = indent_columns |
| 66 | |
| 67 | reindent = options.get('reindent', False) |
| 68 | if reindent not in [True, False]: |
| 69 | raise SQLParseError('Invalid value for reindent: ' |
| 70 | '{!r}'.format(reindent)) |
| 71 | elif reindent: |
nothing calls this directly
no test coverage detected
searching dependent graphs…