From: Oleg Broytman Date: Thu, 6 Mar 2025 17:18:21 +0000 (+0300) Subject: Feat(Robots): Robot based on `httpx.AsyncClinet()` X-Git-Tag: 6.4.0~3 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=2793973309d9011bd37ee49f8489521191c8d3ea;p=bookmarks_db.git Feat(Robots): Robot based on `httpx.AsyncClinet()` --- diff --git a/Robots/bkmk_rasynchttpx.py b/Robots/bkmk_rasynchttpx.py new file mode 100644 index 0000000..19e5dec --- /dev/null +++ b/Robots/bkmk_rasynchttpx.py @@ -0,0 +1,52 @@ +"""Robot based on httpx.AsyncCLient() + +This file is a part of Bookmarks database and Internet robot. + +""" + +__author__ = "Oleg Broytman " +__copyright__ = "Copyright (C) 2025 PhiloSoft Design" +__license__ = "GNU GPL" + +__all__ = ['robot_asynchttpx'] + + +import httpx +import socksio + +from Robots.aio_base import aio_base +from Robots.util import get_ftp + + +class robot_asynchttpx(aio_base): + def version_str(self): + return 'python-httpx/%s' % httpx.__version__ + + async def get(self, url, req_headers, use_proxy=False): + if url.startswith('ftp://'): + error, welcome, body = get_ftp(url, self.timeout) + if error is not None: + return error, None, None, None + self.welcome = welcome + return None, None, None, body + + if use_proxy: + proxy = self.proxy + else: + proxy = None + + try: + async with httpx.AsyncClient(proxy=proxy, verify=False) as c: + r = await c.get(url, headers=req_headers, + timeout=httpx.Timeout(self.timeout), + follow_redirects=False) + except (httpx.RequestError, socksio.ProtocolError) as e: + error = str(e) + return error, None, None, None + + return None, r.status_code, r.headers, r.content + + def get_ftp_welcome(self): + welcome = self.welcome + self.welcome = '' + return welcome diff --git a/doc/ANNOUNCE b/doc/ANNOUNCE index 612401b..7a73700 100644 --- a/doc/ANNOUNCE +++ b/doc/ANNOUNCE @@ -11,6 +11,8 @@ Version 6.4.0 (2025-??-??) Robots based on curl-cffi. + Robot based on httpx.AsyncClinet(). + Version 6.3.0 (2025-03-02) Robots based on pycurl. diff --git a/doc/ChangeLog b/doc/ChangeLog index 176f6f0..49d820f 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -2,6 +2,8 @@ Version 6.4.0 (2025-??-??) Robots based on curl-cffi. + Robot based on httpx.AsyncClinet(). + Version 6.3.0 (2025-03-02) Robots based on pycurl. diff --git a/doc/TODO b/doc/TODO index 5e9a6d8..bdc0675 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,5 +1,3 @@ -Async httpx. - Async curl-cffi. Twisted. diff --git a/robots.py b/robots.py index ea293c6..6f2c5a2 100644 --- a/robots.py +++ b/robots.py @@ -16,7 +16,7 @@ from bkmk_objects import parse_params, set_params robot_names, robot_params = parse_params( environ.get("BKMK_ROBOT", - "multicurlcffi,multirequests,multihttpx,curlcffi,aio")) + "multicurlcffi,multirequests,multihttpx,aio")) def import_robot(robot_name):