diff --git a/docs/usage.rst b/docs/usage.rst index 4a94ff4..eaf0180 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -234,10 +234,10 @@ regex When multiple version strings are found, the maximum of those is chosen. token - (*Optional*) A personal authorization token used to call the url. The token type depends the authorization required. + (*Optional*) A personal authorization token used to call the url. The type of token depends on the authorization required. - - For Bearer token set : ``Bearer Your_bearer_token`` - - For Basic token set : ``Basic Your_base64_encoded_token`` + - For Bearer token set : ``Bearer `` + - For Basic token set : ``Basic `` To set an authorization token, you can set: @@ -274,10 +274,10 @@ follow_redirects (*Optional*) Whether to follow 3xx HTTP redirects. Default is ``false``. If you are looking at a ``Location`` header, you shouldn't change this. token - (*Optional*) A personal authorization token used to call the url. The token type depends the authorization required. + (*Optional*) A personal authorization token used to call the url. The type of token depends on the authorization required. - - For Bearer token set : ``Bearer Your_bearer_token`` - - For Basic token set : ``Basic Your_base64_encoded_token`` + - For Bearer token set : ``Bearer `` + - For Basic token set : ``Basic <>`` To set an authorization token, you can set: @@ -299,10 +299,10 @@ xpath A xpath expression used to find the version string token - (*Optional*) A personal authorization token used to call the url. The token type depends the authorization required. + (*Optional*) A personal authorization token used to call the url. The type of token depends on the authorization required. - - For Bearer token set : ``Bearer Your_bearer_token`` - - For Basic token set : ``Basic Your_base64_encoded_token`` + - For Bearer token set : ``Bearer `` + - For Basic token set : ``Basic <>`` To set an authorization token, you can set: diff --git a/nvchecker_source/htmlparser.py b/nvchecker_source/htmlparser.py index 526646c..b64dc75 100644 --- a/nvchecker_source/htmlparser.py +++ b/nvchecker_source/htmlparser.py @@ -1,5 +1,5 @@ # MIT licensed -# Copyright (c) 2013-2020 lilydjwg , et al. +# Copyright (c) 2020 Ypsilik , et al. from lxml import html, etree @@ -9,18 +9,15 @@ from nvchecker.api import ( ) async def get_version(name, conf, **kwargs): - try: - return await get_version_real(name, conf, **kwargs) - except TemporaryError as e: - check_ratelimit(e, name) + return await get_version_real(name, conf, **kwargs) async def get_version_real( name: str, conf: Entry, *, keymanager: KeyManager, **kwargs, ) -> VersionResult: - encoding = conf.get('encoding', 'latin1') - + encoding = conf.get('encoding', 'latin1') + # Load token from config token = conf.get('token') # Load token from keyman @@ -33,7 +30,7 @@ async def get_version_real( if token: headers["Authorization"] = token - data = await session.get(conf.get('url'), headers = headers) + data = await session.get(conf.get('url'), headers=headers) body = html.fromstring(data.body.decode(encoding)) try: checkxpath = body.xpath(conf.get('xpath')) diff --git a/nvchecker_source/httpheader.py b/nvchecker_source/httpheader.py index 2d70ffa..761d00c 100644 --- a/nvchecker_source/httpheader.py +++ b/nvchecker_source/httpheader.py @@ -5,7 +5,7 @@ import re import sre_constants from nvchecker.api import ( VersionResult, Entry, KeyManager, - TemporaryError,session, GetVersionError + TemporaryError, session, GetVersionError ) async def get_version(name, conf, **kwargs): @@ -52,4 +52,4 @@ async def get_version_real( version = regex.findall(header_value) except ValueError: raise GetVersionError('version string not found.') - return version + return version \ No newline at end of file diff --git a/nvchecker_source/regex.py b/nvchecker_source/regex.py index 64c29d3..1f530a5 100644 --- a/nvchecker_source/regex.py +++ b/nvchecker_source/regex.py @@ -8,13 +8,8 @@ from nvchecker.api import ( TemporaryError, session, GetVersionError ) - async def get_version(name, conf, **kwargs): - try: - return await get_version_real(name, conf, **kwargs) - except TemporaryError as e: - check_ratelimit(e, name) - + return await get_version_real(name, conf, **kwargs) async def get_version_real( name: str, conf: Entry, *, keymanager: KeyManager, diff --git a/tests/test_htmlpasrer.py b/tests/test_htmlpasrer.py index 76d0e8d..dcbabae 100644 --- a/tests/test_htmlpasrer.py +++ b/tests/test_htmlpasrer.py @@ -1,5 +1,5 @@ # MIT licensed -# Copyright (c) 2021 lilydjwg , et al. +# Copyright (c) 2021 ypsilik , et al. import pytest @@ -11,12 +11,11 @@ async def test_xpath_ok(get_version): "url": "http://httpbin.org/", "xpath": '//pre[@class="version"]/text()', }) != None - + async def test_xpath_missing_ok(get_version): assert await get_version("unifiedremote", { "source": "htmlparser", "url": "http://httpbin.org/", "xpath": '//pre[@class="test-is-ok"]/text()', "missing_ok": True, - }) is None - \ No newline at end of file + }) is None \ No newline at end of file diff --git a/tests/test_httpheader.py b/tests/test_httpheader.py index 4c38dd7..c5e20e4 100644 --- a/tests/test_httpheader.py +++ b/tests/test_httpheader.py @@ -3,7 +3,7 @@ import pytest import pytest_httpbin -assert pytest_httpbin # for pyflakes +assert pytest_httpbin # for pyflakes pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] async def test_redirection(get_version): @@ -20,4 +20,4 @@ async def test_get_version_withtoken(get_version, httpbin): "token": "Basic dXNlcm5hbWU6c3VwZXJwYXNzd29yZA==", "header": "server", "regex": r'([0-9.]+)*', - }) != None + }) != None \ No newline at end of file diff --git a/tests/test_regex.py b/tests/test_regex.py index 2ef5c63..4b29a04 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -5,7 +5,7 @@ import base64 import pytest import pytest_httpbin -assert pytest_httpbin # for pyflakes +assert pytest_httpbin # for pyflakes pytestmark = pytest.mark.asyncio @@ -42,7 +42,7 @@ async def test_missing_ok(get_version, httpbin): "regex": "foobar", "missing_ok": True, }) is None - + async def test_regex_with_tokenBasic(get_version, httpbin): assert await get_version("example", { "source": "regex", @@ -50,12 +50,11 @@ async def test_regex_with_tokenBasic(get_version, httpbin): "token": "Basic dXNlcm5hbWU6c3VwZXJwYXNzd29yZA==", "regex": r'"user":"([a-w]+)"', }) == "username" - + async def test_regex_with_tokenBearer(get_version, httpbin): assert await get_version("example", { "source": "regex", "url": httpbin.url + "/bearer", "token": "Bearer username:password", "regex": r'"token":"([a-w]+):.*"', - }) == "username" - + }) == "username" \ No newline at end of file