summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M. Larson <SethMichaelLarson@users.noreply.github.com>2018-04-25 07:22:46 -0500
committerGitHub <noreply@github.com>2018-04-25 07:22:46 -0500
commitc8c98c473ab30f427fe05057f2ceded10ec93153 (patch)
treece24a644a2b96c9153a4d8c409dea8eac625138d
parent11b6c15791a57c7b69040bfd4bb82c77f2b015b6 (diff)
parent2906be4d1682363f80f1044ecb1b25239a86f44b (diff)
downloadurllib3-c8c98c473ab30f427fe05057f2ceded10ec93153.tar.gz
Stop using uuid for choose_boundary() (#1380)
Stop using uuid for choose_boundary()
-rw-r--r--CHANGES.rst2
-rw-r--r--urllib3/filepost.py17
2 files changed, 8 insertions, 11 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 4b6ca7cb..3c909e1c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -20,7 +20,7 @@ dev (master)
* Add the port to the connectionpool connect print (Pull #1251)
-* Lazily load `uuid` to boost performance on imports (Pull #1270)
+* Don't use the ``uuid`` module to create multipart data boundaries. (Pull #1380)
* ``read_chunked()`` on a closed response returns no chunks. (Issue #1088)
diff --git a/urllib3/filepost.py b/urllib3/filepost.py
index 5af4fb31..78f1e19b 100644
--- a/urllib3/filepost.py
+++ b/urllib3/filepost.py
@@ -1,5 +1,7 @@
from __future__ import absolute_import
+import binascii
import codecs
+import os
from io import BytesIO
@@ -13,16 +15,11 @@ writer = codecs.lookup('utf-8')[3]
def choose_boundary():
"""
Our embarrassingly-simple replacement for mimetools.choose_boundary.
-
- We are lazily loading uuid here, because we don't want its issues
-
- https://bugs.python.org/issue5885
- https://bugs.python.org/issue11063
-
- to affect our entire library.
"""
- from uuid import uuid4
- return uuid4().hex
+ boundary = binascii.hexlify(os.urandom(16))
+ if six.PY3:
+ boundary = boundary.decode('ascii')
+ return boundary
def iter_field_objects(fields):
@@ -72,7 +69,7 @@ def encode_multipart_formdata(fields, boundary=None):
:param boundary:
If not specified, then a random boundary will be generated using
- :func:`mimetools.choose_boundary`.
+ :func:`urllib3.filepost.choose_boundary`.
"""
body = BytesIO()
if boundary is None: