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