Skip to content

Restore urllib.parse.parse_qs behavior on new versions of python #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 6, 2021
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
rev: stable
hooks:
- id: black
language_version: python3.7
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ stages:
- script: |
. venv/bin/activate

pip install -r requirements_test.txt
pip install pytest pytest-azurepipelines pytest-cov pytest-xdist
pytest --cov compal --cov-report html -qq -o console_output_style=count -p no:sugar tests
displayName: 'pytest'
Expand Down
14 changes: 11 additions & 3 deletions compal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Client for the Compal CH7465LG/Ziggo Connect box cable modem
"""
import inspect
import io
import itertools
import logging
Expand All @@ -17,13 +18,13 @@
from .models import (
BandSetting,
FilterAction,
GuestNetworkSettings,
InterfaceGuestNetworkSettings,
NatMode,
PortForward,
Proto,
RadioSettings,
TimerMode,
InterfaceGuestNetworkSettings,
GuestNetworkSettings,
)

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -207,7 +208,14 @@ def login(self, key=None):
else:
raise ValueError("Login failed for unknown reason!")

tokens = urllib.parse.parse_qs(res.text)
def parse_response(text):
# As per python 3.9.2 parse_qs does not split on ';' by default
if "separator" in inspect.signature(urllib.parse.parse_qs).parameters:
return urllib.parse.parse_qs(text, separator=";")
else:
return urllib.parse.parse_qs(text)

tokens = parse_response(res.text)

token_sids = tokens.get("SID")
if not token_sids:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ use_parentheses = true
line_length = 88

[settings]
known_third_party = ["lxml", "requests", "setuptools"]
known_third_party = ["lxml", "requests", "responses", "setuptools"]
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
black
isort[pyproject]
responses
28 changes: 28 additions & 0 deletions tests/test_login_response_parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import responses

from compal import Compal


def load_login_responses(ip):
# Response required by constructor
responses.add(
responses.Response(
method="GET",
url=f"http://{ip}/",
status=302,
headers={"Location": "../common_page/login.html"},
)
)
responses.add(responses.GET, f"http://{ip}/common_page/login.html", body="dummy")

# Successful login response
responses.add(
responses.POST, f"http://{ip}/xml/setter.xml", body="successful;SID=1025573888"
)


@responses.activate
def test_successful_response():
load_login_responses("router")
router = Compal("router", "1234")
router.login()