Use urlsplit instead of urlparse.

Closes #118.
This commit is contained in:
Jakub Roztocil 2013-01-03 14:12:27 +01:00
parent d84d94dd55
commit 1481749c22
9 changed files with 31 additions and 13 deletions

View File

@ -7,10 +7,9 @@ TODO: make the options config friendly, i.e., no mutually exclusive groups to
"""
from argparse import FileType, OPTIONAL, ZERO_OR_MORE, SUPPRESS
from requests.compat import is_windows
from . import __doc__
from . import __version__
from .compat import is_windows
from .sessions import DEFAULT_SESSIONS_DIR
from .manage import session_name_validator
from .output import AVAILABLE_STYLES, DEFAULT_STYLE

18
httpie/compat.py Normal file
View File

@ -0,0 +1,18 @@
"""
Python 2/3 compatibility.
"""
#noinspection PyUnresolvedReferences
from requests.compat import (
is_windows,
bytes,
str,
is_py3,
is_py26,
)
try:
from urllib.parse import urlsplit
except ImportError:
from urlparse import urlsplit

View File

@ -3,7 +3,7 @@ import json
import errno
from . import __version__
from requests.compat import is_windows
from .compat import is_windows
DEFAULT_CONFIG_DIR = os.environ.get(

View File

@ -14,12 +14,12 @@ import sys
import errno
import requests
from requests.compat import str, is_py3
from httpie import __version__ as httpie_version
from requests import __version__ as requests_version
from pygments import __version__ as pygments_version
from .cli import parser
from .compat import str, is_py3
from .client import get_response
from .models import Environment
from .output import build_output_stream, write, write_with_colors_win_p3k

View File

@ -16,7 +16,8 @@ except ImportError:
OrderedDict = dict
from requests.structures import CaseInsensitiveDict
from requests.compat import str, urlparse
from .compat import urlsplit, str
HTTP_POST = 'POST'
@ -128,7 +129,7 @@ class Parser(ArgumentParser):
return args
def _process_auth(self, args):
url = urlparse(args.url)
url = urlsplit(args.url)
if args.auth:
if not args.auth.has_password():

View File

@ -1,6 +1,6 @@
import os
import sys
from requests.compat import urlparse, is_windows, bytes, str
from .compat import urlsplit, is_windows, bytes, str
from .config import DEFAULT_CONFIG_DIR, Config
@ -142,7 +142,7 @@ class HTTPRequest(HTTPMessage):
@property
def headers(self):
url = urlparse(self._orig.url)
url = urlsplit(self._orig.url)
# Querystring
qs = ''
@ -166,7 +166,7 @@ class HTTPRequest(HTTPMessage):
headers = dict(self._orig.headers)
if 'Host' not in headers:
headers['Host'] = urlparse(self._orig.url).netloc
headers['Host'] = urlsplit(self._orig.url).netloc
headers = ['%s: %s' % (name, value)
for name, value in headers.items()]

View File

@ -12,8 +12,8 @@ from pygments.lexers import get_lexer_for_mimetype, get_lexer_by_name
from pygments.formatters.terminal import TerminalFormatter
from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.util import ClassNotFound
from requests.compat import is_windows
from .compat import is_windows
from .solarized import Solarized256Style
from .models import HTTPRequest, HTTPResponse, Environment
from .input import (OUT_REQ_BODY, OUT_REQ_HEAD,

View File

@ -11,10 +11,10 @@ import shutil
import subprocess
import requests
from requests.compat import urlparse
from requests.cookies import RequestsCookieJar, create_cookie
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
from .compat import urlsplit
from .config import BaseConfigDict, DEFAULT_CONFIG_DIR
from .output import PygmentsProcessor
@ -32,7 +32,7 @@ def get_response(name, request_kwargs, config_dir, read_only=False):
host = Host(
root_dir=sessions_dir,
name=request_kwargs['headers'].get('Host', None)
or urlparse(request_kwargs['url']).netloc.split('@')[-1]
or urlsplit(request_kwargs['url']).netloc.split('@')[-1]
)
session = Session(host, name)
session.load()

View File

@ -45,7 +45,6 @@ except ImportError:
return decorator
from requests import __version__ as requests_version
from requests.compat import is_windows, is_py26, bytes, str
#################################################################
@ -62,6 +61,7 @@ from httpie.models import Environment
from httpie.core import main
from httpie.output import BINARY_SUPPRESSED_NOTICE
from httpie.input import ParseError
from httpie.compat import is_windows, is_py26, bytes, str
CRLF = '\r\n'