Karim shoair commited on
Commit ·
bbd0c34
1
Parent(s): 87684d6
refactor: internal API changes
Browse files
scrapling/engines/static.py
CHANGED
|
@@ -600,6 +600,7 @@ class FetcherSession:
|
|
| 600 |
"_default_http3",
|
| 601 |
"selector_config",
|
| 602 |
"_client",
|
|
|
|
| 603 |
)
|
| 604 |
|
| 605 |
def __init__(
|
|
@@ -653,6 +654,7 @@ class FetcherSession:
|
|
| 653 |
self._default_cert = cert
|
| 654 |
self._default_http3 = http3
|
| 655 |
self.selector_config = selector_config or {}
|
|
|
|
| 656 |
self._client: _SyncSessionLogic | _ASyncSessionLogic | None = None
|
| 657 |
|
| 658 |
def __enter__(self) -> _SyncSessionLogic:
|
|
@@ -663,6 +665,7 @@ class FetcherSession:
|
|
| 663 |
config["stealthy_headers"] = self._stealth
|
| 664 |
config["selector_config"] = self.selector_config
|
| 665 |
self._client = _SyncSessionLogic(**config)
|
|
|
|
| 666 |
return self._client.__enter__()
|
| 667 |
raise RuntimeError("This FetcherSession instance already has an active synchronous session.")
|
| 668 |
|
|
@@ -670,6 +673,7 @@ class FetcherSession:
|
|
| 670 |
if self._client is not None and isinstance(self._client, _SyncSessionLogic):
|
| 671 |
self._client.__exit__(exc_type, exc_val, exc_tb)
|
| 672 |
self._client = None
|
|
|
|
| 673 |
return
|
| 674 |
raise RuntimeError("Cannot exit invalid session")
|
| 675 |
|
|
@@ -681,6 +685,7 @@ class FetcherSession:
|
|
| 681 |
config["stealthy_headers"] = self._stealth
|
| 682 |
config["selector_config"] = self.selector_config
|
| 683 |
self._client = _ASyncSessionLogic(**config)
|
|
|
|
| 684 |
return await self._client.__aenter__()
|
| 685 |
raise RuntimeError("This FetcherSession instance already has an active asynchronous session.")
|
| 686 |
|
|
@@ -688,6 +693,7 @@ class FetcherSession:
|
|
| 688 |
if self._client is not None and isinstance(self._client, _ASyncSessionLogic):
|
| 689 |
await self._client.__aexit__(exc_type, exc_val, exc_tb)
|
| 690 |
self._client = None
|
|
|
|
| 691 |
return
|
| 692 |
raise RuntimeError("Cannot exit invalid session")
|
| 693 |
|
|
|
|
| 600 |
"_default_http3",
|
| 601 |
"selector_config",
|
| 602 |
"_client",
|
| 603 |
+
"_is_alive",
|
| 604 |
)
|
| 605 |
|
| 606 |
def __init__(
|
|
|
|
| 654 |
self._default_cert = cert
|
| 655 |
self._default_http3 = http3
|
| 656 |
self.selector_config = selector_config or {}
|
| 657 |
+
self._is_alive = False
|
| 658 |
self._client: _SyncSessionLogic | _ASyncSessionLogic | None = None
|
| 659 |
|
| 660 |
def __enter__(self) -> _SyncSessionLogic:
|
|
|
|
| 665 |
config["stealthy_headers"] = self._stealth
|
| 666 |
config["selector_config"] = self.selector_config
|
| 667 |
self._client = _SyncSessionLogic(**config)
|
| 668 |
+
self._is_alive = True
|
| 669 |
return self._client.__enter__()
|
| 670 |
raise RuntimeError("This FetcherSession instance already has an active synchronous session.")
|
| 671 |
|
|
|
|
| 673 |
if self._client is not None and isinstance(self._client, _SyncSessionLogic):
|
| 674 |
self._client.__exit__(exc_type, exc_val, exc_tb)
|
| 675 |
self._client = None
|
| 676 |
+
self._is_alive = False
|
| 677 |
return
|
| 678 |
raise RuntimeError("Cannot exit invalid session")
|
| 679 |
|
|
|
|
| 685 |
config["stealthy_headers"] = self._stealth
|
| 686 |
config["selector_config"] = self.selector_config
|
| 687 |
self._client = _ASyncSessionLogic(**config)
|
| 688 |
+
self._is_alive = True
|
| 689 |
return await self._client.__aenter__()
|
| 690 |
raise RuntimeError("This FetcherSession instance already has an active asynchronous session.")
|
| 691 |
|
|
|
|
| 693 |
if self._client is not None and isinstance(self._client, _ASyncSessionLogic):
|
| 694 |
await self._client.__aexit__(exc_type, exc_val, exc_tb)
|
| 695 |
self._client = None
|
| 696 |
+
self._is_alive = False
|
| 697 |
return
|
| 698 |
raise RuntimeError("Cannot exit invalid session")
|
| 699 |
|