diff --git a/_update_changes.py b/_update_changes.py index d0620e9..42fbb41 100644 --- a/_update_changes.py +++ b/_update_changes.py @@ -79,7 +79,13 @@ def get_version(project_file: Path): subprocess.run("copy docs\\_build\\markdown\\README.md .", shell=True) change_version() subprocess.run("black nodriver/core *.py") +modified_files = list( + m[1] for m in re.finditer("modified:\s+(.+)", subprocess.getoutput("git status")) +) +subprocess.run("git add " + " ".join(modified_files), shell=True) + subprocess.run("git status") + commit = input("commit message (use no quotes) :") if commit: subprocess.run(f'git commit -m "{commit}"') diff --git a/nodriver/core/_contradict.py b/nodriver/core/_contradict.py index c770361..89412e7 100644 --- a/nodriver/core/_contradict.py +++ b/nodriver/core/_contradict.py @@ -40,35 +40,28 @@ class ContraDict(dict): def __init__(self, *args, **kwargs): super().__init__() - silent = False - try: - silent = kwargs.pop("silent") - except: # noqa - pass + silent = kwargs.pop("silent", False) _ = dict(*args, **kwargs) - for key, val in _.copy().items(): - del _[key] - key = _camel_to_snake(key) - _[key] = val + + # for key, val in dict(*args, **kwargs).items(): + # _[key] = val super().__setattr__("__dict__", self) for k, v in _.items(): _check_key(k, self, False, silent) super().__setitem__(k, _wrap(self.__class__, v)) def __setitem__(self, key, value): - key = _camel_to_snake(key) super().__setitem__(key, _wrap(self.__class__, value)) def __setattr__(self, key, value): - key = _camel_to_snake(key) super().__setitem__(key, _wrap(self.__class__, value)) def __getattribute__(self, attribute): - attribute = _camel_to_snake(attribute) - if not _check_key(attribute, self, boolean=True, silent=True): - return getattr(super(), attribute) if attribute in self: return self[attribute] + if not _check_key(attribute, self, True, silent=True): + return getattr(super(), attribute) + return object.__getattribute__(self, attribute) @@ -122,32 +115,8 @@ def _check_key(key: str, mapping: _Mapping, boolean: bool = False, silent=False) return key if key.lower() in _warning_names or any(_ in key for _ in ("-", ".")): if not silent: - __logger__.warning(_warning_names_message.format(key)) + _warnings.warn(_warning_names_message.format(key)) e = True if not boolean: return key return not e - - -__RE_CAMEL_TO_SNAKE__ = re.compile("((?!^)(?" + + +async def resolve_node(tab: Tab, node_id: cdp.dom.NodeId): + remote_obj: cdp.runtime.RemoteObject = await tab.send( + cdp.dom.resolve_node(node_id=node_id) + ) + node_id: cdp.dom.NodeId = await tab.send(cdp.dom.request_node(remote_obj.object_id)) + node: cdp.dom.Node = await tab.send(cdp.dom.describe_node(node_id)) + return node diff --git a/nodriver/core/tab.py b/nodriver/core/tab.py index b2f374c..5d98d87 100644 --- a/nodriver/core/tab.py +++ b/nodriver/core/tab.py @@ -562,8 +562,8 @@ async def find_element_by_text( :rtype: """ doc = await self.send(cdp.dom.get_document(-1, True)) - search_id, nresult = await self.send(cdp.dom.perform_search(text, True)) text = text.strip() + search_id, nresult = await self.send(cdp.dom.perform_search(text, True)) node_ids = await self.send(cdp.dom.get_search_results(search_id, 0, nresult)) await self.send(cdp.dom.discard_search_results(search_id)) diff --git a/nodriver/core/util.py b/nodriver/core/util.py index c307067..8bf94de 100644 --- a/nodriver/core/util.py +++ b/nodriver/core/util.py @@ -160,9 +160,10 @@ def filter_recurse_all( if predicate(child): # if predicate is True out.append(child) + if child.shadow_roots is not None: + out.extend(filter_recurse_all(child.shadow_roots[0], predicate)) out.extend(filter_recurse_all(child, predicate)) - # if result: - # out.append(result) + return out @@ -182,6 +183,10 @@ def filter_recurse(doc: T, predicate: Callable[[cdp.dom.Node, Element], bool]) - if predicate(child): # if predicate is True return child + if child.shadow_roots: + shadow_root_result = filter_recurse(child.shadow_roots[0], predicate) + if shadow_root_result: + return shadow_root_result result = filter_recurse(child, predicate) if result: return result diff --git a/pyproject.toml b/pyproject.toml index dc105e2..0fbcb2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "nodriver" # Required -version = "0.32" # Required +version = "0.33" # Required description = """ @@ -64,6 +64,8 @@ classifiers = [ # Optional "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ]