Forgot to port parsing of open actions to use the new action_alias infra
This commit is contained in:
parent
d7df4fa5dc
commit
cecca854c0
@ -13,9 +13,7 @@ from urllib.parse import ParseResult, unquote, urlparse
|
|||||||
from .conf.utils import KeyAction, to_cmdline_implementation
|
from .conf.utils import KeyAction, to_cmdline_implementation
|
||||||
from .constants import config_dir
|
from .constants import config_dir
|
||||||
from .guess_mime_type import guess_type
|
from .guess_mime_type import guess_type
|
||||||
from .options.utils import (
|
from .options.utils import ActionAlias, resolve_aliases_and_parse_actions
|
||||||
ActionAlias, action_alias, parse_key_actions, resolve_aliases_in_action
|
|
||||||
)
|
|
||||||
from .types import run_once
|
from .types import run_once
|
||||||
from .typing import MatchType
|
from .typing import MatchType
|
||||||
from .utils import expandvars, log_error
|
from .utils import expandvars, log_error
|
||||||
@ -33,7 +31,7 @@ class OpenAction(NamedTuple):
|
|||||||
|
|
||||||
def parse(lines: Iterable[str]) -> Iterator[OpenAction]:
|
def parse(lines: Iterable[str]) -> Iterator[OpenAction]:
|
||||||
match_criteria: List[MatchCriteria] = []
|
match_criteria: List[MatchCriteria] = []
|
||||||
actions: List[KeyAction] = []
|
raw_actions: List[str] = []
|
||||||
alias_map: Dict[str, List[ActionAlias]] = {}
|
alias_map: Dict[str, List[ActionAlias]] = {}
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
@ -42,10 +40,10 @@ def parse(lines: Iterable[str]) -> Iterator[OpenAction]:
|
|||||||
if line.startswith('#'):
|
if line.startswith('#'):
|
||||||
continue
|
continue
|
||||||
if not line:
|
if not line:
|
||||||
if match_criteria and actions:
|
if match_criteria and raw_actions:
|
||||||
entries.append((tuple(match_criteria), tuple(actions)))
|
entries.append((tuple(match_criteria), tuple(raw_actions)))
|
||||||
match_criteria = []
|
match_criteria = []
|
||||||
actions = []
|
raw_actions = []
|
||||||
continue
|
continue
|
||||||
parts = line.split(maxsplit=1)
|
parts = line.split(maxsplit=1)
|
||||||
if len(parts) != 2:
|
if len(parts) != 2:
|
||||||
@ -53,23 +51,30 @@ def parse(lines: Iterable[str]) -> Iterator[OpenAction]:
|
|||||||
key, rest = parts
|
key, rest = parts
|
||||||
key = key.lower()
|
key = key.lower()
|
||||||
if key == 'action':
|
if key == 'action':
|
||||||
with to_cmdline_implementation.filter_env_vars('URL', 'FILE_PATH', 'FILE', 'FRAGMENT'):
|
raw_actions.append(rest)
|
||||||
for x in parse_key_actions(rest):
|
# with to_cmdline_implementation.filter_env_vars('URL', 'FILE_PATH', 'FILE', 'FRAGMENT'):
|
||||||
actions.append(x)
|
# for x in parse_key_actions(rest):
|
||||||
|
# actions.append(x)
|
||||||
elif key in ('mime', 'ext', 'protocol', 'file', 'path', 'url', 'fragment_matches'):
|
elif key in ('mime', 'ext', 'protocol', 'file', 'path', 'url', 'fragment_matches'):
|
||||||
if key != 'url':
|
if key != 'url':
|
||||||
rest = rest.lower()
|
rest = rest.lower()
|
||||||
match_criteria.append(MatchCriteria(cast(MatchType, key), rest))
|
match_criteria.append(MatchCriteria(cast(MatchType, key), rest))
|
||||||
elif key == 'action_alias':
|
elif key == 'action_alias':
|
||||||
for (alias_name, args) in action_alias(rest):
|
alias_name, alias_val = rest.split(maxsplit=1)
|
||||||
alias_map[alias_name] = [ActionAlias(args[0], args=tuple(args[1:]))]
|
is_recursive = alias_name == alias_val.split(maxsplit=1)[0]
|
||||||
|
alias_map[alias_name] = [ActionAlias(alias_name, alias_val, is_recursive)]
|
||||||
else:
|
else:
|
||||||
log_error(f'Ignoring malformed open actions line: {line}')
|
log_error(f'Ignoring malformed open actions line: {line}')
|
||||||
|
|
||||||
for (mc, ac) in entries:
|
if match_criteria and raw_actions:
|
||||||
yield OpenAction(mc, tuple(resolve_aliases_in_action(a, alias_map) for a in ac))
|
entries.append((tuple(match_criteria), tuple(raw_actions)))
|
||||||
if match_criteria and actions:
|
|
||||||
yield OpenAction(tuple(match_criteria), tuple(resolve_aliases_in_action(a, alias_map) for a in actions))
|
for (mc, action_defns) in entries:
|
||||||
|
actions: List[KeyAction] = []
|
||||||
|
with to_cmdline_implementation.filter_env_vars('URL', 'FILE_PATH', 'FILE', 'FRAGMENT'):
|
||||||
|
for defn in action_defns:
|
||||||
|
actions.extend(resolve_aliases_and_parse_actions(defn, alias_map, 'open_action'))
|
||||||
|
yield OpenAction(mc, tuple(actions))
|
||||||
|
|
||||||
|
|
||||||
def url_matches_criterion(purl: 'ParseResult', url: str, unquoted_path: str, mc: MatchCriteria) -> bool:
|
def url_matches_criterion(purl: 'ParseResult', url: str, unquoted_path: str, mc: MatchCriteria) -> bool:
|
||||||
|
|||||||
@ -2896,7 +2896,7 @@ prefer to use :opt:`action_alias`. This option is a legacy
|
|||||||
version, present for backwards compatibility. It causes all invocations
|
version, present for backwards compatibility. It causes all invocations
|
||||||
of the aliased kitten to be substituted. So the example above will cause
|
of the aliased kitten to be substituted. So the example above will cause
|
||||||
all invocations of the hints kitten to have the :code:`--hints-offset=0`
|
all invocations of the hints kitten to have the :code:`--hints-offset=0`
|
||||||
option applied.
|
option appliedLeave kitten_alias documented.
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user