]> git.phdru.name Git - bookmarks_db.git/commitdiff
Feat(Robots): Removed connect_timeout, added ftp_timeout
authorOleg Broytman <phd@phdru.name>
Fri, 16 Aug 2024 12:46:50 +0000 (15:46 +0300)
committerOleg Broytman <phd@phdru.name>
Fri, 16 Aug 2024 16:13:25 +0000 (19:13 +0300)
Robots/bkmk_raiohttp.py
Robots/bkmk_rcurl.py
Robots/bkmk_robot_base.py
doc/ANNOUNCE
doc/ChangeLog

index df47aa40bb1adcafe7f27e9503a94bdc03854931..422db04d567ae8e8f541c562b72a7616120f4d6e 100644 (file)
@@ -28,8 +28,7 @@ class robot_aiohttp(robot_base):
     def get(self, bookmark, url, accept_charset=False, use_proxy=False):
         if url.startswith('ftp://'):
             error, body = asyncio.run(_get_ftp(
-                url, connect_timeout=self.connect_timeout,
-                timeout=self.timeout,
+                url, timeout=self.ftp_timeout,
             ))
             if error is not None:
                 error = str(error)
@@ -49,7 +48,7 @@ class robot_aiohttp(robot_base):
 
         error, status, resp_headers, body = asyncio.run(get_http(
             url, headers=headers, proxy=proxy,
-            connect_timeout=self.connect_timeout, timeout=self.timeout,
+            timeout=self.timeout,
         ))
         if error is not None or (status and status >= 400):
             if error is None:
@@ -67,8 +66,8 @@ class robot_aiohttp(robot_base):
         return ''  # We don't store welcome message yet
 
 
-async def get_http(url, headers={}, proxy=None, connect_timeout=30, timeout=60):
-    timeout = aiohttp.ClientTimeout(connect=connect_timeout, total=timeout)
+async def get_http(url, headers={}, proxy=None, timeout=60):
+    timeout = aiohttp.ClientTimeout(connect=timeout, total=timeout)
     try:
         async with aiohttp.ClientSession(timeout=timeout) as session:
             async with session.get(
@@ -79,7 +78,7 @@ async def get_http(url, headers={}, proxy=None, connect_timeout=30, timeout=60):
         return e, None, None, None
 
 
-async def _get_ftp(url, connect_timeout=30, timeout=60):
+async def _get_ftp(url, timeout=60):
     split_results = urlsplit(url)
     path = split_results.path or '/'
     user = split_results.username or 'anonymous'
@@ -91,7 +90,7 @@ async def _get_ftp(url, connect_timeout=30, timeout=60):
     try:
         async with aioftp.Client.context(
             host, port, user=user, password=password,
-            socket_timeout=connect_timeout, path_timeout=timeout,
+            socket_timeout=timeout, path_timeout=timeout,
         ) as client:
             async for _path, _info in client.list(path):
                 lines.append('%s %s' % (_info, _path))
index bf32970844a599bf02128e371281d468aa75e582..a9941767929c65e2fa2a3f7d142a06dfeefffe63 100644 (file)
@@ -42,8 +42,12 @@ class robot_curl(robot_base):
         curl.setopt(pycurl.SSL_VERIFYHOST, 2)
         curl.setopt(curl.CAINFO, certifi.where())
         # Set timeouts to avoid hanging too long
-        curl.setopt(pycurl.CONNECTTIMEOUT, self.connect_timeout)
-        curl.setopt(pycurl.TIMEOUT, self.timeout)
+        if url.startswith('ftp://'):
+            timeout = self.ftp_timeout
+        else:
+            timeout = self.timeout
+        curl.setopt(pycurl.CONNECTTIMEOUT, timeout)
+        curl.setopt(pycurl.TIMEOUT, timeout)
         # Parse Last-Modified
         curl.setopt(pycurl.OPT_FILETIME, 1)
 
index a8a15d513d600a87208d1020cc098f063bdb0f14..ddece9005ba8b2cb7b1de1a2282231683b01945d 100644 (file)
@@ -74,11 +74,11 @@ class robot_base(Robot):
     # ...but aren't accessible even through proxy
     proxy_error = set()
 
-    connect_timeout = 30
     timeout = 60
+    ftp_timeout = 60
 
     def __init__(self, *args, **kw):
-        for attr in 'connect_timeout', 'timeout':
+        for attr in 'timeout', 'ftp_timeout':
             value = getattr(self, attr)
             if not isinstance(value, int):
                 value = int(value)
index 3b7d9a38a1ee23b1e70d1284753c0db496ff74a1..e97f411f818bbf172b10f3a5ee0117735ecfb686 100644 (file)
@@ -11,6 +11,8 @@ Version 5.7.0 (2024-??-??)
 
    Robot bkmk_rrequests: Use ftplib directly, without requests_ftp.
 
+   Robots: Removed connect_timeout, added ftp_timeout.
+
 Version 5.6.1 (2024-08-15)
 
    Minor fixes.
index f213e72e741a5de179fb7850a63f6e40526f807f..4bb123a1fb65804f037f4734d11b616d0580dea3 100644 (file)
@@ -2,6 +2,8 @@ Version 5.7.0 (2024-??-??)
 
    Robot bkmk_rrequests: Use ftplib directly, without requests_ftp.
 
+   Robots: Removed connect_timeout, added ftp_timeout.
+
 Version 5.6.1 (2024-08-15)
 
    Minor fixes.