perf: General code restructure to not use more than needed memory
This commit is contained in:
+2
-1
@@ -2,8 +2,9 @@ from pathlib import Path
|
|||||||
from subprocess import check_output
|
from subprocess import check_output
|
||||||
from sys import executable as python_executable
|
from sys import executable as python_executable
|
||||||
|
|
||||||
|
from scrapling.core.utils import log
|
||||||
from scrapling.engines.toolbelt.custom import Response
|
from scrapling.engines.toolbelt.custom import Response
|
||||||
from scrapling.core.utils import log, _CookieParser, _ParseHeaders
|
from scrapling.core.utils._shell import _CookieParser, _ParseHeaders
|
||||||
from scrapling.core._types import List, Optional, Dict, Tuple, Any, Callable
|
from scrapling.core._types import List, Optional, Dict, Tuple, Any, Callable
|
||||||
|
|
||||||
from orjson import loads as json_loads, JSONDecodeError
|
from orjson import loads as json_loads, JSONDecodeError
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ from logging import (
|
|||||||
from orjson import loads as json_loads, JSONDecodeError
|
from orjson import loads as json_loads, JSONDecodeError
|
||||||
|
|
||||||
from scrapling import __version__
|
from scrapling import __version__
|
||||||
|
from scrapling.core.utils import log
|
||||||
from scrapling.parser import Selector, Selectors
|
from scrapling.parser import Selector, Selectors
|
||||||
from scrapling.core.custom_types import TextHandler
|
from scrapling.core.custom_types import TextHandler
|
||||||
from scrapling.engines.toolbelt.custom import Response
|
from scrapling.engines.toolbelt.custom import Response
|
||||||
from scrapling.core.utils import log, _ParseHeaders, _CookieParser
|
from scrapling.core.utils._shell import _ParseHeaders, _CookieParser
|
||||||
from scrapling.core._types import (
|
from scrapling.core._types import (
|
||||||
Optional,
|
Optional,
|
||||||
Dict,
|
Dict,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from sqlite3 import connect as db_connect
|
|||||||
|
|
||||||
from orjson import dumps, loads
|
from orjson import dumps, loads
|
||||||
from lxml.html import HtmlElement
|
from lxml.html import HtmlElement
|
||||||
from tldextract import extract as tld
|
|
||||||
|
|
||||||
from scrapling.core.utils import _StorageTools, log
|
from scrapling.core.utils import _StorageTools, log
|
||||||
from scrapling.core._types import Dict, Optional, Any
|
from scrapling.core._types import Dict, Optional, Any
|
||||||
@@ -26,6 +25,8 @@ class StorageSystemMixin(ABC): # pragma: no cover
|
|||||||
return default_value
|
return default_value
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from tldextract import extract as tld
|
||||||
|
|
||||||
extracted = tld(self.url)
|
extracted = tld(self.url)
|
||||||
return extracted.top_domain_under_public_suffix or extracted.domain or default_value
|
return extracted.top_domain_under_public_suffix or extracted.domain or default_value
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|||||||
@@ -7,4 +7,3 @@ from ._utils import (
|
|||||||
clean_spaces,
|
clean_spaces,
|
||||||
html_forbidden,
|
html_forbidden,
|
||||||
)
|
)
|
||||||
from ._shell import _CookieParser, _ParseHeaders
|
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
import re
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
|
from re import Pattern as re_Pattern
|
||||||
|
|
||||||
from lxml.html import HtmlElement, HtmlMixin, HTMLParser
|
from lxml.html import HtmlElement, HtmlMixin, HTMLParser
|
||||||
from cssselect import SelectorError, SelectorSyntaxError, parse as split_selectors
|
from cssselect import SelectorError, SelectorSyntaxError, parse as split_selectors
|
||||||
@@ -751,7 +751,7 @@ class Selector(SelectorsGeneration):
|
|||||||
)
|
)
|
||||||
attributes.update(arg)
|
attributes.update(arg)
|
||||||
|
|
||||||
elif isinstance(arg, re.Pattern):
|
elif isinstance(arg, re_Pattern):
|
||||||
patterns.add(arg)
|
patterns.add(arg)
|
||||||
|
|
||||||
elif callable(arg):
|
elif callable(arg):
|
||||||
|
|||||||
Reference in New Issue
Block a user