Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Two Dev committed Dec 30, 2024
1 parent 80e7e71 commit 4e196e6
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 39 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build Documentation
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
python-version: ['3.9']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- name: Publish Documentation
run: |
echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
mkdocs gh-deploy --force
2 changes: 1 addition & 1 deletion tls_requests/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__url__ = "https://github.com/thewebscraping/tls-requests"
__author__ = "Tu Pham"
__author_email__ = "thetwofarm@gmail.com"
__version__ = "1.0.9"
__version__ = "1.1.0"
__license__ = "MIT"
15 changes: 4 additions & 11 deletions tls_requests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,7 @@ def send(
request = request_

self.follow_redirects = follow_redirects
response = self._send(
request,
start=time.perf_counter(),
history=[]
)
response = self._send(request, start=time.perf_counter(), history=[])

if self.hooks.get("response"):
response_ = self.build_hook_response(response)
Expand Down Expand Up @@ -980,11 +976,7 @@ async def send(
request = request_

self.follow_redirects = follow_redirects
response = await self._send(
request,
start=time.perf_counter(),
history=[]
)
response = await self._send(request, start=time.perf_counter(), history=[])

if self.hooks.get("response"):
response_ = self.build_hook_response(response)
Expand All @@ -1002,7 +994,8 @@ async def _send(
start = start or time.perf_counter()
config = self.prepare_config(request)
response = Response.from_tls_response(
await self.session.arequest(config.to_dict()), is_byte_response=config.isByteResponse,
await self.session.arequest(config.to_dict()),
is_byte_response=config.isByteResponse,
)
response.request = request
response.default_encoding = self.encoding
Expand Down
154 changes: 127 additions & 27 deletions tls_requests/models/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,43 +132,135 @@ class TLSLibrary:
"""

_PATH: str = None
_STATIC_API_DATA = {
"name": "v1.7.10",
"tag_name": "v1.7.10",
"assets": [
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-darwin-amd64-1.7.10.dylib",
"name": "tls-client-darwin-amd64-1.7.10.dylib",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-darwin-arm64-1.7.10.dylib",
"name": "tls-client-darwin-arm64-1.7.10.dylib",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-linux-arm64-1.7.10.so",
"name": "tls-client-linux-arm64-1.7.10.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-linux-armv7-1.7.10.so",
"name": "tls-client-linux-armv7-1.7.10.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-linux-ubuntu-amd64-1.7.10.so",
"name": "tls-client-linux-ubuntu-amd64-1.7.10.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-windows-32-1.7.10.dll",
"name": "tls-client-windows-32-1.7.10.dll",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-windows-64-1.7.10.dll",
"name": "tls-client-windows-64-1.7.10.dll",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-darwin-amd64.dylib",
"name": "tls-client-xgo-1.7.10-darwin-amd64.dylib",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-darwin-arm64.dylib",
"name": "tls-client-xgo-1.7.10-darwin-arm64.dylib",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-386.so",
"name": "tls-client-xgo-1.7.10-linux-386.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-amd64.so",
"name": "tls-client-xgo-1.7.10-linux-amd64.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-arm-5.so",
"name": "tls-client-xgo-1.7.10-linux-arm-5.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-arm-6.so",
"name": "tls-client-xgo-1.7.10-linux-arm-6.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-arm-7.so",
"name": "tls-client-xgo-1.7.10-linux-arm-7.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-arm64.so",
"name": "tls-client-xgo-1.7.10-linux-arm64.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-ppc64le.so",
"name": "tls-client-xgo-1.7.10-linux-ppc64le.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-riscv64.so",
"name": "tls-client-xgo-1.7.10-linux-riscv64.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-linux-s390x.so",
"name": "tls-client-xgo-1.7.10-linux-s390x.so",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-windows-386.dll",
"name": "tls-client-xgo-1.7.10-windows-386.dll",
},
{
"browser_download_url": "https://github.com/bogdanfinn/tls-client/releases/download/v1.7.10/tls-client-xgo-1.7.10-windows-amd64.dll",
"name": "tls-client-xgo-1.7.10-windows-amd64.dll",
},
],
}

@classmethod
def fetch_api(cls, version: str = None, retries: int = 3):
def _find_release(data, version_: str = None):
releases = [
Release.from_kwargs(**kwargs) for kwargs in data
]

if version_ is not None:
version_ = (
"v%s" % version_
if not str(version_).startswith("v")
else str(version_)
)
releases = [
release
for release in releases
if re.search(version_, release.name, re.I)
]

for release in releases:
for asset in release.assets:
if IS_UBUNTU and PATTERN_UBUNTU_RE.search(
asset.browser_download_url
):
ubuntu_urls.append(asset.browser_download_url)
if PATTERN_RE.search(asset.browser_download_url):
asset_urls.append(asset.browser_download_url)

asset_urls, ubuntu_urls = [], []
for _ in range(retries):
try:
response = requests.get(GITHUB_API_URL)
if response.ok:
response_json = response.json()
releases = [
Release.from_kwargs(**kwargs) for kwargs in response_json
]

if version is not None:
version = (
"v%s" % version
if not str(version).startswith("v")
else str(version)
)
releases = [
release
for release in releases
if re.search(version, release.name, re.I)
]

for release in releases:
for asset in release.assets:
if IS_UBUNTU and PATTERN_UBUNTU_RE.search(
asset.browser_download_url
):
ubuntu_urls.append(asset.browser_download_url)
if PATTERN_RE.search(asset.browser_download_url):
asset_urls.append(asset.browser_download_url)
_find_release(response.json())
break

except Exception as ex:
print("Unable to fetch GitHub API: %s" % ex)

if not asset_urls and not ubuntu_urls:
_find_release([cls._STATIC_API_DATA])

for url in ubuntu_urls:
yield url

Expand All @@ -183,14 +275,22 @@ def find(cls) -> str:

@classmethod
def find_all(cls) -> list[str]:
return [src for src in glob.glob(os.path.join(BIN_DIR, r"*")) if src.lower().endswith(('so', 'dll', 'dylib'))]
return [
src
for src in glob.glob(os.path.join(BIN_DIR, r"*"))
if src.lower().endswith(("so", "dll", "dylib"))
]

@classmethod
def download(cls, version: str = None) -> str:
try:
print(
"System Info - Platform: %s, Machine: %s, File Ext : %s."
% (PLATFORM, "%s (Ubuntu)" % MACHINE if IS_UBUNTU else MACHINE, FILE_EXT)
% (
PLATFORM,
"%s (Ubuntu)" % MACHINE if IS_UBUNTU else MACHINE,
FILE_EXT,
)
)
download_url = None
for download_url in cls.fetch_api(version):
Expand Down

0 comments on commit 4e196e6

Please sign in to comment.