Skip to content

Commit

Permalink
Revert "Fix some mypy errors"
Browse files Browse the repository at this point in the history
Python in R4.1's dom0 is too old for some of those constructs:

    Traceback (most recent call last):
      File "/usr/bin/qrexec-policy-daemon", line 2, in <module>
        from qrexec.tools.qrexec_policy_daemon import main
      File "/usr/lib/python3.8/site-packages/qrexec/tools/qrexec_policy_daemon.py", line 29, in <module>
        from .qrexec_policy_exec import handle_request
      File "/usr/lib/python3.8/site-packages/qrexec/tools/qrexec_policy_exec.py", line 31, in <module>
        from ..policy import parser
      File "/usr/lib/python3.8/site-packages/qrexec/policy/parser.py", line 188, in <module>
        class VMTokenMeta(abc.ABCMeta):
      File "/usr/lib/python3.8/site-packages/qrexec/policy/parser.py", line 190, in VMTokenMeta
        exacts: collections.OrderedDict[str, Type[str]] = collections.OrderedDict()
    TypeError: 'type' object is not subscriptable

This reverts commit c97b0d7.
  • Loading branch information
marmarek committed May 22, 2023
1 parent 9439779 commit f0b1904
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions qrexec/policy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
Tuple,
Dict,
Optional,
Set,
Union,
Type,
)

from .. import QREXEC_CLIENT, POLICYPATH, RPCNAME_ALLOWED_CHARSET, POLICYSUFFIX
Expand Down Expand Up @@ -92,7 +89,7 @@ def filter_filepaths(filepaths: Iterable[pathlib.Path]) -> List[pathlib.Path]:
return filepaths


def parse_service_and_argument(rpcname: Union[str, pathlib.PurePath], *, no_arg: str ="+"):
def parse_service_and_argument(rpcname, *, no_arg="+"):
"""Parse service and argument string.
Parse ``SERVICE+ARGUMENT``. Argument may be empty (single ``+`` at the end)
Expand Down Expand Up @@ -187,8 +184,8 @@ def validate_service_and_argument(service, argument, *, filepath, lineno):

class VMTokenMeta(abc.ABCMeta):
# pylint: disable=missing-docstring
exacts: collections.OrderedDict[str, Type[str]] = collections.OrderedDict()
prefixes: collections.OrderedDict[str, Type[str]] = collections.OrderedDict()
exacts = collections.OrderedDict()
prefixes = collections.OrderedDict()

def __init__(cls, name, bases, dict_):
super().__init__(name, bases, dict_)
Expand Down Expand Up @@ -565,7 +562,7 @@ def __init__(self, rule, request, *, user):
self.notify = rule.action.notify

@abc.abstractmethod
async def execute(self, caller_ident: str) -> str:
async def execute(self, caller_ident):
"""
Execute the action. For allow, this runs the qrexec. For ask, it asks
user and then (depending on verdict) runs the call.
Expand Down Expand Up @@ -755,7 +752,7 @@ def handle_invalid_response(self):
# pylint: disable=no-self-use
raise AccessDenied("invalid response")

async def execute(self, caller_ident: str) -> str:
async def execute(self, caller_ident):
"""Ask the user for permission.
This method should be overloaded in children classes. This
Expand Down Expand Up @@ -1569,7 +1566,7 @@ def collect_targets_for_ask(self, request):
Word 'targets' is used intentionally instead of 'domains', because it
can also contains @dispvm like keywords.
"""
targets: Set[str] = set()
targets = set()

# iterate over rules in reversed order to easier handle 'deny'
# actions - simply remove matching domains from allowed set
Expand Down Expand Up @@ -1632,23 +1629,22 @@ def resolve_filepath(
Raises:
qrexec.exc.PolicySyntaxError: when the path does not point to a file
"""
resolved_included_path: pathlib.Path = self.resolve_path(included_path)
if not resolved_included_path.is_file():
included_path = self.resolve_path(included_path)
if not included_path.is_file():
raise exc.PolicySyntaxError(
filepath, lineno, "not a file: {}".format(resolved_included_path)
filepath, lineno, "not a file: {}".format(included_path)
)
# pylint: disable=consider-using-with
return (open(str(resolved_included_path), encoding='utf-8'),
pathlib.PurePath(resolved_included_path))
return open(str(included_path), encoding='utf-8'), included_path

def handle_include(
self, included_path: pathlib.PurePosixPath, *, filepath, lineno
):
file, resolved_included_path = self.resolve_filepath(
file, included_path = self.resolve_filepath(
included_path, filepath=filepath, lineno=lineno
)
with file:
self.load_policy_file(file, resolved_included_path)
self.load_policy_file(file, pathlib.PurePosixPath(included_path))

def handle_include_service(
self,
Expand All @@ -1662,12 +1658,12 @@ def handle_include_service(
service, argument = validate_service_and_argument(
service, argument, filepath=filepath, lineno=lineno
)
file, resolved_included_path = self.resolve_filepath(
file, included_path = self.resolve_filepath(
included_path, filepath=filepath, lineno=lineno
)
with file:
self.load_policy_file_service(
service, argument, file, resolved_included_path
service, argument, file, pathlib.PurePosixPath(included_path)
)


Expand All @@ -1685,20 +1681,20 @@ def resolve_dirpath(
qrexec.exc.PolicySyntaxError: when the path does not point to
a directory
"""
resolved_included_path = self.resolve_path(included_path)
if not resolved_included_path.is_dir():
included_path = self.resolve_path(included_path)
if not included_path.is_dir():
raise exc.PolicySyntaxError(
filepath, lineno, "not a directory: {}".format(resolved_included_path)
filepath, lineno, "not a directory: {}".format(included_path)
)
return resolved_included_path
return included_path

def handle_include_dir(
self, included_path: pathlib.PurePosixPath, *, filepath, lineno
):
resolved_included_path = self.resolve_dirpath(
included_path = self.resolve_dirpath(
included_path, filepath=filepath, lineno=lineno
)
self.load_policy_dir(resolved_included_path)
self.load_policy_dir(included_path)

def load_policy_dir(self, dirpath):
"""Load all files in the directory (``!include-dir``)
Expand Down Expand Up @@ -1906,7 +1902,7 @@ def handle_include(
filepath,
)
self.save_included_path(included_path, filepath=filepath, lineno=lineno)
super().handle_include(included_path, filepath=filepath, lineno=lineno) # type: ignore
super().handle_include(included_path, filepath=filepath, lineno=lineno)

def handle_include_service(
self,
Expand All @@ -1924,7 +1920,7 @@ def handle_include_service(
filepath,
)
self.save_included_path(included_path, filepath=filepath, lineno=lineno)
super().handle_include_service( # type: ignore
super().handle_include_service(
service, argument, included_path, filepath=filepath, lineno=lineno
)

Expand All @@ -1949,13 +1945,7 @@ def __init__(self, *args, policy, **kwds):
super().__init__(*args, **kwds)
self.policy = policy

def resolve_filepath(
self,
included_path,
*,
filepath,
lineno,
) -> Tuple[TextIO, pathlib.PurePath]:
def resolve_filepath(self, included_path, *, filepath, lineno):
"""
Raises:
qrexec.exc.PolicySyntaxError: when wrong path is included
Expand Down

0 comments on commit f0b1904

Please sign in to comment.