Contact: fumanchu@aminus.org

Log in as guest/misc to create tickets

Changeset 22

Show
Ignore:
Timestamp:
12/10/05 01:19:54
Author:
fumanchu
Message:

More-meaningful error on coerce_in exceptions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • alamode.py

    r21 r22  
    378378missing=object() 
    379379 
     380typenames = {'int': 'a whole number', 
     381             'long': 'a whole number', 
     382             'date': 'a date (of the form m/d/yyyy)', 
     383             'datetime': 'a date and time (of the form m/d/yyyy hh:mm:ss)', 
     384             'FixedPoint': 'a dollar amount', 
     385             'decimal': 'a dollar amount', 
     386             } 
     387 
    380388def coerce_in(paramMap, key, type, default=missing): 
    381389    """coerce_in(paramMap, key, type, default=missing) -> instance of type. 
     
    393401        else: 
    394402            return default 
    395     return from_html.coerce(value, type) 
     403     
     404    try: 
     405        coerced = from_html.coerce(value, type) 
     406    except Exception, x: 
     407        msg = ("The value named '%s' should be %s, but the supplied value " 
     408               "(%s) could not be converted to that type.") 
     409        tname = type.__name__ 
     410        raise TypeError(msg % (key, typenames.get(tname, tname), value)) 
     411    return coerced 
    396412 
    397413def coerce_out(obj, attr=missing, default=missing):