wsgi.py
changeset 72 5160b9e0edf1
parent 46 54c5f5f340de
equal deleted inserted replaced
71:0162c2b21dc5 72:5160b9e0edf1
    44         start_response(response.get_status(), response.get_headers())
    44         start_response(response.get_status(), response.get_headers())
    45 
    45 
    46         # send respones data
    46         # send respones data
    47         yield response.get_data()
    47         yield response.get_data()
    48 
    48 
       
    49     def handle_error (self, exc_info, env, start_response) :
       
    50         """
       
    51             Handle errors thrown by handle_request. This should call start_response with the exc_info and return the
       
    52             error message (i.e. str), otherwise the error will be thrown up yet another level.
       
    53 
       
    54             Note that e.g. unicode is a failure...
       
    55         """
       
    56 
       
    57         # try and send 500 ISE to browser, if no headers yet...
       
    58         start_response("500 Internal Server Error", [('Content-type', "text/plain; charset=UTF-8")], exc_info)
       
    59 
       
    60         # format traceback
       
    61         data = ''.join(traceback.format_exception(*exc_info))
       
    62         
       
    63         # no unicode, kplzthx
       
    64         return data.encode('utf-8')
       
    65     
    49     def __call__ (self, env, start_response) :
    66     def __call__ (self, env, start_response) :
    50         """
    67         """
    51             Wraps handle_request to trap errors
    68             Wraps handle_request to trap errors
    52         """
    69         """
    53 
    70 
    58 
    75 
    59         except :
    76         except :
    60             # execption info
    77             # execption info
    61             info = sys.exc_info()
    78             info = sys.exc_info()
    62 
    79 
    63             # try and send 500 ISE to browser, if no headers yet...
    80             # handle
    64             start_response("500 Internal Server Error", [('Content-type', "text/plain; charset=utf8")], info)
    81             yield self.handle_error(info, env, start_response)
    65 
    82 
    66             # send traceback
       
    67             yield traceback.format_exc()
       
    68