style(utils): optimize imports
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
|
||||||
from itertools import chain
|
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 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
|
# 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
|
from functools import lru_cache # isort:skip
|
||||||
@@ -15,7 +15,7 @@ html_forbidden = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__CLEANING_TABLE__ = str.maketrans({"\t": " ", "\n": None, "\r": None})
|
__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)
|
@lru_cache(1, typed=True)
|
||||||
@@ -49,9 +49,9 @@ def is_jsonable(content: bytes | str) -> bool:
|
|||||||
content = content.decode()
|
content = content.decode()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_ = orjson.loads(content)
|
_ = orjson_loads(content)
|
||||||
return True
|
return True
|
||||||
except orjson.JSONDecodeError:
|
except JSONDecodeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user