ver Jan15thv2
thunderbird example w.r.t. unified folder
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import logging
|
||||
import zipfile
|
||||
from typing import Any
|
||||
from typing import Dict, List, Set
|
||||
from typing import Any, TypeVar, Union, Iterable, Optional
|
||||
from typing import Dict, List, Set, Match
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
import re
|
||||
import functools
|
||||
import operator
|
||||
|
||||
import lxml.cssselect
|
||||
import lxml.etree
|
||||
@@ -13,6 +16,8 @@ from openpyxl import Workbook
|
||||
from openpyxl.chart._chart import ChartBase
|
||||
from openpyxl.worksheet.worksheet import Worksheet
|
||||
|
||||
V = TypeVar("Value")
|
||||
|
||||
logger = logging.getLogger("desktopenv.metrics.utils")
|
||||
|
||||
_xlsx_namespaces = [("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main")
|
||||
@@ -133,6 +138,34 @@ def load_charts(xlsx_file: Workbook, **options) -> Dict[str, Any]:
|
||||
def _match_record(pattern: Dict[str, Any], item: Dict[str, Any]) -> bool:
|
||||
return all(k in item and item[k] == val for k, val in pattern.items())
|
||||
|
||||
def _match_value_to_rule(value: V, rule: Dict[str, Union[str, V]]) -> bool:
|
||||
"""
|
||||
Args:
|
||||
value (V): value to match
|
||||
rule (Dict[str, Union[str, V]]): rule dict like
|
||||
{
|
||||
"method": str
|
||||
"ref": V as ref value
|
||||
}
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
|
||||
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()
|
||||
|
||||
def are_lists_equal(list1, list2, comparison_func):
|
||||
# First check if both lists have the same length
|
||||
|
||||
Reference in New Issue
Block a user