Skip to content

Commit

Permalink
Python: rewrited some functions to static, fixed missed commas in saf…
Browse files Browse the repository at this point in the history
…e_builtins
  • Loading branch information
Vladislav Denisov committed Jan 11, 2017
1 parent ba51ff9 commit 265e912
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions query_runner/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def __call__(self):
class Python(BaseQueryRunner):
safe_builtins = (
'sorted', 'reversed', 'map', 'reduce', 'any', 'all',
'slice', 'filter', 'len', 'next', 'enumerate'
'sum', 'abs', 'min', 'max', 'round', 'cmp', 'divmod'
'slice', 'filter', 'len', 'next', 'enumerate',
'sum', 'abs', 'min', 'max', 'round', 'cmp', 'divmod',
'str', 'unicode', 'int', 'float', 'complex',
'tuple', 'set', 'list', 'dict', 'bool',
)
Expand Down Expand Up @@ -101,20 +101,24 @@ def custom_import(self, name, globals=None, locals=None, fromlist=(), level=0):

raise Exception("'{0}' is not configured as a supported import module".format(name))

def custom_write(self, obj):
@staticmethod
def custom_write(obj):
"""
Custom hooks which controls the way objects/lists/tuples/dicts behave in
RestrictedPython
"""
return obj

def custom_get_item(self, obj, key):
@staticmethod
def custom_get_item(obj, key):
return obj[key]

def custom_get_iter(self, obj):
@staticmethod
def custom_get_iter(obj):
return iter(obj)

def add_result_column(self, result, column_name, friendly_name, column_type):
@staticmethod
def add_result_column(result, column_name, friendly_name, column_type):
"""Helper function to add columns inside a Python script running in Redash in an easier way
Parameters:
Expand All @@ -135,7 +139,8 @@ def add_result_column(self, result, column_name, friendly_name, column_type):
"type": column_type
})

def add_result_row(self, result, values):
@staticmethod
def add_result_row(result, values):
"""Helper function to add one row to results set.
Parameters:
Expand All @@ -147,7 +152,8 @@ def add_result_row(self, result, values):

result["rows"].append(values)

def execute_query(self, data_source_name_or_id, query):
@staticmethod
def execute_query(data_source_name_or_id, query):
"""Run query from specific data source.
Parameters:
Expand All @@ -170,7 +176,8 @@ def execute_query(self, data_source_name_or_id, query):
# TODO: allow avoiding the json.dumps/loads in same process
return json.loads(data)

def get_source_schema(self, data_source_name_or_id):
@staticmethod
def get_source_schema(data_source_name_or_id):
"""Get schema from specific data source.
:param data_source_name_or_id: string|integer: Name or ID of the data source
Expand All @@ -186,7 +193,8 @@ def get_source_schema(self, data_source_name_or_id):
schema = data_source.query_runner.get_schema()
return schema

def get_query_result(self, query_id):
@staticmethod
def get_query_result(query_id):
"""Get result of an existing query.
Parameters:
Expand Down

0 comments on commit 265e912

Please sign in to comment.