style: Using keywords for validation
Less lines of code and more stylish
This commit is contained in:
@@ -144,56 +144,8 @@ class AsyncSession(SyncSession):
|
|||||||
|
|
||||||
|
|
||||||
class DynamicSessionMixin:
|
class DynamicSessionMixin:
|
||||||
def __validate__(
|
def __validate__(self, **params):
|
||||||
self,
|
config = validate(**params, model=PlaywrightConfig)
|
||||||
__max_pages,
|
|
||||||
headless,
|
|
||||||
google_search,
|
|
||||||
hide_canvas,
|
|
||||||
disable_webgl,
|
|
||||||
real_chrome,
|
|
||||||
stealth,
|
|
||||||
wait,
|
|
||||||
page_action,
|
|
||||||
proxy,
|
|
||||||
locale,
|
|
||||||
extra_headers,
|
|
||||||
useragent,
|
|
||||||
cdp_url,
|
|
||||||
timeout,
|
|
||||||
disable_resources,
|
|
||||||
wait_selector,
|
|
||||||
init_script,
|
|
||||||
cookies,
|
|
||||||
network_idle,
|
|
||||||
wait_selector_state,
|
|
||||||
selector_config,
|
|
||||||
):
|
|
||||||
params = {
|
|
||||||
"max_pages": __max_pages,
|
|
||||||
"headless": headless,
|
|
||||||
"google_search": google_search,
|
|
||||||
"hide_canvas": hide_canvas,
|
|
||||||
"disable_webgl": disable_webgl,
|
|
||||||
"real_chrome": real_chrome,
|
|
||||||
"stealth": stealth,
|
|
||||||
"wait": wait,
|
|
||||||
"page_action": page_action,
|
|
||||||
"proxy": proxy,
|
|
||||||
"locale": locale,
|
|
||||||
"extra_headers": extra_headers,
|
|
||||||
"useragent": useragent,
|
|
||||||
"timeout": timeout,
|
|
||||||
"selector_config": selector_config,
|
|
||||||
"disable_resources": disable_resources,
|
|
||||||
"wait_selector": wait_selector,
|
|
||||||
"init_script": init_script,
|
|
||||||
"cookies": cookies,
|
|
||||||
"network_idle": network_idle,
|
|
||||||
"wait_selector_state": wait_selector_state,
|
|
||||||
"cdp_url": cdp_url,
|
|
||||||
}
|
|
||||||
config = validate(params, PlaywrightConfig)
|
|
||||||
|
|
||||||
self.max_pages = config.max_pages
|
self.max_pages = config.max_pages
|
||||||
self.headless = config.headless
|
self.headless = config.headless
|
||||||
@@ -268,62 +220,8 @@ class DynamicSessionMixin:
|
|||||||
|
|
||||||
|
|
||||||
class StealthySessionMixin:
|
class StealthySessionMixin:
|
||||||
def __validate__(
|
def __validate__(self, **params):
|
||||||
self,
|
config = validate(**params, model=CamoufoxConfig)
|
||||||
max_pages,
|
|
||||||
headless,
|
|
||||||
block_images,
|
|
||||||
disable_resources,
|
|
||||||
block_webrtc,
|
|
||||||
allow_webgl,
|
|
||||||
network_idle,
|
|
||||||
humanize,
|
|
||||||
solve_cloudflare,
|
|
||||||
wait,
|
|
||||||
timeout,
|
|
||||||
page_action,
|
|
||||||
wait_selector,
|
|
||||||
init_script,
|
|
||||||
addons,
|
|
||||||
wait_selector_state,
|
|
||||||
cookies,
|
|
||||||
google_search,
|
|
||||||
extra_headers,
|
|
||||||
proxy,
|
|
||||||
os_randomize,
|
|
||||||
disable_ads,
|
|
||||||
geoip,
|
|
||||||
selector_config,
|
|
||||||
additional_args,
|
|
||||||
):
|
|
||||||
params = {
|
|
||||||
"max_pages": max_pages,
|
|
||||||
"headless": headless,
|
|
||||||
"block_images": block_images,
|
|
||||||
"disable_resources": disable_resources,
|
|
||||||
"block_webrtc": block_webrtc,
|
|
||||||
"allow_webgl": allow_webgl,
|
|
||||||
"network_idle": network_idle,
|
|
||||||
"humanize": humanize,
|
|
||||||
"solve_cloudflare": solve_cloudflare,
|
|
||||||
"wait": wait,
|
|
||||||
"timeout": timeout,
|
|
||||||
"page_action": page_action,
|
|
||||||
"wait_selector": wait_selector,
|
|
||||||
"init_script": init_script,
|
|
||||||
"addons": addons,
|
|
||||||
"wait_selector_state": wait_selector_state,
|
|
||||||
"cookies": cookies,
|
|
||||||
"google_search": google_search,
|
|
||||||
"extra_headers": extra_headers,
|
|
||||||
"proxy": proxy,
|
|
||||||
"os_randomize": os_randomize,
|
|
||||||
"disable_ads": disable_ads,
|
|
||||||
"geoip": geoip,
|
|
||||||
"selector_config": selector_config,
|
|
||||||
"additional_args": additional_args,
|
|
||||||
}
|
|
||||||
config = validate(params, CamoufoxConfig)
|
|
||||||
|
|
||||||
self.max_pages = config.max_pages
|
self.max_pages = config.max_pages
|
||||||
self.headless = config.headless
|
self.headless = config.headless
|
||||||
|
|||||||
@@ -133,31 +133,31 @@ class StealthySession(StealthySessionMixin, SyncSession):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.__validate__(
|
self.__validate__(
|
||||||
__max_pages,
|
wait=wait,
|
||||||
headless,
|
proxy=proxy,
|
||||||
block_images,
|
geoip=geoip,
|
||||||
disable_resources,
|
addons=addons,
|
||||||
block_webrtc,
|
timeout=timeout,
|
||||||
allow_webgl,
|
cookies=cookies,
|
||||||
network_idle,
|
headless=headless,
|
||||||
humanize,
|
humanize=humanize,
|
||||||
solve_cloudflare,
|
max_pages=__max_pages,
|
||||||
wait,
|
disable_ads=disable_ads,
|
||||||
timeout,
|
allow_webgl=allow_webgl,
|
||||||
page_action,
|
page_action=page_action,
|
||||||
wait_selector,
|
init_script=init_script,
|
||||||
init_script,
|
network_idle=network_idle,
|
||||||
addons,
|
block_images=block_images,
|
||||||
wait_selector_state,
|
block_webrtc=block_webrtc,
|
||||||
cookies,
|
os_randomize=os_randomize,
|
||||||
google_search,
|
wait_selector=wait_selector,
|
||||||
extra_headers,
|
google_search=google_search,
|
||||||
proxy,
|
extra_headers=extra_headers,
|
||||||
os_randomize,
|
additional_args=additional_args,
|
||||||
disable_ads,
|
selector_config=selector_config,
|
||||||
geoip,
|
solve_cloudflare=solve_cloudflare,
|
||||||
selector_config,
|
disable_resources=disable_resources,
|
||||||
additional_args,
|
wait_selector_state=wait_selector_state,
|
||||||
)
|
)
|
||||||
super().__init__(max_pages=self.max_pages)
|
super().__init__(max_pages=self.max_pages)
|
||||||
|
|
||||||
@@ -447,31 +447,31 @@ class AsyncStealthySession(StealthySessionMixin, AsyncSession):
|
|||||||
:param additional_args: Additional arguments to be passed to Camoufox as additional settings, and it takes higher priority than Scrapling's settings.
|
:param additional_args: Additional arguments to be passed to Camoufox as additional settings, and it takes higher priority than Scrapling's settings.
|
||||||
"""
|
"""
|
||||||
self.__validate__(
|
self.__validate__(
|
||||||
max_pages,
|
wait=wait,
|
||||||
headless,
|
proxy=proxy,
|
||||||
block_images,
|
geoip=geoip,
|
||||||
disable_resources,
|
addons=addons,
|
||||||
block_webrtc,
|
timeout=timeout,
|
||||||
allow_webgl,
|
cookies=cookies,
|
||||||
network_idle,
|
headless=headless,
|
||||||
humanize,
|
humanize=humanize,
|
||||||
solve_cloudflare,
|
max_pages=max_pages,
|
||||||
wait,
|
disable_ads=disable_ads,
|
||||||
timeout,
|
allow_webgl=allow_webgl,
|
||||||
page_action,
|
page_action=page_action,
|
||||||
wait_selector,
|
init_script=init_script,
|
||||||
init_script,
|
network_idle=network_idle,
|
||||||
addons,
|
block_images=block_images,
|
||||||
wait_selector_state,
|
block_webrtc=block_webrtc,
|
||||||
cookies,
|
os_randomize=os_randomize,
|
||||||
google_search,
|
wait_selector=wait_selector,
|
||||||
extra_headers,
|
google_search=google_search,
|
||||||
proxy,
|
extra_headers=extra_headers,
|
||||||
os_randomize,
|
additional_args=additional_args,
|
||||||
disable_ads,
|
selector_config=selector_config,
|
||||||
geoip,
|
solve_cloudflare=solve_cloudflare,
|
||||||
selector_config,
|
disable_resources=disable_resources,
|
||||||
additional_args,
|
wait_selector_state=wait_selector_state,
|
||||||
)
|
)
|
||||||
super().__init__(max_pages=self.max_pages)
|
super().__init__(max_pages=self.max_pages)
|
||||||
|
|
||||||
|
|||||||
@@ -122,28 +122,28 @@ class DynamicSession(DynamicSessionMixin, SyncSession):
|
|||||||
:param selector_config: The arguments that will be passed in the end while creating the final Selector's class.
|
:param selector_config: The arguments that will be passed in the end while creating the final Selector's class.
|
||||||
"""
|
"""
|
||||||
self.__validate__(
|
self.__validate__(
|
||||||
__max_pages,
|
wait=wait,
|
||||||
headless,
|
proxy=proxy,
|
||||||
google_search,
|
locale=locale,
|
||||||
hide_canvas,
|
timeout=timeout,
|
||||||
disable_webgl,
|
stealth=stealth,
|
||||||
real_chrome,
|
cdp_url=cdp_url,
|
||||||
stealth,
|
cookies=cookies,
|
||||||
wait,
|
headless=headless,
|
||||||
page_action,
|
useragent=useragent,
|
||||||
proxy,
|
max_pages=__max_pages,
|
||||||
locale,
|
real_chrome=real_chrome,
|
||||||
extra_headers,
|
page_action=page_action,
|
||||||
useragent,
|
hide_canvas=hide_canvas,
|
||||||
cdp_url,
|
init_script=init_script,
|
||||||
timeout,
|
network_idle=network_idle,
|
||||||
disable_resources,
|
google_search=google_search,
|
||||||
wait_selector,
|
extra_headers=extra_headers,
|
||||||
init_script,
|
wait_selector=wait_selector,
|
||||||
cookies,
|
disable_webgl=disable_webgl,
|
||||||
network_idle,
|
selector_config=selector_config,
|
||||||
wait_selector_state,
|
disable_resources=disable_resources,
|
||||||
selector_config,
|
wait_selector_state=wait_selector_state,
|
||||||
)
|
)
|
||||||
super().__init__(max_pages=self.max_pages)
|
super().__init__(max_pages=self.max_pages)
|
||||||
|
|
||||||
@@ -378,28 +378,28 @@ class AsyncDynamicSession(DynamicSessionMixin, AsyncSession):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.__validate__(
|
self.__validate__(
|
||||||
max_pages,
|
wait=wait,
|
||||||
headless,
|
proxy=proxy,
|
||||||
google_search,
|
locale=locale,
|
||||||
hide_canvas,
|
timeout=timeout,
|
||||||
disable_webgl,
|
stealth=stealth,
|
||||||
real_chrome,
|
cdp_url=cdp_url,
|
||||||
stealth,
|
cookies=cookies,
|
||||||
wait,
|
headless=headless,
|
||||||
page_action,
|
useragent=useragent,
|
||||||
proxy,
|
max_pages=max_pages,
|
||||||
locale,
|
real_chrome=real_chrome,
|
||||||
extra_headers,
|
page_action=page_action,
|
||||||
useragent,
|
hide_canvas=hide_canvas,
|
||||||
cdp_url,
|
init_script=init_script,
|
||||||
timeout,
|
network_idle=network_idle,
|
||||||
disable_resources,
|
google_search=google_search,
|
||||||
wait_selector,
|
extra_headers=extra_headers,
|
||||||
init_script,
|
wait_selector=wait_selector,
|
||||||
cookies,
|
disable_webgl=disable_webgl,
|
||||||
network_idle,
|
selector_config=selector_config,
|
||||||
wait_selector_state,
|
disable_resources=disable_resources,
|
||||||
selector_config,
|
wait_selector_state=wait_selector_state,
|
||||||
)
|
)
|
||||||
super().__init__(max_pages=self.max_pages)
|
super().__init__(max_pages=self.max_pages)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user