|
3 | 3 | import os |
4 | 4 |
|
5 | 5 |
|
| 6 | +__all__ = ['Stream', 'ByteStream', 'DuplexStream', 'FileStream', 'MultiPartStream'] |
| 7 | + |
| 8 | + |
6 | 9 | class Stream: |
7 | 10 | async def read(self, size: int=-1) -> bytes: |
8 | 11 | raise NotImplementedError() |
@@ -103,47 +106,6 @@ async def __aenter__(self): |
103 | 106 | return self |
104 | 107 |
|
105 | 108 |
|
106 | | -class HTTPStream(Stream): |
107 | | - def __init__(self, next_chunk, complete): |
108 | | - self._next_chunk = next_chunk |
109 | | - self._complete = complete |
110 | | - self._buffer = io.BytesIO() |
111 | | - |
112 | | - async def read(self, size=-1) -> bytes: |
113 | | - sections = [] |
114 | | - length = 0 |
115 | | - |
116 | | - # If we have any data in the buffer read that and clear the buffer. |
117 | | - buffered = self._buffer.read() |
118 | | - if buffered: |
119 | | - sections.append(buffered) |
120 | | - length += len(buffered) |
121 | | - self._buffer.seek(0) |
122 | | - self._buffer.truncate(0) |
123 | | - |
124 | | - # Read each chunk in turn. |
125 | | - while (size < 0) or (length < size): |
126 | | - section = await self._next_chunk() |
127 | | - sections.append(section) |
128 | | - length += len(section) |
129 | | - if section == b'': |
130 | | - break |
131 | | - |
132 | | - # If we've more data than requested, then push some back into the buffer. |
133 | | - output = b''.join(sections) |
134 | | - if size > -1 and len(output) > size: |
135 | | - output, remainder = output[:size], output[size:] |
136 | | - self._buffer.write(remainder) |
137 | | - self._buffer.seek(0) |
138 | | - |
139 | | - return output |
140 | | - |
141 | | - async def close(self) -> None: |
142 | | - self._buffer.close() |
143 | | - if self._complete is not None: |
144 | | - await self._complete() |
145 | | - |
146 | | - |
147 | 109 | class MultiPartStream(Stream): |
148 | 110 | def __init__(self, form: list[tuple[str, str]], files: list[tuple[str, str]], boundary=''): |
149 | 111 | self._form = list(form) |
|
0 commit comments