Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def validate_python(self, value, state):
raise validators.Invalid('ERROR: Description', value, state)
except ValueError:
wiki_in_url = -1
if wiki_in_url >= len(url_parts) - 2:
value = '/'.join(url_parts[:wiki_in_url])
# normalize trailing slash
value = value.rstrip('/') + '/'
try:
resp = requests.head(value, allow_redirects=True, timeout=10)
except IOError:
# fall through to 'raise' below
pass
else:
if resp.status_code == 200:
return value
raise fev.Invalid(self.message('unavailable', state), value, state)
def to_python(self, value, state=None):
value = super(ToolsValidator, self).to_python(value, state)
valid = []
invalid = []
for name in value:
importer = ToolImporter.by_name(name)
if importer is not None and importer.source == self.source:
valid.append(name)
else:
invalid.append(name)
if invalid:
pl = 's' if len(invalid) > 1 else ''
raise fev.Invalid('Invalid tool%s selected: %s' %
(pl, ', '.join(invalid)), value, state)
return valid
def _invalid(self, value, state):
message = "please choose an item from the list"
raise v.Invalid(message, value, state)
if value is None:
return None
if isinstance(value, float):
value = str(value)
if isinstance(value, string_type):
try:
connection = state.connection or state.soObject._connection
except AttributeError:
pass
else:
if hasattr(connection, "decimalSeparator"):
value = value.replace(connection.decimalSeparator, ".")
try:
return Decimal(value)
except Exception:
raise validators.Invalid(
"can not parse Decimal value '%s' "
"in the DecimalCol from '%s'" % (
value, getattr(state, 'soObject', '(unknown)')),
value, state)
if isinstance(value, (int, long, Decimal, sqlbuilder.SQLExpression)):
return value
raise validators.Invalid(
"expected a Decimal in the DecimalCol '%s', got %s %r instead" % (
self.name, type(value), value), value, state)
@app.route('/save_template/', methods=['POST'])
def save_template(doc_id):
doc = couch.PonyExpressTemplate.get(doc_id)
try:
form = TemplateForm.to_python(request.form)
except formencode.validators.Invalid, error:
return str(error)
else:
doc.contents = []
for k,v in form.iteritems():
if not k == 'contents':
setattr(doc, k, v)
elif k == 'contents':
for content in v:
if all([content.get(key, None) for key in ('lang','subject','body')]):
doc.contents.append(couch.LocalTemplate(**content))
doc.save()
return redirect(url_for('view_template', doc_id=doc._id))
if value is None:
return None
if isinstance(value, float):
value = str(value)
if isinstance(value, basestring):
try:
connection = state.connection or state.soObject._connection
except AttributeError:
pass
else:
if hasattr(connection, "decimalSeparator"):
value = value.replace(connection.decimalSeparator, ".")
try:
return Decimal(value)
except:
raise validators.Invalid("can not parse Decimal value '%s' in the DecimalCol from '%s'" %
(value, getattr(state, 'soObject', '(unknown)')), value, state)
if isinstance(value, (int, long, Decimal, sqlbuilder.SQLExpression)):
return value
raise validators.Invalid("expected a Decimal in the DecimalCol '%s', got %s %r instead" % \
(self.name, type(value), value), value, state)
@classmethod
def _to_formencode_invalid(cls, ming_invalid):
if ming_invalid.error_dict:
return fev.Invalid(
ming_invalid.msg,
ming_invalid.value, ming_invalid.state,
error_dict=dict(
(k, cls._to_formencode_invalid(v))
for k,v in ming_invalid.error_dict.items()))
elif ming_invalid.error_list:
return fev.Invalid(
ming_invalid.msg,
ming_invalid.value, ming_invalid.state,
error_list=map(cls._to_formencode_invalid, ming_invalid.error_list))
else:
return fev.Invalid(
ming_invalid.msg,
ming_invalid.value, ming_invalid.state)
flash('Cannot delete the admin tool, sorry....')
redirect('.')
c.project.uninstall_app(self.app.config.options.mount_point)
redirect('..')
for opt in self.app.config_options:
if opt in Application.config_options:
# skip base options (mount_point, mount_label, ordinal)
continue
val = kw.get(opt.name, '')
if opt.ming_type == bool:
val = asbool(val or False)
elif opt.ming_type == int:
val = asint(val or 0)
try:
val = opt.validate(val)
except fev.Invalid as e:
flash(u'{}: {}'.format(opt.name, str(e)), 'error')
continue
self.app.config.options[opt.name] = val
if is_admin:
# possibly moving admin mount point
redirect('/'
+ c.project._id
+ self.app.config.options.mount_point
+ '/'
+ self.app.config.options.mount_point
+ '/')
else:
redirect(request.referer or '/')
@classmethod
def _to_formencode_invalid(cls, ming_invalid):
if ming_invalid.error_dict:
return fev.Invalid(
ming_invalid.msg,
ming_invalid.value, ming_invalid.state,
error_dict=dict(
(k, cls._to_formencode_invalid(v))
for k,v in ming_invalid.error_dict.items()))
elif ming_invalid.error_list:
return fev.Invalid(
ming_invalid.msg,
ming_invalid.value, ming_invalid.state,
error_list=map(cls._to_formencode_invalid, ming_invalid.error_list))
else:
return fev.Invalid(
ming_invalid.msg,
ming_invalid.value, ming_invalid.state)