예제 #1
0
파일: response.py 프로젝트: renskiy/marnadi
 def iterator(self):
     result = yield
     if result is None or isinstance(result, (str, bytes)):
         chunk = to_bytes(result)
         self.headers['Content-Length'] = len(chunk)
         yield chunk
     else:
         chunks = iter(result)
         first_chunk = to_bytes(next(chunks, b''))
         try:
             result_length = len(result)
         except TypeError:  # result doesn't support len()
             pass
         else:
             if result_length <= 1:
                 self.headers['Content-Length'] = len(first_chunk)
         yield first_chunk
         for chunk in chunks:
             yield to_bytes(chunk, error_callback=self.logger.exception)
예제 #2
0
파일: error.py 프로젝트: renskiy/marnadi
 def __init__(self, status=None, data=None, headers=()):
     self.status = status or self.default_status
     self.data = to_bytes(data or status)
     self.update_headers(headers)