Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _api_call(self, method, path, wrap_args=None, user='test-admin', status=None, **params):
'''
If you need to use one of the method kwargs as a URL parameter,
pass params={...} as a dict instead of **kwargs
'''
if 'params' in params:
params = params['params']
if wrap_args:
params = {wrap_args: params}
if status is None:
status = [200, 201, 301, 302]
params = variabledecode.variable_encode(params, add_repetitions=False)
token = self.token(user).api_key
headers = {
'Authorization': 'Bearer {}'.format(token)
}
fn = getattr(self.app, method.lower())
response = fn(
str(path),
params=params,
headers=headers,
status=status)
if response.status_int in [301, 302]:
return response.follow()
else:
def _api_getpost(self, method, path, wrap_args=None, user='test-admin', status=None, **params):
'''
If you need to use one of the method kwargs as a URL parameter,
pass params={...} as a dict instead of **kwargs
'''
if 'params' in params:
params = params['params']
if wrap_args:
params = {wrap_args: params}
if status is None:
status = [200, 201, 301, 302, 400, 403, 404]
params = variabledecode.variable_encode(params, add_repetitions=False)
params['access_token'] = self.token(user).api_key
fn = self.app.post if method == 'POST' else self.app.get
response = fn(
str(path),
params=params,
status=status)
if response.status_int in [301, 302]:
return response.follow()
else:
return response
def test_variable_decode(self):
from formencode.variabledecode import variable_encode
obj = dict(a=['1','2','3'], b=dict(c=[dict(d='1')]))
params = variable_encode(dict(obj=obj), add_repetitions=False)
resp = self.app.get('/test_vardec', params=params)
assert resp.json['obj'] == obj, (resp.json['obj'], obj)
"""
from __future__ import print_function
import os
from django.core.management import setup_environ
from example.settings import local
setup_environ(local)
from django.conf import settings
from formencode.variabledecode import variable_encode
env_dict = variable_encode(settings.MERCHANT_SETTINGS, prepend='MERCHANT', dict_char='__')
for k, v in env_dict.iteritems():
print('adding %s' % (k))
os.system('travis encrypt %s="%s" --add env.global' % (k, v))
def __init__(self, method, path, params=None, **kwargs):
if params is None:
params = {}
params = variabledecode.variable_encode(
params, add_repetitions=False)
params = client.sign_request(path, params)
self._method = method.upper()
if self._method == 'GET':
url = urljoin(client.base_uri, path) + \
'?' + urlencode(params)
data = None
else:
url = urljoin(client.base_uri, path)
data = urlencode(params)
urllib2.Request.__init__(self, url, data=data, **kwargs)
def coerce_vars(self, vars):
global variabledecode
need_variable_encode = False
for key, value in vars.items():
if isinstance(value, dict):
need_variable_encode = True
if key.endswith('_'):
vars[key[:-1]] = vars[key]
del vars[key]
if need_variable_encode:
if variabledecode is None:
from formencode import variabledecode
vars = variabledecode.variable_encode(vars)
return vars
self.m = g.p.connect()
c.outputs = self.m.outputs()
for o in c.outputs:
if o['outputenabled'] == '1':
key = 'enabled'
else:
key = 'disabled'
configured_outputs.append({key: o['outputid']})
except ConnectionClosed:
return render('/null.html')
if use_htmlfill:
values = formencode.variabledecode.variable_encode({'firsttime': c.firsttime, 'server':g.tc.server,
'port':g.tc.port,
'password':g.tc.password,'webpassword':g.tc.webpassword,
'awskey':g.tc.awskey,'timeout':g.tc.timeout,
'aws_secret':g.tc.aws_secret,
'default_search':g.tc.default_search,
'outputs': configured_outputs})
return formencode.htmlfill.render(render("/config.html"), values)
else:
return render("/config.html")