Split check_bookmark() into sync and async variants.
from base64 import b64encode
from urllib.parse import urlsplit, urljoin
+import asyncio
import sys
import socket
import time
return self.__class__.__name__
def check_bookmark(self, bookmark):
+ return asyncio.run(self.check_bookmark_async(bookmark))
+
+ async def check_bookmark_async(self, bookmark):
try:
self.start = int(time.time())
bookmark.icon = None
error, http_status_code, redirect_to, headers, content = \
- self.get_url(bookmark, bookmark.href, True)
+ await self.get_url(bookmark, bookmark.href, True)
if error is not None:
bookmark.error = error
icon_error, \
icon_status_code, icon_redirect_to, \
icon_headers, icon_data = \
- self.get_url(bookmark, _icon_url)
+ await self.get_url(bookmark, _icon_url)
if icon_error:
raise IOError("No icon: " + icon_error)
break
finally:
self.finish_check_url(bookmark)
- def get_url(self, bookmark, url, accept_charset=False):
+ async def get_url(self, bookmark, url, accept_charset=False):
split_results = urlsplit(url)
url_proto = split_results.scheme
url_host = split_results.hostname
if use_proxy and url_host in self.proxy_ok:
self.log(' Immediately trying with the proxy')
error, http_status_code, redirect_to, headers, content = \
- self.get(bookmark, url,
- accept_charset=accept_charset,
- use_proxy=True)
+ await self.get(bookmark, url,
+ accept_charset=accept_charset,
+ use_proxy=True)
else:
error, http_status_code, redirect_to, headers, content = \
- self.get(bookmark, url,
- accept_charset=accept_charset)
+ await self.get(bookmark, url,
+ accept_charset=accept_charset)
if error is not None and (
not url_host.startswith('localhost') and
not url_host.startswith('127.')
if use_proxy and http_status_code != 404:
self.log(' Retrying with the proxy...')
error, http_status_code, redirect_to, headers, content = \
- self.get(bookmark, url,
- accept_charset=accept_charset,
- use_proxy=True)
+ await self.get(bookmark, url,
+ accept_charset=accept_charset,
+ use_proxy=True)
if error is None:
self.proxy_ok.add(url_host)
if (error is not None) or (
def version_str(self):
return 'aiohttp/%s' % aiohttp.__version__
- def get(self, bookmark, url, accept_charset=False, use_proxy=False):
+ async def get(self, bookmark, url, accept_charset=False, use_proxy=False):
if url.startswith('ftp://'):
- error, body = asyncio.run(_get_ftp(
+ error, body = await _get_ftp(
url, timeout=self.ftp_timeout,
- ))
+ )
if error is not None:
error = str(error)
return error, None, None, None, None
else:
proxy = None
- error, status, resp_headers, body = asyncio.run(_get_http(
+ error, status, resp_headers, body = await _get_http(
url, headers=headers, proxy=proxy,
timeout=self.timeout,
- ))
+ )
if error is not None or (status and status >= 400):
if error is None:
error = 'Error %d' % status
def version_str(self):
return str(pycurl.version)
- def get(self, bookmark, url, accept_charset=False, use_proxy=False):
+ async def get(self, bookmark, url, accept_charset=False, use_proxy=False):
if accept_charset and bookmark.charset:
headers = request_headers.copy()
headers['Accept-Charset'] = bookmark.charset
def version_str(self):
return 'python-requests urllib3/%s' % urllib3.__version__
- def get(self, bookmark, url, accept_charset=False, use_proxy=False):
+ async def get(self, bookmark, url, accept_charset=False, use_proxy=False):
if url.startswith('ftp://'):
error, welcome, body = _get_ftp(url, self.timeout)
if error is not None:
Version 6.0.0 (2024-??-??)
+ Make all robots async.
+ Split check_bookmark() into sync and async variants.
+
Renamed max_workers to max_urls.
git clone https://git.phdru.name/bookmarks_db.git
git clone git://git.phdru.name/bookmarks_db.git
- Requires: Python 3.6+, BeautifulSoup 4, lxml, m_lib 2.0+,
+ Requires: Python 3.7+, BeautifulSoup 4, lxml, m_lib 2.0+,
requests and requests-ftp.
Version 6.0.0 (2024-??-??)
+ Make all robots async.
+ Split check_bookmark() into sync and async variants.
+
Renamed max_workers to max_urls.
Version 5.7.0 (2024-08-16)
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
- 'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
- python_requires='>=3.6',
+ python_requires='>=3.7',
install_requires=[
'm_lib.full>=1.0',
],