예제 #1
0
 def parse_chunked(self, unreader):
     (size, rest) = self.parse_chunk_size(unreader)
     while size > 0:
         while size > len(rest):
             size -= len(rest)
             yield rest
             rest = unreader.read()
             if not rest:
                 raise NoMoreData()
         yield rest[:size]
         # Remove \r\n after chunk
         rest = rest[size:]
         while len(rest) < 2:
             rest += unreader.read()
         if rest[:2] != b'\r\n':
             raise ChunkMissingTerminator(rest[:2])
         (size, rest) = self.parse_chunk_size(unreader, data=rest[2:])
예제 #2
0
파일: body.py 프로젝트: luog1992/gunicorn
    def parse_chunked(self, unreader):
        size, rest = self.parse_chunk_size(unreader)
        while size > 0:
            # 读取一个chunk中的数据直到差不多要读取完了
            while size > len(rest):
                size -= len(rest)
                yield rest
                rest = unreader.read()
                if not rest:
                    raise NoMoreData()
            # 读取一个chunk中最后剩余的数据
            yield rest[:size]
            # Remove \r\n after chunk
            rest = rest[size:]
            while len(rest) < 2:
                rest += unreader.read()
            # 上一个chunk的结尾必然是 \r\n
            if rest[:2] != b'\r\n':
                raise ChunkMissingTerminator(rest[:2])

            # 读取下一个chunk的数据
            size, rest = self.parse_chunk_size(unreader, data=rest[2:])