/usr/lib/python3/dist-packages/astroML/datasets/tools/sql_query.py is in python3-astroml 0.3-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """
Tools to perform a SQL queries to an online server.
Default values are provided for http://cas.sdss.org
"""
from ...py3k_compat import urlencode, urlopen
PUBLIC_URL = 'http://cas.sdss.org/public/en/tools/search/x_sql.asp'
DEFAULT_FMT = 'csv'
def remove_sql_comments(sql):
"""Strip SQL comments starting with --"""
return ' \n'.join(map(lambda x: x.split('--')[0], sql.split('\n')))
def sql_query(sql_str, url=PUBLIC_URL, format='csv'):
"""Execute query
Parameters
----------
sql_str : string
valid sql query
url: string (optional)
query url. Default is http://cas.sdss.org query script
format: string (default='csv')
query output format
Returns
-------
F: file object
results of the query
"""
sql_str = remove_sql_comments(sql_str)
params = urlencode(dict(cmd=sql_str, format=format))
return urlopen(url + '?%s' % params)
|