def set_pref(real_user, user, key, value, use_real_user=True): class Pref(formencode.Schema): key = fv.MaxLength(64, not_empty=True) value = fv.MaxLength(64, not_empty=False) scrubbed = validate(Pref, key=key, value=value) u = user if use_real_user: u = real_user u.set_preference(scrubbed.key, scrubbed.value or '')
def explode_no_auth(real_user, user, type=None, **kw): """ An action to test the error handling of the stack. The tests use this. """ if type == 'app': raise AppException('This is an app exception!', code=INVALID, field='type') elif type == 'client': raise ClientException('Oh Noes, ClientException!', code=INVALID, field='type') elif type == 'client404': raise ClientException('Oh Noes, ClientException NOT FOUND!', code=NOT_FOUND, field='type') elif type == 'client403': raise ClientException('Oh Noes, ClientException FORBIDDEN!', code=FORBIDDEN, field='type') elif type == 'explosion': 1/0 elif type == 'http': abort(404, 'This thing was not found!') elif type == 'validation': class Rawr(formencode.Schema): meow = fv.Number() scrubbed = validate(Rawr, meow='zzzz') return kw