<s> import traceback <EOL> from pyramid . httpexceptions import HTTPNotFound <EOL> from pyramid . security import unauthenticated_userid <EOL> def generic ( context , request ) : <EOL> request . response . status_int = <NUM_LIT> <EOL> try : <EOL> response = { '<STR_LIT:message>' : context . args [ <NUM_LIT:0> ] } <EOL> except IndexError : <EOL> response = { '<STR_LIT:message>' : '<STR_LIT>' } <EOL> if request . registry . settings . get ( '<STR_LIT>' ) : <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' . join ( <EOL> traceback . format_exception ( * request . exc_info ) ) <EOL> return response <EOL> def http_error ( context , request ) : <EOL> request . response . status = context . status <EOL> for ( header , value ) in context . headers . items ( ) : <EOL> if header in { '<STR_LIT:Content-Type>' , '<STR_LIT>' } : <EOL> continue <EOL> request . response . headers [ header ] = value <EOL> if context . message : <EOL> return { '<STR_LIT:message>' : context . message } <EOL> else : <EOL> return { '<STR_LIT:message>' : context . status } <EOL> def notfound ( context , request ) : <EOL> message = '<STR_LIT>' <EOL> if isinstance ( context , HTTPNotFound ) : <EOL> if context . content_type == '<STR_LIT:application/json>' : <EOL> return context <EOL> elif context . detail : <EOL> message = context . detail <EOL> request . response . status_int = <NUM_LIT> <EOL> return { '<STR_LIT:message>' : message } <EOL> def forbidden ( request ) : <EOL> if unauthenticated_userid ( request ) : <EOL> request . response . status_int = <NUM_LIT> <EOL> return { '<STR_LIT:message>' : '<STR_LIT>' } <EOL> else : <EOL> request . response . status_int = <NUM_LIT> <EOL> return { '<STR_LIT:message>' : '<STR_LIT>' } </s>
