def __init__(self, detail=None, headers=None, comment=None): assert self.code, "Do not directly instantiate abstract exceptions." assert isinstance( headers, (type(None), list)), ("headers must be None or a list: %r" % headers) assert isinstance( detail, (type(None), basestring)), ("detail must be None or a string: %r" % detail) assert isinstance( comment, (type(None), basestring)), ("comment must be None or a string: %r" % comment) self.headers = headers or tuple() for req in self.required_headers: assert headers and has_header(headers, req), ( "Exception %s must be passed the header %r " "(got headers: %r)" % (self.__class__.__name__, req, headers)) if detail is not None: self.detail = detail if comment is not None: self.comment = comment Exception.__init__( self, "%s %s\n%s\n%s\n" % (self.code, self.title, self.explanation, self.detail))
def add_no_cache_headers(event): """ Add no-cache headers if this response doesnt already have a Cache-Control header""" response = event.response if response is not None: if not has_header(response.headerlist, 'Cache-Control'): response.headerlist.append( ('Cache-Control', 'private, must-revalidate'))
def __init__(self, detail=None, headers=None, comment=None): assert self.code, "Do not directly instantiate abstract exceptions." assert isinstance(headers, (type(None), list)), ( "headers must be None or a list: %r" % headers) assert isinstance(detail, (type(None), six.binary_type, six.text_type)), ( "detail must be None or a string: %r" % detail) assert isinstance(comment, (type(None), six.binary_type, six.text_type)), ( "comment must be None or a string: %r" % comment) self.headers = headers or tuple() for req in self.required_headers: assert headers and has_header(headers, req), ( "Exception %s must be passed the header %r " "(got headers: %r)" % (self.__class__.__name__, req, headers)) if detail is not None: self.detail = detail if comment is not None: self.comment = comment Exception.__init__(self,"%s %s\n%s\n%s\n" % ( self.code, self.title, self.explanation, self.detail))