style: replacing os with Pathlib and small optimizations

This commit is contained in:
Karim shoair
2025-07-30 01:15:28 +03:00
parent 18660f8132
commit e7cdd39695
4 changed files with 18 additions and 16 deletions
+4 -4
View File
@@ -1,13 +1,12 @@
from msgspec import Struct, convert, ValidationError
from urllib.parse import urlparse
from os.path import exists, isdir
from pathlib import Path
from scrapling.core._types import (
Optional,
Union,
Dict,
Callable,
Literal,
List,
SelectorWaitStates,
)
@@ -125,9 +124,10 @@ class CamoufoxConfig(Struct, kw_only=True, frozen=False):
self.addons = []
else:
for addon in self.addons:
if not exists(addon):
addon_path = Path(addon)
if not addon_path.exists():
raise FileNotFoundError(f"Addon's path not found: {addon}")
elif not isdir(addon):
elif not addon_path.is_dir():
raise ValueError(
f"Addon's path is not a folder, you need to pass a folder of the extracted addon: {addon}"
)
+6 -4
View File
@@ -2,17 +2,20 @@
Functions related to files and URLs
"""
import os
from pathlib import Path
from functools import lru_cache
from urllib.parse import urlencode, urlparse
from playwright.async_api import Route as async_Route
from msgspec import Struct, structs, convert, ValidationError
from playwright.sync_api import Route
from scrapling.core.utils import log
from scrapling.core._types import Dict, Optional, Union, Tuple
from scrapling.core.utils import log, lru_cache
from scrapling.engines.constants import DEFAULT_DISABLED_RESOURCES
__BYPASSES_DIR__ = Path(__file__).parent / "bypasses"
class ProxyDict(Struct):
server: str
@@ -129,5 +132,4 @@ def js_bypass_path(filename: str) -> str:
:param filename: The base filename of the JS file.
:return: The full path of the JS file.
"""
current_directory = os.path.dirname(__file__)
return os.path.join(current_directory, "bypasses", filename)
return str(__BYPASSES_DIR__ / filename)