Skip to content

🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev

style(utils): optimize imports

Karim shoairca12a11b7e5f
diff --git a/scrapling/core/utils.py b/scrapling/core/utils.py
index f6d6c41..a78afbd 100644
--- a/scrapling/core/utils.py
+++ b/scrapling/core/utils.py
@@ -1,11 +1,11 @@
import logging
-import re
from itertools import chain
+from re import compile as re_compile
-import orjson
+from orjson import loads as orjson_loads, JSONDecodeError
from lxml import html
-from scrapling.core._types import Any, Dict, Iterable, Union, List
+from scrapling.core._types import Any, Dict, Iterable, List
# Using cache on top of a class is a brilliant way to achieve a Singleton design pattern without much code
from functools import lru_cache # isort:skip
@@ -15,7 +15,7 @@ html_forbidden = {
}
__CLEANING_TABLE__ = str.maketrans({"\t": " ", "\n": None, "\r": None})
-__CONSECUTIVE_SPACES_REGEX__ = re.compile(r" +")
+__CONSECUTIVE_SPACES_REGEX__ = re_compile(r" +")
@lru_cache(1, typed=True)
@@ -49,9 +49,9 @@ def is_jsonable(content: bytes | str) -> bool:
content = content.decode()
try:
- _ = orjson.loads(content)
+ _ = orjson_loads(content)
return True
- except orjson.JSONDecodeError:
+ except JSONDecodeError:
return False