fix: correct typo, indent...

This commit is contained in:
Maud LAURENT 2021-05-07 16:23:13 +02:00
parent 23fd48c281
commit c1a7bebc78
7 changed files with 26 additions and 36 deletions

View file

@ -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 <Your_bearer_token>``
- For Basic token set : ``Basic <Your_base64_encoded_token>``
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 <Your_bearer_token>``
- For Basic token set : ``Basic <<Your_base64_encoded_token>>``
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 <Your_bearer_token>``
- For Basic token set : ``Basic <<Your_base64_encoded_token>>``
To set an authorization token, you can set:

View file

@ -1,5 +1,5 @@
# MIT licensed
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
# Copyright (c) 2020 Ypsilik <tt2laurent.maud@gmail.com>, 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'))

View file

@ -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

View file

@ -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,

View file

@ -1,5 +1,5 @@
# MIT licensed
# Copyright (c) 2021 lilydjwg <lilydjwg@gmail.com>, et al.
# Copyright (c) 2021 ypsilik <tt2laurent.maud@gmail.com>, 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
}) is None

View file

@ -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

View file

@ -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"