aboutsummaryrefslogtreecommitdiffstats
path: root/python/urllib3/packages/backports
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-02-25 20:47:49 -0800
committerJames Taylor <user234683@users.noreply.github.com>2019-02-25 20:47:49 -0800
commit1e1f55c9e5d98ba076bc67e7abe9e4d77d84c65b (patch)
tree56eeabd9f7f0813c4b02f03f865d7cae35277d29 /python/urllib3/packages/backports
parentb32330be4f15dd044e6212f526e52375f0a0f6c2 (diff)
downloadyt-local-1e1f55c9e5d98ba076bc67e7abe9e4d77d84c65b.tar.lz
yt-local-1e1f55c9e5d98ba076bc67e7abe9e4d77d84c65b.tar.xz
yt-local-1e1f55c9e5d98ba076bc67e7abe9e4d77d84c65b.zip
Use persistent connections
Diffstat (limited to 'python/urllib3/packages/backports')
-rw-r--r--python/urllib3/packages/backports/__init__.py0
-rw-r--r--python/urllib3/packages/backports/makefile.py53
2 files changed, 53 insertions, 0 deletions
diff --git a/python/urllib3/packages/backports/__init__.py b/python/urllib3/packages/backports/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python/urllib3/packages/backports/__init__.py
diff --git a/python/urllib3/packages/backports/makefile.py b/python/urllib3/packages/backports/makefile.py
new file mode 100644
index 0000000..740db37
--- /dev/null
+++ b/python/urllib3/packages/backports/makefile.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+"""
+backports.makefile
+~~~~~~~~~~~~~~~~~~
+
+Backports the Python 3 ``socket.makefile`` method for use with anything that
+wants to create a "fake" socket object.
+"""
+import io
+
+from socket import SocketIO
+
+
+def backport_makefile(self, mode="r", buffering=None, encoding=None,
+ errors=None, newline=None):
+ """
+ Backport of ``socket.makefile`` from Python 3.5.
+ """
+ if not set(mode) <= {"r", "w", "b"}:
+ raise ValueError(
+ "invalid mode %r (only r, w, b allowed)" % (mode,)
+ )
+ writing = "w" in mode
+ reading = "r" in mode or not writing
+ assert reading or writing
+ binary = "b" in mode
+ rawmode = ""
+ if reading:
+ rawmode += "r"
+ if writing:
+ rawmode += "w"
+ raw = SocketIO(self, rawmode)
+ self._makefile_refs += 1
+ if buffering is None:
+ buffering = -1
+ if buffering < 0:
+ buffering = io.DEFAULT_BUFFER_SIZE
+ if buffering == 0:
+ if not binary:
+ raise ValueError("unbuffered streams must be binary")
+ return raw
+ if reading and writing:
+ buffer = io.BufferedRWPair(raw, raw, buffering)
+ elif reading:
+ buffer = io.BufferedReader(raw, buffering)
+ else:
+ assert writing
+ buffer = io.BufferedWriter(raw, buffering)
+ if binary:
+ return buffer
+ text = io.TextIOWrapper(buffer, encoding, errors, newline)
+ text.mode = mode
+ return text