Opened 8 years ago
Last modified 7 years ago
#12426 closed enhancement
Add as_int and as_bool methods to the Request class — at Version 1
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.2 |
Component: | web frontend | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description (last modified by )
comment:5:ticket:12325 suggested adding as_int
and as_bool
methods to the Request
class. This was discussed further a bit later in the ticket.
as_int
and as_bool
in trac.util
do not raise exceptions. Perhaps we should be somewhat consistent with the interface of those functions. We could add two pairs of methods with the following behaviors:
as_int(self, name, default=None, min=None, max=None)
- Return
default
ifname
not in dict - Return
default
if exception raised convertingself[name]
to an int
- Return
getint(self, name, default=None, min=None, max=None)
- Return
default
ifname
not in dict - Raise
HTTPBadRequest
if exception is raised convertingself[name]
to an int
- Return
get_int
would be a better name, but getint
is more consistent with getfirst
and getlist
. Also it seems reasonable to expect that a get
method might raise an exception.