Example #1
0
 def __init__(self, status, message, headers=None, content=b''):
     super().__init__(message)
     self.status = ASSERT.in_range(_cast_status(status), (300, 600))
     self.headers = ASSERT.predicate(
         dict(headers) if headers is not None else {},
         lambda hdrs: all(
             isinstance(k, str) and isinstance(v, str)
             for k, v in hdrs.items()),
     )
     self.content = ASSERT.isinstance(content, bytes)
Example #2
0
 def redirect(cls, status, message, location):
     ASSERT.in_range(status, (300, 400))
     return cls(status, message, {consts.HEADER_LOCATION: location})