mirror of
https://github.com/httpie/cli.git
synced 2025-06-25 03:51:31 +02:00
Improve startup time when pyOpenSSL is available on the environment (#1233)
This commit is contained in:
parent
c237e15108
commit
1bd8422fb5
@ -1,9 +1,11 @@
|
|||||||
import zlib
|
import zlib
|
||||||
from typing import Callable, IO, Iterable, Tuple, Union
|
from typing import Callable, IO, Iterable, Tuple, Union, TYPE_CHECKING
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from requests.utils import super_len
|
from requests.utils import super_len
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
from requests_toolbelt import MultipartEncoder
|
from requests_toolbelt import MultipartEncoder
|
||||||
|
|
||||||
from .cli.dicts import MultipartRequestDataDict, RequestDataDict
|
from .cli.dicts import MultipartRequestDataDict, RequestDataDict
|
||||||
@ -23,7 +25,7 @@ class ChunkedUploadStream:
|
|||||||
class ChunkedMultipartUploadStream:
|
class ChunkedMultipartUploadStream:
|
||||||
chunk_size = 100 * 1024
|
chunk_size = 100 * 1024
|
||||||
|
|
||||||
def __init__(self, encoder: MultipartEncoder):
|
def __init__(self, encoder: 'MultipartEncoder'):
|
||||||
self.encoder = encoder
|
self.encoder = encoder
|
||||||
|
|
||||||
def __iter__(self) -> Iterable[Union[str, bytes]]:
|
def __iter__(self) -> Iterable[Union[str, bytes]]:
|
||||||
@ -35,12 +37,12 @@ class ChunkedMultipartUploadStream:
|
|||||||
|
|
||||||
|
|
||||||
def prepare_request_body(
|
def prepare_request_body(
|
||||||
body: Union[str, bytes, IO, MultipartEncoder, RequestDataDict],
|
body: Union[str, bytes, IO, 'MultipartEncoder', RequestDataDict],
|
||||||
body_read_callback: Callable[[bytes], bytes],
|
body_read_callback: Callable[[bytes], bytes],
|
||||||
content_length_header_value: int = None,
|
content_length_header_value: int = None,
|
||||||
chunked=False,
|
chunked=False,
|
||||||
offline=False,
|
offline=False,
|
||||||
) -> Union[str, bytes, IO, MultipartEncoder, ChunkedUploadStream]:
|
) -> Union[str, bytes, IO, 'MultipartEncoder', ChunkedUploadStream]:
|
||||||
|
|
||||||
is_file_like = hasattr(body, 'read')
|
is_file_like = hasattr(body, 'read')
|
||||||
|
|
||||||
@ -85,6 +87,7 @@ def prepare_request_body(
|
|||||||
body.read = new_read
|
body.read = new_read
|
||||||
|
|
||||||
if chunked:
|
if chunked:
|
||||||
|
from requests_toolbelt import MultipartEncoder
|
||||||
if isinstance(body, MultipartEncoder):
|
if isinstance(body, MultipartEncoder):
|
||||||
body = ChunkedMultipartUploadStream(
|
body = ChunkedMultipartUploadStream(
|
||||||
encoder=body,
|
encoder=body,
|
||||||
@ -102,7 +105,9 @@ def get_multipart_data_and_content_type(
|
|||||||
data: MultipartRequestDataDict,
|
data: MultipartRequestDataDict,
|
||||||
boundary: str = None,
|
boundary: str = None,
|
||||||
content_type: str = None,
|
content_type: str = None,
|
||||||
) -> Tuple[MultipartEncoder, str]:
|
) -> Tuple['MultipartEncoder', str]:
|
||||||
|
from requests_toolbelt import MultipartEncoder
|
||||||
|
|
||||||
encoder = MultipartEncoder(
|
encoder = MultipartEncoder(
|
||||||
fields=data.items(),
|
fields=data.items(),
|
||||||
boundary=boundary,
|
boundary=boundary,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user