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_returns_true_on_valid_length(value, min, max):
assert validators.length(value, min=min, max=max)
def test_returns_failed_validation_on_invalid_range(value, min, max):
assert isinstance(
validators.length(value, min=min, max=max),
validators.ValidationFailure
)
def test_raises_assertion_error_for_invalid_args(value, min, max):
with pytest.raises(AssertionError):
assert validators.length(value, min=min, max=max)
def request_form(hash_map):
"""
"""
form = request.form
message = None
name = form['name']
hash_map['name'] = name
hash_map['value'] = {}
if not length(name, 2, 20):
message = 'nada 1'
elif not username(name):
message = 'nada 2'
list_label = [ int(x.split('_')[3]) for x in form if x.startswith('label_name_') ]
if len(list_label) > 0:
len_label = max(list_label) + 1
for i in range(len_label):
i = str(i)
if 'label_name_'+g.lan+'_'+i in form:
key = form['label_name_'+g.lan+'_'+i].strip()
if not length(key, 2, 20):
message = 'nada 3'
if not length(name, 2, 20):
message = 'nada 1'
elif not username(name):
message = 'nada 2'
list_label = [ int(x.split('_')[3]) for x in form if x.startswith('label_name_') ]
if len(list_label) > 0:
len_label = max(list_label) + 1
for i in range(len_label):
i = str(i)
if 'label_name_'+g.lan+'_'+i in form:
key = form['label_name_'+g.lan+'_'+i].strip()
if not length(key, 2, 20):
message = 'nada 3'
elif not username(key):
message = 'nada 4'
hash_map['value'][key] = {}
for code in LIST_LANGUAGES:
if 'label_name_'+code+'_'+i in form:
value = form['label_'+code+'_'+i]
hash_map['value'][key][code] = value
else:
hash_map['value'][key][code] = ''
if message is None:
return (message, hash_map)
def set_token(auth_token):
"""
Configure EvalAI Token.
"""
"""
Invoked by `evalai set_token `.
"""
if validators.length(auth_token, min=LEN_OF_TOKEN, max=LEN_OF_TOKEN):
if not os.path.exists(AUTH_TOKEN_DIR):
os.makedirs(AUTH_TOKEN_DIR)
with open(AUTH_TOKEN_PATH, "w+") as fw:
try:
auth_token = {"token": "{}".format(auth_token)} # noqa
auth_token = json.dumps(auth_token)
fw.write(auth_token)
except (OSError, IOError) as e:
echo(e)
echo(
style(
"Success: Authentication token is successfully set.",
bold=True,
fg="green",
)
)