> For my usage, anyway, the "otherwise" parameter is just as relevant in > either case. I see args and vars as parallel to passing arguments to > Python functions by position and by keyword. >
Understood, but because request.args are part of the URL path, it is more likely that they will be required for a valid resource to be returned, whereas URLs that include query strings typically return some resource even without the query string (i.e., at the base URL). > In either case, I might want to raise an error if a given argument is > not present. But unlike when calling a plain Python function, web2py > doesn't provide a builtin way to validate the arguments of a request (i.e., > as far as I can tell, there's no way to stipulate that a given controller > function requires particular arguments, in the URL path or query string). > So "otherwise" can provide a way to do what would normally be done by > Python's enforcement of a function's call signature, but with the extra > flexibility of potentially raising different errors for different kinds of > mismatch. > If you want to validate a set of required arguments, there are probably better ways than making separate calls to a method for each argument. I would write a generalized function or a decorator to take some specification and confirm that request.args and request.vars meet the specification. Anyway, right now, instead of: myvar = request.vars('myvar', otherwise=URL('default', 'other')) you can simply do: myvar = request.vars.myvar or redirect(URL('default', 'other')) Anyway, how are you using BetterStorage? Your initial post referred >> specifically to request.vars -- are you converting request.vars to >> BetterStorage? In that case, it might be simpler to write a function rather >> than a whole new class just for this purpose. >> > > Not sure what you mean by "a whole new class". My BetterStorage class > inherits from Storage, and adds nothing except the __call__ method. So I > essentially did just write a function, but putting that function as a > method on a class lets me inherit all the existing functionality of Storage. > Sure, just a matter of preference -- I tend to go for a function if a class doesn't add any further benefit. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.