Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ jobs:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
uses: abatilo/actions-poetry@v2.0.0
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.3.2
poetry-version: 1.5.0
- name: Install dependencies
run: poetry install -E crypto
- name: Generate rest sync code and tests
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Setup poetry
uses: abatilo/actions-poetry@v2.0.0
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.3.2
poetry-version: 1.5.0
- name: Install dependencies
run: poetry install -E crypto
- name: Lint with flake8
Expand Down
34 changes: 20 additions & 14 deletions ably/http/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
from urllib.parse import urljoin

import httpx
import niquests
import msgpack

from ably.rest.auth import Auth
Expand Down Expand Up @@ -86,10 +86,10 @@ def version(self):

class Response:
"""
Composition for httpx.Response with delegation
Composition for niquests.Response with delegation
"""

def __init__(self, response):
def __init__(self, response: niquests.Response):
self.__response = response

def to_native(self):
Expand Down Expand Up @@ -129,10 +129,10 @@ def __init__(self, ably, options):
# Cached fallback host (RSC15f)
self.__host = None
self.__host_expires = None
self.__client = httpx.AsyncClient(http2=True)
self.__client = niquests.AsyncSession()

async def close(self):
await self.__client.aclose()
await self.__client.close()

def dump_body(self, body):
if self.options.use_binary_protocol:
Expand Down Expand Up @@ -196,18 +196,24 @@ def should_stop_retrying():
base_url = "%s://%s:%d" % (self.preferred_scheme,
host,
self.preferred_port)

# remove redundant port in base_url
if self.preferred_scheme == "https" and self.preferred_port == 443:
base_url = base_url.replace(":443", "")
elif self.preferred_scheme == "http" and self.preferred_port == 80:
base_url = base_url.replace(":80", "")

url = urljoin(base_url, path)

request = self.__client.build_request(
method=method,
url=url,
content=body,
params=params,
headers=all_headers,
timeout=timeout,
)
try:
response = await self.__client.send(request)
response = await self.__client.request(
method=method,
url=url,
data=body,
params=params,
headers=all_headers,
timeout=timeout,
)
except Exception as e:
if should_stop_retrying():
raise e
Expand Down
6 changes: 3 additions & 3 deletions ably/realtime/connectionmanager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
import logging
import asyncio
import httpx
import niquests
from ably.transport.websockettransport import WebSocketTransport, ProtocolMessageAction
from ably.transport.defaults import Defaults
from ably.types.connectionerrors import ConnectionErrors
Expand Down Expand Up @@ -52,10 +52,10 @@ def enact_state_change(self, state: ConnectionState, reason: Optional[AblyExcept

def check_connection(self) -> bool:
try:
response = httpx.get(self.options.connectivity_check_url)
response = niquests.get(self.options.connectivity_check_url)
return 200 <= response.status_code < 300 and \
(self.options.connectivity_check_url != Defaults.connectivity_check_url or "yes" in response.text)
except httpx.HTTPError:
except niquests.HTTPError:
return False

def get_state_error(self) -> AblyException:
Expand Down
4 changes: 2 additions & 2 deletions ably/rest/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from typing import Optional, TYPE_CHECKING, Union
import uuid
import httpx
import niquests

from ably.types.options import Options
if TYPE_CHECKING:
Expand Down Expand Up @@ -400,7 +400,7 @@ async def token_request_from_auth_url(self, method: str, url: str, token_params,
body = dict(auth_params, **token_params)

from ably.http.http import Response
async with httpx.AsyncClient(http2=True) as client:
async with niquests.AsyncSession() as client:
resp = await client.request(method=method, url=url, headers=headers, params=params, data=body)
response = Response(resp)

Expand Down
6 changes: 3 additions & 3 deletions ably/scripts/unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def find_files(dir_path, file_name_regex):
def run():
# Source files ==========================================

_TOKEN_REPLACE["AsyncClient"] = "Client"
_TOKEN_REPLACE["aclose"] = "close"
_TOKEN_REPLACE["AsyncSession"] = "Session"
_TOKEN_REPLACE["close"] = "close"

_IMPORTS_REPLACE["ably"] = "ably.sync"

Expand Down Expand Up @@ -271,7 +271,7 @@ def run():
_STRING_REPLACE['ably.rest.auth.Auth.request_token'] = 'ably.sync.rest.auth.AuthSync.request_token'
_STRING_REPLACE['ably.rest.auth.TokenRequest'] = 'ably.sync.rest.auth.TokenRequest'
_STRING_REPLACE['ably.rest.rest.Http.post'] = 'ably.sync.rest.rest.HttpSync.post'
_STRING_REPLACE['httpx.AsyncClient.send'] = 'httpx.Client.send'
_STRING_REPLACE['niquests.AsyncSession.send'] = 'niquests.Session.send'
_STRING_REPLACE['ably.util.exceptions.AblyException.raise_for_response'] = \
'ably.sync.util.exceptions.AblyException.raise_for_response'
_STRING_REPLACE['ably.rest.rest.AblyRest.time'] = 'ably.sync.rest.rest.AblyRestSync.time'
Expand Down
2 changes: 1 addition & 1 deletion ably/util/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_default_params(params=None):
if not key:
raise ValueError("Crypto.get_default_params: a key is required")

if type(key) == str:
if isinstance(key, str):
key = base64.b64decode(key)

cipher_params = CipherParams(algorithm=algorithm, secret_key=key, iv=iv, mode=mode)
Expand Down
Loading