makefile(...) -> an I/O stream connected to the socket The arguments are as for io.open() after the filename, except the only supported mode values are 'r' (default), 'w', 'b', or a combination of those.
(self, mode="r", buffering=None, *,
encoding=None, errors=None, newline=None)
| 306 | return sock, addr |
| 307 | |
| 308 | def makefile(self, mode="r", buffering=None, *, |
| 309 | encoding=None, errors=None, newline=None): |
| 310 | """makefile(...) -> an I/O stream connected to the socket |
| 311 | |
| 312 | The arguments are as for io.open() after the filename, except the only |
| 313 | supported mode values are 'r' (default), 'w', 'b', or a combination of |
| 314 | those. |
| 315 | """ |
| 316 | # XXX refactor to share code? |
| 317 | if not set(mode) <= {"r", "w", "b"}: |
| 318 | raise ValueError("invalid mode %r (only r, w, b allowed)" % (mode,)) |
| 319 | writing = "w" in mode |
| 320 | reading = "r" in mode or not writing |
| 321 | assert reading or writing |
| 322 | binary = "b" in mode |
| 323 | rawmode = "" |
| 324 | if reading: |
| 325 | rawmode += "r" |
| 326 | if writing: |
| 327 | rawmode += "w" |
| 328 | raw = SocketIO(self, rawmode) |
| 329 | self._io_refs += 1 |
| 330 | if buffering is None: |
| 331 | buffering = -1 |
| 332 | if buffering < 0: |
| 333 | buffering = io.DEFAULT_BUFFER_SIZE |
| 334 | if buffering == 0: |
| 335 | if not binary: |
| 336 | raise ValueError("unbuffered streams must be binary") |
| 337 | return raw |
| 338 | if reading and writing: |
| 339 | buffer = io.BufferedRWPair(raw, raw, buffering) |
| 340 | elif reading: |
| 341 | buffer = io.BufferedReader(raw, buffering) |
| 342 | else: |
| 343 | assert writing |
| 344 | buffer = io.BufferedWriter(raw, buffering) |
| 345 | if binary: |
| 346 | return buffer |
| 347 | encoding = io.text_encoding(encoding) |
| 348 | text = io.TextIOWrapper(buffer, encoding, errors, newline) |
| 349 | text.mode = mode |
| 350 | return text |
| 351 | |
| 352 | def _sendfile_zerocopy(self, zerocopy_func, giveup_exc_type, file, |
| 353 | offset=0, count=None): |