Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_convert_options_post_request_with_dictionary_params(self):
options = {'params': {'foo': {'bar': 'baz'}}}
expected_result = {'json': {'foo.bar': 'baz'}}
result = Util.convert_options(request_type='post', **options)
self.assertEqual(cmp(result, expected_result), 0)
def convert_options(request_type, **options):
if request_type == 'get':
return Util._convert_options_for_get_request(**options)
elif request_type == 'post':
return Util._convert_options_for_post_request(**options)
else:
raise Exception('Can only convert options for get or post requests')
def request(cls, http_verb, url, **options):
if 'headers' in options:
headers = options['headers']
else:
headers = {}
accept_value = 'application/json'
if ApiConfig.api_version:
accept_value += ", application/vnd.quandl+json;version=%s" % ApiConfig.api_version
headers = Util.merge_to_dicts({'accept': accept_value,
'request-source': 'python',
'request-source-version': VERSION}, headers)
if ApiConfig.api_key:
headers = Util.merge_to_dicts({'x-api-token': ApiConfig.api_key}, headers)
options['headers'] = headers
abs_url = '%s/%s' % (ApiConfig.api_base, url)
return cls.execute_request(http_verb, abs_url, **options)
def convert_to_dates(dic_or_list):
if isinstance(dic_or_list, dict):
for k, v in list(dic_or_list.items()):
dic_or_list[k] = Util.convert_to_dates(v)
elif isinstance(dic_or_list, list):
for idx, v in enumerate(dic_or_list):
dic_or_list[idx] = Util.convert_to_dates(v)
else:
return Util.convert_to_date(dic_or_list)
return dic_or_list
def convert_options(request_type, **options):
if request_type == 'get':
return Util._convert_options_for_get_request(**options)
elif request_type == 'post':
return Util._convert_options_for_post_request(**options)
else:
raise Exception('Can only convert options for get or post requests')
def datasets(self, **options):
params = {'database_code': self.code, 'query': '', 'page': 1}
options = Util.merge_options('params', params, **options)
return quandl.model.dataset.Dataset.all(**options)
def convert_to_dates(dic_or_list):
if isinstance(dic_or_list, dict):
for k, v in list(dic_or_list.items()):
dic_or_list[k] = Util.convert_to_dates(v)
elif isinstance(dic_or_list, list):
for idx, v in enumerate(dic_or_list):
dic_or_list[idx] = Util.convert_to_dates(v)
else:
return Util.convert_to_date(dic_or_list)
return dic_or_list
def __init__(self, klass, values, meta):
self.klass = klass
if 'columns' in meta.keys():
meta['column_types'] = Util.convert_to_columns_list(meta['columns'], 'type')
meta['columns'] = Util.convert_to_columns_list(meta['columns'], 'name')
# Since we are iterating over a list of data be sure to only compute the
# methodized column names once and pass that down to the objects that are being created.
converted_column_names = Util.convert_column_names(meta)
if hasattr(klass, 'get_code_from_meta'):
self.values = list([klass(
klass.get_code_from_meta(x),
x,
meta=meta,
converted_column_names=converted_column_names
) for x in values])
else:
self.values = list([klass(
x,