Skip to content

Commit

Permalink
Merge pull request #11367 from pymedusa/release/release-1.0.17
Browse files Browse the repository at this point in the history
Release/release 1.0.17
  • Loading branch information
medariox committed Jun 29, 2023
2 parents e98773f + 8039506 commit 3d65665
Show file tree
Hide file tree
Showing 67 changed files with 4,003 additions and 3,817 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,18 @@ pymedusa.egg-info
.cache
htmlcov
xo-errors.log
yarn-error.log

# Contrib #
######################
/contrib/

# Yarn #
######################
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
yarn-error.log
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 1.0.17 (29-06-2023)

#### New Features
- Add TheOldSchool torrent provider (Thanks to @IamMika23)

#### Improvements
- Update IPTorrents default domain
- Update many dependencies

#### Fixes
- Fix saving order of various tables

-----

## 1.0.16 (27-05-2023)

#### Improvements
Expand Down
18 changes: 14 additions & 4 deletions ext/cachecontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
"""
__author__ = "Eric Larson"
__email__ = "[email protected]"
__version__ = "0.12.11"
__version__ = "0.13.1"

from .wrapper import CacheControl
from .adapter import CacheControlAdapter
from .controller import CacheController
from cachecontrol.adapter import CacheControlAdapter
from cachecontrol.controller import CacheController
from cachecontrol.wrapper import CacheControl

__all__ = [
"__author__",
"__email__",
"__version__",
"CacheControlAdapter",
"CacheController",
"CacheControl",
]

import logging

logging.getLogger(__name__).addHandler(logging.NullHandler())
25 changes: 17 additions & 8 deletions ext/cachecontrol/_cmd.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
# SPDX-FileCopyrightText: 2015 Eric Larson
#
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

import logging
from argparse import ArgumentParser
from typing import TYPE_CHECKING

import requests

from cachecontrol.adapter import CacheControlAdapter
from cachecontrol.cache import DictCache
from cachecontrol.controller import logger

from argparse import ArgumentParser
if TYPE_CHECKING:
from argparse import Namespace

from cachecontrol.controller import CacheController

def setup_logging():

def setup_logging() -> None:
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)


def get_session():
def get_session() -> requests.Session:
adapter = CacheControlAdapter(
DictCache(), cache_etags=True, serializer=None, heuristic=None
)
sess = requests.Session()
sess.mount("http://", adapter)
sess.mount("https://", adapter)

sess.cache_controller = adapter.controller
sess.cache_controller = adapter.controller # type: ignore[attr-defined]
return sess


def get_args():
def get_args() -> Namespace:
parser = ArgumentParser()
parser.add_argument("url", help="The URL to try and cache")
return parser.parse_args()


def main(args=None):
def main() -> None:
args = get_args()
sess = get_session()

Expand All @@ -48,10 +54,13 @@ def main(args=None):
setup_logging()

# try setting the cache
sess.cache_controller.cache_response(resp.request, resp.raw)
cache_controller: CacheController = (
sess.cache_controller # type: ignore[attr-defined]
)
cache_controller.cache_response(resp.request, resp.raw)

# Now try to get it
if sess.cache_controller.cached_request(resp.request):
if cache_controller.cached_request(resp.request):
print("Cached!")
else:
print("Not cached :(")
Expand Down
80 changes: 52 additions & 28 deletions ext/cachecontrol/adapter.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
# SPDX-FileCopyrightText: 2015 Eric Larson
#
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

import types
import functools
import types
import zlib
from typing import TYPE_CHECKING, Any, Collection, Mapping

from requests.adapters import HTTPAdapter

from .controller import CacheController, PERMANENT_REDIRECT_STATUSES
from .cache import DictCache
from .filewrapper import CallbackFileWrapper
from cachecontrol.cache import DictCache
from cachecontrol.controller import PERMANENT_REDIRECT_STATUSES, CacheController
from cachecontrol.filewrapper import CallbackFileWrapper

if TYPE_CHECKING:
from requests import PreparedRequest, Response
from urllib3 import HTTPResponse

from cachecontrol.cache import BaseCache
from cachecontrol.heuristics import BaseHeuristic
from cachecontrol.serialize import Serializer


class CacheControlAdapter(HTTPAdapter):
invalidating_methods = {"PUT", "PATCH", "DELETE"}

def __init__(
self,
cache=None,
cache_etags=True,
controller_class=None,
serializer=None,
heuristic=None,
cacheable_methods=None,
*args,
**kw
):
super(CacheControlAdapter, self).__init__(*args, **kw)
cache: BaseCache | None = None,
cache_etags: bool = True,
controller_class: type[CacheController] | None = None,
serializer: Serializer | None = None,
heuristic: BaseHeuristic | None = None,
cacheable_methods: Collection[str] | None = None,
*args: Any,
**kw: Any,
) -> None:
super().__init__(*args, **kw)
self.cache = DictCache() if cache is None else cache
self.heuristic = heuristic
self.cacheable_methods = cacheable_methods or ("GET",)
Expand All @@ -37,7 +47,16 @@ def __init__(
self.cache, cache_etags=cache_etags, serializer=serializer
)

def send(self, request, cacheable_methods=None, **kw):
def send(
self,
request: PreparedRequest,
stream: bool = False,
timeout: None | float | tuple[float, float] | tuple[float, None] = None,
verify: bool | str = True,
cert: (None | bytes | str | tuple[bytes | str, bytes | str]) = None,
proxies: Mapping[str, str] | None = None,
cacheable_methods: Collection[str] | None = None,
) -> Response:
"""
Send a request. Use the request information to see if it
exists in the cache and cache the response if we need to and can.
Expand All @@ -54,13 +73,17 @@ def send(self, request, cacheable_methods=None, **kw):
# check for etags and add headers if appropriate
request.headers.update(self.controller.conditional_headers(request))

resp = super(CacheControlAdapter, self).send(request, **kw)
resp = super().send(request, stream, timeout, verify, cert, proxies)

return resp

def build_response(
self, request, response, from_cache=False, cacheable_methods=None
):
self,
request: PreparedRequest,
response: HTTPResponse,
from_cache: bool = False,
cacheable_methods: Collection[str] | None = None,
) -> Response:
"""
Build a response by making a request or using the cache.
Expand Down Expand Up @@ -102,36 +125,37 @@ def build_response(
else:
# Wrap the response file with a wrapper that will cache the
# response when the stream has been consumed.
response._fp = CallbackFileWrapper(
response._fp,
response._fp = CallbackFileWrapper( # type: ignore[attr-defined]
response._fp, # type: ignore[attr-defined]
functools.partial(
self.controller.cache_response, request, response
),
)
if response.chunked:
super_update_chunk_length = response._update_chunk_length
super_update_chunk_length = response._update_chunk_length # type: ignore[attr-defined]

def _update_chunk_length(self):
def _update_chunk_length(self: HTTPResponse) -> None:
super_update_chunk_length()
if self.chunk_left == 0:
self._fp._close()
self._fp._close() # type: ignore[attr-defined]

response._update_chunk_length = types.MethodType(
response._update_chunk_length = types.MethodType( # type: ignore[attr-defined]
_update_chunk_length, response
)

resp = super(CacheControlAdapter, self).build_response(request, response)
resp: Response = super().build_response(request, response) # type: ignore[no-untyped-call]

# See if we should invalidate the cache.
if request.method in self.invalidating_methods and resp.ok:
assert request.url is not None
cache_url = self.controller.cache_url(request.url)
self.cache.delete(cache_url)

# Give the request a from_cache attr to let people use it
resp.from_cache = from_cache
resp.from_cache = from_cache # type: ignore[attr-defined]

return resp

def close(self):
def close(self) -> None:
self.cache.close()
super(CacheControlAdapter, self).close()
super().close() # type: ignore[no-untyped-call]
33 changes: 21 additions & 12 deletions ext/cachecontrol/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,46 @@
The cache object API for implementing caches. The default is a thread
safe in-memory dictionary.
"""
from __future__ import annotations

from threading import Lock
from typing import IO, TYPE_CHECKING, MutableMapping

if TYPE_CHECKING:
from datetime import datetime

class BaseCache(object):

def get(self, key):
class BaseCache:
def get(self, key: str) -> bytes | None:
raise NotImplementedError()

def set(self, key, value, expires=None):
def set(
self, key: str, value: bytes, expires: int | datetime | None = None
) -> None:
raise NotImplementedError()

def delete(self, key):
def delete(self, key: str) -> None:
raise NotImplementedError()

def close(self):
def close(self) -> None:
pass


class DictCache(BaseCache):

def __init__(self, init_dict=None):
def __init__(self, init_dict: MutableMapping[str, bytes] | None = None) -> None:
self.lock = Lock()
self.data = init_dict or {}

def get(self, key):
def get(self, key: str) -> bytes | None:
return self.data.get(key, None)

def set(self, key, value, expires=None):
def set(
self, key: str, value: bytes, expires: int | datetime | None = None
) -> None:
with self.lock:
self.data.update({key: value})

def delete(self, key):
def delete(self, key: str) -> None:
with self.lock:
if key in self.data:
self.data.pop(key)
Expand All @@ -55,10 +63,11 @@ class SeparateBodyBaseCache(BaseCache):
Similarly, the body should be loaded separately via ``get_body()``.
"""
def set_body(self, key, body):

def set_body(self, key: str, body: bytes) -> None:
raise NotImplementedError()

def get_body(self, key):
def get_body(self, key: str) -> IO[bytes] | None:
"""
Return the body as file-like object.
"""
Expand Down
5 changes: 2 additions & 3 deletions ext/cachecontrol/caches/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

from .file_cache import FileCache, SeparateBodyFileCache
from .redis_cache import RedisCache

from cachecontrol.caches.file_cache import FileCache, SeparateBodyFileCache
from cachecontrol.caches.redis_cache import RedisCache

__all__ = ["FileCache", "SeparateBodyFileCache", "RedisCache"]

0 comments on commit 3d65665

Please sign in to comment.