Skip to content

utils: remove custom memoize decorator #3486

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

Merged
merged 1 commit into from
Jan 30, 2021
Merged
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
4 changes: 2 additions & 2 deletions src/streamlink/plugins/wwenetwork.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import json
import logging
import re
from functools import lru_cache
from urllib.parse import parse_qsl, urlparse

from streamlink import PluginError
from streamlink.plugin import Plugin, PluginArgument, PluginArguments
from streamlink.plugin.api import useragents
from streamlink.stream import HLSStream
from streamlink.utils import memoize
from streamlink.utils.times import seconds_to_hhmmss

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -91,7 +91,7 @@ def login(self, email, password):
return self.auth_token

@property
@memoize
@lru_cache(maxsize=128)
def item_config(self):
log.debug("Loading page config")
p = urlparse(self.url)
Expand Down
5 changes: 3 additions & 2 deletions src/streamlink/session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import pkgutil
from collections import OrderedDict
from functools import lru_cache

import requests

Expand All @@ -10,7 +11,7 @@
from streamlink.logger import StreamlinkLogger
from streamlink.options import Options
from streamlink.plugin import Plugin, api
from streamlink.utils import load_module, memoize, update_scheme
from streamlink.utils import load_module, update_scheme
from streamlink.utils.l10n import Localization

# Ensure that the Logger class returned is Streamslink's for using the API (for backwards compatibility)
Expand Down Expand Up @@ -337,7 +338,7 @@ def get_plugin_option(self, plugin, key):
plugin = self.plugins[plugin]
return plugin.get_option(key)

@memoize
@lru_cache(maxsize=128)
def resolve_url(self, url, follow_redirect=True):
"""Attempts to find a plugin that can use this URL.

Expand Down
13 changes: 0 additions & 13 deletions src/streamlink/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import functools
import json
import re
import xml.etree.ElementTree as ET
Expand Down Expand Up @@ -151,18 +150,6 @@ def rtmpparse(url):
return tcurl, playpath


def memoize(obj):
cache = obj.cache = {}

@functools.wraps(obj)
def memoizer(*args, **kwargs):
key = str(args) + str(kwargs)
if key not in cache:
cache[key] = obj(*args, **kwargs)
return cache[key]
return memoizer


def search_dict(data, key):
"""
Search for a key in a nested dict, or list of nested dicts, and return the values.
Expand Down
1 change: 1 addition & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_resolve_url(self):
plugin = session.resolve_url("http://test.se/channel")
self.assertTrue(isinstance(plugin, Plugin))
self.assertTrue(isinstance(plugin, plugins["testplugin"]))
self.assertTrue(hasattr(session.resolve_url, "cache_info"), "resolve_url has a lookup cache")

def test_resolve_url_priority(self):
from tests.plugin.testplugin import TestPlugin
Expand Down