Edgewall Software

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 Ryan J Ollos)

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 if name not in dict
    • Return default if exception raised converting self[name] to an int
  • getint(self, name, default=None, min=None, max=None)
    • Return default if name not in dict
    • Raise HTTPBadRequest if exception is raised converting self[name] to an int

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.

Change History (1)

comment:1 by Ryan J Ollos, 8 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.