diff options
| author | Seth M. Larson <SethMichaelLarson@users.noreply.github.com> | 2018-04-24 16:57:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-24 16:57:40 -0500 |
| commit | 0fab5f709d1cac7dee492b62f17e2cf3fd97ee3d (patch) | |
| tree | a759aeb076132057b9b8cb101646f2db3c5cc050 | |
| parent | 11b6c15791a57c7b69040bfd4bb82c77f2b015b6 (diff) | |
| download | urllib3-0fab5f709d1cac7dee492b62f17e2cf3fd97ee3d.tar.gz | |
Stop using uuid for choose_boundary()
This solution is about 4 times faster than uuid.uuid4().hex method
| -rw-r--r-- | urllib3/filepost.py | 17 |
1 files changed, 7 insertions, 10 deletions
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: |
