mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-09-03 20:52:57 -05:00
Code tidy.
This commit is contained in:
@@ -455,7 +455,7 @@ class SQLAutoComplete(object):
|
||||
status, res = self.conn.execute_dict(query)
|
||||
if status:
|
||||
for record in res['rows']:
|
||||
columns.append(record['column_name'])
|
||||
columns.append(record['column_name'])
|
||||
else:
|
||||
# Schema not specified, so traverse the search path looking for
|
||||
# a table or view that matches. Note that in order to get proper
|
||||
@@ -503,7 +503,7 @@ class SQLAutoComplete(object):
|
||||
status, res = self.conn.execute_dict(query)
|
||||
if status:
|
||||
for record in res['rows']:
|
||||
columns.append(record['column_name'])
|
||||
columns.append(record['column_name'])
|
||||
|
||||
return columns
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class Completion(object):
|
||||
:param get_display_meta: Lazy `display_meta`. Retrieve meta information
|
||||
only when meta is displayed.
|
||||
"""
|
||||
|
||||
def __init__(self, text, start_position=0, display=None, display_meta=None,
|
||||
get_display_meta=None):
|
||||
self.text = text
|
||||
|
||||
@@ -87,7 +87,7 @@ class Counter(dict):
|
||||
for elem, count in iterable.iteritems():
|
||||
self[elem] = self_get(elem, 0) + count
|
||||
else:
|
||||
dict.update(self, iterable) # fast path when counter is empty
|
||||
dict.update(self, iterable) # fast path when counter is empty
|
||||
else:
|
||||
self_get = self.get
|
||||
for elem in iterable:
|
||||
|
||||
@@ -7,7 +7,6 @@ table_def_regex = re.compile(r'^TABLE\s*\((.+)\)$', re.IGNORECASE)
|
||||
|
||||
|
||||
class FunctionMetadata(object):
|
||||
|
||||
def __init__(self, schema_name, func_name, arg_list, return_type, is_aggregate,
|
||||
is_window, is_set_returning):
|
||||
"""Class for describing a postgresql function"""
|
||||
@@ -29,8 +28,8 @@ class FunctionMetadata(object):
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.schema_name, self.func_name, self.arg_list,
|
||||
self.return_type, self.is_aggregate, self.is_window,
|
||||
self.is_set_returning))
|
||||
self.return_type, self.is_aggregate, self.is_window,
|
||||
self.is_set_returning))
|
||||
|
||||
def __repr__(self):
|
||||
return (('%s(schema_name=%r, func_name=%r, arg_list=%r, return_type=%r,'
|
||||
|
||||
@@ -6,15 +6,15 @@ from sqlparse.sql import IdentifierList, Identifier, Function
|
||||
from sqlparse.tokens import Keyword, DML, Punctuation, Token, Error
|
||||
|
||||
cleanup_regex = {
|
||||
# This matches only alphanumerics and underscores.
|
||||
'alphanum_underscore': re.compile(r'(\w+)$'),
|
||||
# This matches everything except spaces, parens, colon, and comma
|
||||
'many_punctuations': re.compile(r'([^():,\s]+)$'),
|
||||
# This matches everything except spaces, parens, colon, comma, and period
|
||||
'most_punctuations': re.compile(r'([^\.():,\s]+)$'),
|
||||
# This matches everything except a space.
|
||||
'all_punctuations': re.compile('([^\s]+)$'),
|
||||
}
|
||||
# This matches only alphanumerics and underscores.
|
||||
'alphanum_underscore': re.compile(r'(\w+)$'),
|
||||
# This matches everything except spaces, parens, colon, and comma
|
||||
'many_punctuations': re.compile(r'([^():,\s]+)$'),
|
||||
# This matches everything except spaces, parens, colon, comma, and period
|
||||
'most_punctuations': re.compile(r'([^\.():,\s]+)$'),
|
||||
# This matches everything except a space.
|
||||
'all_punctuations': re.compile('([^\s]+)$'),
|
||||
}
|
||||
|
||||
|
||||
def last_word(text, include='alphanum_underscore'):
|
||||
@@ -51,7 +51,7 @@ def last_word(text, include='alphanum_underscore'):
|
||||
'"foo*bar'
|
||||
"""
|
||||
|
||||
if not text: # Empty string
|
||||
if not text: # Empty string
|
||||
return ''
|
||||
|
||||
if text[-1].isspace():
|
||||
@@ -118,7 +118,7 @@ def extract_from_part(parsed, stop_at_punctuation=True):
|
||||
elif isinstance(item, IdentifierList):
|
||||
for identifier in item.get_identifiers():
|
||||
if (identifier.ttype is Keyword and
|
||||
identifier.value.upper() == 'FROM'):
|
||||
identifier.value.upper() == 'FROM'):
|
||||
tbl_prefix_seen = True
|
||||
break
|
||||
|
||||
@@ -202,7 +202,7 @@ def find_prev_keyword(sql):
|
||||
|
||||
for t in reversed(flattened):
|
||||
if t.value == '(' or (t.is_keyword and (
|
||||
t.value.upper() not in logical_operators)):
|
||||
t.value.upper() not in logical_operators)):
|
||||
# Find the location of token t in the original parsed statement
|
||||
# We can't use parsed.token_index(t) because t may be a child token
|
||||
# inside a TokenList, in which case token_index thows an error
|
||||
@@ -215,7 +215,7 @@ def find_prev_keyword(sql):
|
||||
# Combine the string values of all tokens in the original list
|
||||
# up to and including the target keyword token t, to produce a
|
||||
# query string with everything after the keyword token removed
|
||||
text = ''.join(tok.value for tok in flattened[:idx+1])
|
||||
text = ''.join(tok.value for tok in flattened[:idx + 1])
|
||||
return t, text
|
||||
|
||||
return None, ''
|
||||
@@ -245,7 +245,7 @@ def _parsed_is_open_quote(parsed):
|
||||
elif (tok.ttype in Token.Name.Builtin
|
||||
and dollar_quote_regex.match(tok.value)):
|
||||
# Find the matching closing dollar quote sign
|
||||
for (j, tok2) in enumerate(tokens[i+1:], i+1):
|
||||
for (j, tok2) in enumerate(tokens[i + 1:], i + 1):
|
||||
if tok2.match(Token.Name.Builtin, tok.value):
|
||||
# Found the matching closing quote - continue our scan for
|
||||
# open quotes thereafter
|
||||
|
||||
@@ -45,6 +45,3 @@ class PrevalenceCounter(object):
|
||||
|
||||
def name_count(self, name):
|
||||
return self.name_counts[name]
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user