forked from kenzuya/unshackle
refactor(drm): drop the hardcoded service branch in the license flow
One service needed session_id in its license call, which a near-duplicate of get_content_keys supplied behind a service-tag test. service_licence now passes each service only the arguments its own license function declares, so the duplicate and the branch are gone. The REST API license paths and the base PlayReady delegate get the same filtering, replacing their fixed argument set. Two behaviour changes ride along: an empty license challenge now raises EmptyLicense for every service, not just the one, and a service that declares only challenge now receives a working call instead of a TypeError.
This commit is contained in:
@@ -2,6 +2,7 @@ import ast
|
||||
import contextlib
|
||||
import gzip
|
||||
import importlib.util
|
||||
import inspect
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@@ -16,7 +17,7 @@ from collections import defaultdict
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from types import ModuleType
|
||||
from typing import Any, Optional, Sequence, Union
|
||||
from typing import Any, Callable, Optional, Sequence, Union
|
||||
from urllib.parse import ParseResult, urlparse
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -1254,6 +1255,23 @@ def close_debug_logger():
|
||||
debug_logger = None
|
||||
|
||||
|
||||
def declared_kwargs(fn: Callable[..., Any], kwargs: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Keep only the arguments ``fn`` declares, so an extra one never raises TypeError.
|
||||
|
||||
A service licence function that never asked for ``pssh`` or ``session_id`` must not fail
|
||||
on them. Filter only against a signature this function can read and call by keyword.
|
||||
Anything else, such as the licence function of a compiled service, gets every argument,
|
||||
and the caller handles the TypeError.
|
||||
"""
|
||||
try:
|
||||
params = inspect.signature(fn).parameters
|
||||
except (TypeError, ValueError):
|
||||
return kwargs
|
||||
if "challenge" not in params or any(p.kind is p.VAR_KEYWORD for p in params.values()):
|
||||
return kwargs
|
||||
return {k: v for k, v in kwargs.items() if k in params}
|
||||
|
||||
|
||||
__all__ = (
|
||||
"DebugLogger",
|
||||
"get_debug_logger",
|
||||
|
||||
Reference in New Issue
Block a user