From 66df11633723d7c5e7bde27a4ad3e9fcdd692e7f Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Mon, 6 Jun 2016 18:57:17 -0700 Subject: Format `pr` to pass flake8 and update functions used --- sqlparse/filters_tmp.py | 74 ++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 34 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/filters_tmp.py b/sqlparse/filters_tmp.py index 6464391..b95cd9a 100644 --- a/sqlparse/filters_tmp.py +++ b/sqlparse/filters_tmp.py @@ -37,15 +37,11 @@ def StripWhitespace(stream): class InfoCreateTable(object): - # sqlparse outputs some tokens as Keyword type at places where they are names - ALLOWED_KEYWORD_AS_NAME = set(( - 'data', - 'source', - 'type', - )) + # sqlparse outputs some tokens as Keyword at places where they are names + ALLOWED_KEYWORD_AS_NAME = 'data', 'source', 'type' def process(self, stack, stream): - class St: + class St(object): create = 0 table = 1 table_name = 2 @@ -64,32 +60,32 @@ class InfoCreateTable(object): for token_type, value in StripWhitespace(stream): # Ignore comments - if token_type in (Comment, Whitespace): + if token_type in (T.Comment, T.Whitespace): continue if state == St.create: table_name = '' - columns = {} # index => (name, type) + columns = {} # index => (name, type) column_names = set() column = None - if token_type in Keyword and value.upper() == 'CREATE': + if token_type in T.Keyword and value.upper() == 'CREATE': state = St.table else: error = 'Not a CREATE statement' elif state == St.table: - if token_type in Keyword and value.upper() == 'TABLE': + if token_type in T.Keyword and value.upper() == 'TABLE': state = St.table_name else: error = 'Not a CREATE TABLE statement' elif state == St.table_name: - if token_type in Name: + if token_type in T.Name: state = St.create_table_open_paren table_name += value else: error = 'No table name given' elif state == St.create_table_open_paren: - if token_type in Punctuation: + if token_type in T.Punctuation: if value == '(': state = St.column_name elif value == '.': @@ -99,43 +95,47 @@ class InfoCreateTable(object): if state == St.create_table_open_paren: error = 'No opening paren for CREATE TABLE' elif state == St.column_name: - if token_type in Name or (token_type in Keyword and value.lower() in InfoCreateTable.ALLOWED_KEYWORD_AS_NAME): + if (token_type in T.Name or + (token_type in T.Keyword and value.lower() in + InfoCreateTable.ALLOWED_KEYWORD_AS_NAME)): column = [self._to_column_name(value), None, None] state = St.column_type - elif token_type in Keyword: + elif token_type in T.Keyword: state = St.ignore_rest else: error = 'No column name given' elif state == St.column_type: - if token_type in Name: + if token_type in T.Name: column[1] = value state = St.column_ignore_rest else: error = 'No column type given' elif state == St.ignore_rest: - if token_type in Punctuation: + if token_type in T.Punctuation: if value == '(': parens += 1 elif value == ')': - if parens == 0: # closes 'CREATE TABLE (' + if parens == 0: # closes 'CREATE TABLE (' state = St.finished else: parens -= 1 elif value == ',' and parens == 0: state = St.column_name elif state == St.column_ignore_rest: - if token_type in Punctuation and parens == 0: # ignore anything in parens + # ignore anything in parens + if token_type in T.Punctuation and parens == 0: add_column = False if value == '(': parens += 1 elif value == ')': - if parens == 0: # closes 'CREATE TABLE (' + # closes 'CREATE TABLE (' + if parens == 0: state = St.finished add_column = True - else: # pragma: no cover - error = 'Logic error (end of column declaration #1)' + else: + error = 'Logic error (end of column declaration#1)' elif value == ',': add_column = True @@ -150,43 +150,50 @@ class InfoCreateTable(object): columns[len(columns)] = tuple(column) column = None - elif token_type in Keyword and parens == 0: + elif token_type in T.Keyword and parens == 0: keyword_value = value.upper() if keyword_value in ('NULL', 'NOT NULL'): column[2] = keyword_value - elif token_type in Punctuation and parens > 0: + elif token_type in T.Punctuation and parens > 0: # ignore anything in parens if value == '(': parens += 1 elif value == ')': parens -= 1 - # else ignore until comma or end of statement + # else ignore until comma or end of statement elif state == St.finished: - # Finished one CREATE TABLE statement, yield result and try to parse next statement + # Finished one CREATE TABLE statement, + # yield result and try to parse next statement # (after semicolon) yield (table_name, columns) - if token_type in Punctuation and value == ';': + if token_type in T.Punctuation and value == ';': state = St.create else: state = St.ignore_remaining_statement elif state == St.ignore_remaining_statement: # Ignore until semicolon - if token_type in Punctuation and value == ';': + if token_type in T.Punctuation and value == ';': state = St.create - else: # pragma: no cover + else: error = 'Unknown state %r' % state if error: - raise ValueError('%s (token_type: %r, value: %r, column: %r)' % (error, token_type, value, column)) + raise ValueError( + '%s (token_type: %r, value: %r, column: %r)' % ( + error, token_type, value, column)) if not error: - if state == St.finished: # no more tokens after ')' + # no more tokens after ')' + if state == St.finished: yield (table_name, columns) - if state not in (St.create, St.finished, St.ignore_remaining_statement): - error = 'Unexpected end state %r (token_type: %r, value: %r, column: %r)' % (state, token_type, value, column) + if state not in ( + St.create, St.finished, St.ignore_remaining_statement): + error = ('Unexpected end state %r (token_type: ' + '%r, value: %r, column: %r)' % ( + state, token_type, value, column)) if error: raise ValueError(error) @@ -194,4 +201,3 @@ class InfoCreateTable(object): @staticmethod def _to_column_name(token_value): return token_value.strip(u'`ยด') - -- cgit v1.2.1