Adjust patch to utilize requests utility functions

Use the utility class provided by requests to do native string
transformation rather than recreating the wheel.
This commit is contained in:
Brian Bamsch
2016-09-26 09:11:18 -07:00
parent 550dc19099
commit 2af059797a
+3 -7
View File
@@ -13,6 +13,8 @@ import copy
import time
import calendar
import collections
from . import utils
from .compat import cookielib, urlparse, urlunparse, Morsel
try:
@@ -55,14 +57,8 @@ class MockRequest(object):
if not self._r.headers.get('Host'):
return self._r.url
# If they did set it, retrieve it and reconstruct the expected domain
host = self._r.headers['Host']
host = utils.to_native_string(self._r.headers['Host'], encoding='utf-8')
parsed = urlparse(self._r.url)
# If parsed url is str type, ensure that host is also str type
if isinstance(parsed.scheme, str) and not isinstance(host, str)\
and isinstance(host, bytes):
host = host.decode('ascii')
# Reconstruct the URL as we expect it
return urlunparse([
parsed.scheme, host, parsed.path, parsed.params, parsed.query,