Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
ecc414558a | |||
3b16f60ab0 | |||
06e12a8467 | |||
7a3bcc05b3 | |||
8b34f6d475 | |||
35554771d4 | |||
b238952198 | |||
d19dfe741f |
|
@ -1,5 +1,5 @@
|
||||||
"""# Common HTTP/REST clients interface
|
"""# Common HTTP/REST clients interface"""
|
||||||
"""
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
|
@ -11,6 +11,10 @@ import bs4
|
||||||
import lxml.html
|
import lxml.html
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from ._version import __version__
|
||||||
|
|
||||||
|
__all__ = ['__version__']
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +45,9 @@ class AbstractClient(abc.ABC):
|
||||||
def fetch(self, url: str, **kwargs) -> requests.Response:
|
def fetch(self, url: str, **kwargs) -> requests.Response:
|
||||||
r = self._fetch(url, **kwargs)
|
r = self._fetch(url, **kwargs)
|
||||||
if r.status_code in {301, 302, 303}:
|
if r.status_code in {301, 302, 303}:
|
||||||
msg = f'Redirection: {r.request.method} {url} -> GET {r.headers["Location"]}'
|
msg = (
|
||||||
|
f'Redirection: {r.request.method} {url} -> GET {r.headers["Location"]}'
|
||||||
|
)
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r
|
return r
|
||||||
|
@ -51,7 +57,9 @@ class AbstractClient(abc.ABC):
|
||||||
kwargs.setdefault('allow_redirects', True)
|
kwargs.setdefault('allow_redirects', True)
|
||||||
|
|
||||||
url_parsed = urllib.parse.urlparse(url)
|
url_parsed = urllib.parse.urlparse(url)
|
||||||
origin_url = url_parsed._replace(path='',params='',query='',fragment='').geturl()
|
origin_url = url_parsed._replace(
|
||||||
|
path='', params='', query='', fragment=''
|
||||||
|
).geturl()
|
||||||
|
|
||||||
kwargs.setdefault('headers', {}).setdefault('Origin', origin_url)
|
kwargs.setdefault('headers', {}).setdefault('Origin', origin_url)
|
||||||
kwargs.setdefault('headers', {}).setdefault('Alt-Used', url_parsed.hostname)
|
kwargs.setdefault('headers', {}).setdefault('Alt-Used', url_parsed.hostname)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__ = '0.1.3'
|
__version__ = '0.1.6'
|
||||||
|
|
|
@ -15,6 +15,7 @@ DEFAULT_MAX_RESULTS = 1
|
||||||
|
|
||||||
URL = str
|
URL = str
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True, order=True, slots=True)
|
@dataclasses.dataclass(frozen=True, order=True, slots=True)
|
||||||
class SellerInfo:
|
class SellerInfo:
|
||||||
name: str
|
name: str
|
||||||
|
@ -39,6 +40,7 @@ class StoreOfferProperty(enum.Enum):
|
||||||
AUCTION = enum.auto()
|
AUCTION = enum.auto()
|
||||||
SOLD_OUT = enum.auto()
|
SOLD_OUT = enum.auto()
|
||||||
DISCOUNT = enum.auto()
|
DISCOUNT = enum.auto()
|
||||||
|
PRE_ORDER = enum.auto()
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True, order=True, slots=True)
|
@dataclasses.dataclass(frozen=True, order=True, slots=True)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import dataclasses
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class WishlistItem:
|
class WishlistItem:
|
||||||
"""A single wishlished product."""
|
"""A single wishlished product."""
|
||||||
|
@ -19,7 +20,6 @@ class WishlistItem:
|
||||||
|
|
||||||
|
|
||||||
class WishlistClient(abc.ABC):
|
class WishlistClient(abc.ABC):
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_wishlist(self) -> Sequence[WishlistItem]:
|
def get_wishlist(self) -> Sequence[WishlistItem]:
|
||||||
pass
|
pass
|
||||||
|
|
10
setup.py
10
setup.py
|
@ -10,8 +10,7 @@ from setuptools import setup
|
||||||
PACKAGE_NAME = 'clients_protocol'
|
PACKAGE_NAME = 'clients_protocol'
|
||||||
|
|
||||||
PACKAGE_DESCRIPTION = """
|
PACKAGE_DESCRIPTION = """
|
||||||
# Common HTTP/REST clients interface
|
# Common HTTP/REST clients interface""".strip()
|
||||||
""".strip()
|
|
||||||
|
|
||||||
PACKAGE_DESCRIPTION_SHORT = """
|
PACKAGE_DESCRIPTION_SHORT = """
|
||||||
""".strip()
|
""".strip()
|
||||||
|
@ -27,11 +26,9 @@ def parse_version_file(text: str) -> str:
|
||||||
|
|
||||||
|
|
||||||
def find_python_packages() -> list[str]:
|
def find_python_packages() -> list[str]:
|
||||||
"""
|
"""Find all python packages (directories containing __init__.py files)."""
|
||||||
Find all python packages. (Directories containing __init__.py files.)
|
|
||||||
"""
|
|
||||||
root_path = Path(PACKAGE_NAME)
|
root_path = Path(PACKAGE_NAME)
|
||||||
packages: set[str] = set([PACKAGE_NAME])
|
packages: set[str] = {PACKAGE_NAME}
|
||||||
|
|
||||||
# Search recursively
|
# Search recursively
|
||||||
for init_file in root_path.rglob('__init__.py'):
|
for init_file in root_path.rglob('__init__.py'):
|
||||||
|
@ -39,6 +36,7 @@ def find_python_packages() -> list[str]:
|
||||||
|
|
||||||
return sorted(packages)
|
return sorted(packages)
|
||||||
|
|
||||||
|
|
||||||
with open(PACKAGE_NAME + '/_version.py') as f:
|
with open(PACKAGE_NAME + '/_version.py') as f:
|
||||||
version = parse_version_file(f.read())
|
version = parse_version_file(f.read())
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
def test_init():
|
def test_init():
|
||||||
import clients_protocol
|
import clients_protocol
|
||||||
import clients_protocol.autoload
|
import clients_protocol.autoload
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user