ver Jan15thv2
thunderbird example w.r.t. unified folder
This commit is contained in:
@@ -1,35 +1,16 @@
|
||||
from typing import List, Pattern, Dict, Match, Tuple
|
||||
from typing import Union, Any, Optional, Iterable, TypeVar, Callable
|
||||
from typing import List, Pattern, Dict, Match
|
||||
from typing import Union, Any, TypeVar, Callable
|
||||
|
||||
import re
|
||||
import functools
|
||||
import operator
|
||||
import json
|
||||
from .utils import _match_record
|
||||
from .utils import _match_value_to_rule as _match_pref
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger("desktopenv.metric.thunderbird")
|
||||
|
||||
V = TypeVar("Value")
|
||||
|
||||
def _match_pref(value: Any, rule: Dict[str, Union[str, Any]]) -> bool:
|
||||
# function _match_pref {{{ #
|
||||
if rule["method"].startswith("re"):
|
||||
flags: List[str] = rule["method"].split(".")[1:]
|
||||
flags: Iterable[re.RegexFlag] = (getattr(re, fl) for fl in flags)
|
||||
flag: re.RegexFlag = functools.reduce(operator.or_, flags, re.RegexFlag(0))
|
||||
logger.debug("REFLAG: %s", repr(flag))
|
||||
|
||||
match_: Optional[Match[str]] = re.search(rule["ref"], value, flag)
|
||||
return match_ is not None
|
||||
if rule["method"] in { "eq", "ne"
|
||||
, "le", "lt"
|
||||
, "ge", "gt"
|
||||
}:
|
||||
return getattr(operator, rule["method"])(value, rule["ref"])
|
||||
raise NotImplementedError()
|
||||
# }}} function _match_pref #
|
||||
|
||||
_pref_pattern: Pattern[str] = re.compile(r'^user_pref\("(?P<key>(?:[^"]|\\")+)\", (?P<val>.+)\);$');
|
||||
def check_thunderbird_prefs(result: str, rule: Dict[str, Dict[str, Dict[str, Any]]]):
|
||||
"""
|
||||
@@ -148,9 +129,9 @@ def check_thunderbird_filter(result: str, rules: Dict[str, List[Dict[str, str]]]
|
||||
return float(all(expect_metrics) and unexpect_metric)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import lxml.etree
|
||||
from lxml.cssselect import CSSSelector
|
||||
from lxml.etree import _Element
|
||||
#import lxml.etree
|
||||
#from lxml.cssselect import CSSSelector
|
||||
#from lxml.etree import _Element
|
||||
|
||||
#xml = "../../任务数据/Thunderbird/vertical-card-view.xml"
|
||||
#xml = "../../任务数据/Thunderbird/vertical-table-view.xml"
|
||||
|
||||
Reference in New Issue
Block a user