Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[script.module.urllib3@matrix] 2.2.3 #2693

Open
wants to merge 1 commit into
base: matrix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script.module.urllib3/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.urllib3" name="urllib3" version="2.1.0" provider-name="urllib3">
<addon id="script.module.urllib3" name="urllib3" version="2.2.3" provider-name="urllib3">
<requires>
<import addon="xbmc.python" version="3.0.0" />
</requires>
Expand Down
62 changes: 62 additions & 0 deletions script.module.urllib3/lib/urllib3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Set default logging handler to avoid "No handler found" warnings.
import logging
import sys
import typing
import warnings
from logging import NullHandler
Expand Down Expand Up @@ -132,6 +133,61 @@ def request(
Therefore, its side effects could be shared across dependencies relying on it.
To avoid side effects create a new ``PoolManager`` instance and use it instead.
The method does not accept low-level ``**urlopen_kw`` keyword arguments.

:param method:
HTTP request method (such as GET, POST, PUT, etc.)

:param url:
The URL to perform the request on.

:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.

:param fields:
Data to encode and send in the request body.

:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc.

:param bool preload_content:
If True, the response's body will be preloaded into memory.

:param bool decode_content:
If True, will attempt to decode the body based on the
'content-encoding' header.

:param redirect:
If True, automatically handle redirects (status codes 301, 302,
303, 307, 308). Each redirect counts as a retry. Disabling retries
will disable redirect, too.

:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.

If ``None`` (default) will retry 3 times, see ``Retry.DEFAULT``. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained control
over different types of retries.
Pass an integer number to retry connection errors that many times,
but no other types of errors. Pass zero to never retry.

If ``False``, then retries are disabled and any exception is raised
immediately. Also, instead of raising a MaxRetryError on redirects,
the redirect response will be returned.

:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.

:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.

:param json:
Data to encode and send as JSON with UTF-encoded in the request body.
The ``"Content-Type"`` header will be set to ``"application/json"``
unless specified otherwise.
"""

return _DEFAULT_POOL.request(
Expand All @@ -147,3 +203,9 @@ def request(
timeout=timeout,
json=json,
)


if sys.platform == "emscripten":
from .contrib.emscripten import inject_into_urllib3 # noqa: 401

inject_into_urllib3()
8 changes: 4 additions & 4 deletions script.module.urllib3/lib/urllib3/_base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ProxyConfig(typing.NamedTuple):
ssl_context: ssl.SSLContext | None
use_forwarding_for_https: bool
assert_hostname: None | str | Literal[False]
assert_hostname: None | str | typing.Literal[False]
assert_fingerprint: str | None


Expand All @@ -28,7 +28,7 @@ class _ResponseOptions(typing.NamedTuple):

if typing.TYPE_CHECKING:
import ssl
from typing import Literal, Protocol
from typing import Protocol

from .response import BaseHTTPResponse

Expand Down Expand Up @@ -124,7 +124,7 @@ class BaseHTTPSConnection(BaseHTTPConnection, Protocol):

# Certificate verification methods
cert_reqs: int | str | None
assert_hostname: None | str | Literal[False]
assert_hostname: None | str | typing.Literal[False]
assert_fingerprint: str | None
ssl_context: ssl.SSLContext | None

Expand Down Expand Up @@ -155,7 +155,7 @@ def __init__(
proxy: Url | None = None,
proxy_config: ProxyConfig | None = None,
cert_reqs: int | str | None = None,
assert_hostname: None | str | Literal[False] = None,
assert_hostname: None | str | typing.Literal[False] = None,
assert_fingerprint: str | None = None,
server_hostname: str | None = None,
ssl_context: ssl.SSLContext | None = None,
Expand Down
6 changes: 3 additions & 3 deletions script.module.urllib3/lib/urllib3/_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def _copy_from(self, other: HTTPHeaderDict) -> None:
val = other.getlist(key)
self._container[key.lower()] = [key, *val]

def copy(self) -> HTTPHeaderDict:
def copy(self) -> Self:
clone = type(self)()
clone._copy_from(self)
return clone
Expand Down Expand Up @@ -462,7 +462,7 @@ def __ior__(self, other: object) -> HTTPHeaderDict:
self.extend(maybe_constructable)
return self

def __or__(self, other: object) -> HTTPHeaderDict:
def __or__(self, other: object) -> Self:
# Supports merging header dicts using operator |
# combining items with add instead of __setitem__
maybe_constructable = ensure_can_construct_http_header_dict(other)
Expand All @@ -472,7 +472,7 @@ def __or__(self, other: object) -> HTTPHeaderDict:
result.extend(maybe_constructable)
return result

def __ror__(self, other: object) -> HTTPHeaderDict:
def __ror__(self, other: object) -> Self:
# Supports merging header dicts using operator | when other is on left side
# combining items with add instead of __setitem__
maybe_constructable = ensure_can_construct_http_header_dict(other)
Expand Down
65 changes: 63 additions & 2 deletions script.module.urllib3/lib/urllib3/_request_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ def request(
option to drop down to more specific methods when necessary, such as
:meth:`request_encode_url`, :meth:`request_encode_body`,
or even the lowest level :meth:`urlopen`.

:param method:
HTTP request method (such as GET, POST, PUT, etc.)

:param url:
The URL to perform the request on.

:param body:
Data to send in the request body, either :class:`str`, :class:`bytes`,
an iterable of :class:`str`/:class:`bytes`, or a file-like object.

:param fields:
Data to encode and send in the URL or request body, depending on ``method``.

:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.

:param json:
Data to encode and send as JSON with UTF-encoded in the request body.
The ``"Content-Type"`` header will be set to ``"application/json"``
unless specified otherwise.
"""
method = method.upper()

Expand All @@ -95,9 +118,11 @@ def request(

if json is not None:
if headers is None:
headers = self.headers.copy() # type: ignore
headers = self.headers

if not ("content-type" in map(str.lower, headers.keys())):
headers["Content-Type"] = "application/json" # type: ignore
headers = HTTPHeaderDict(headers)
headers["Content-Type"] = "application/json"

body = _json.dumps(json, separators=(",", ":"), ensure_ascii=False).encode(
"utf-8"
Expand Down Expand Up @@ -130,6 +155,20 @@ def request_encode_url(
"""
Make a request using :meth:`urlopen` with the ``fields`` encoded in
the url. This is useful for request methods like GET, HEAD, DELETE, etc.

:param method:
HTTP request method (such as GET, POST, PUT, etc.)

:param url:
The URL to perform the request on.

:param fields:
Data to encode and send in the URL.

:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.
"""
if headers is None:
headers = self.headers
Expand Down Expand Up @@ -186,6 +225,28 @@ def request_encode_body(
be overwritten because it depends on the dynamic random boundary string
which is used to compose the body of the request. The random boundary
string can be explicitly set with the ``multipart_boundary`` parameter.

:param method:
HTTP request method (such as GET, POST, PUT, etc.)

:param url:
The URL to perform the request on.

:param fields:
Data to encode and send in the request body.

:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If provided,
these headers completely replace any pool-specific headers.

:param encode_multipart:
If True, encode the ``fields`` using the multipart/form-data MIME
format.

:param multipart_boundary:
If not specified, then a random boundary will be generated using
:func:`urllib3.filepost.choose_boundary`.
"""
if headers is None:
headers = self.headers
Expand Down
18 changes: 15 additions & 3 deletions script.module.urllib3/lib/urllib3/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# This file is protected via CODEOWNERS
from __future__ import annotations
# file generated by setuptools_scm
# don't change, don't track in version control
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Tuple, Union
VERSION_TUPLE = Tuple[Union[int, str], ...]
else:
VERSION_TUPLE = object

__version__ = "2.1.0"
version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '2.2.3'
__version_tuple__ = version_tuple = (2, 2, 3)
Loading
Loading