Skip to content
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 .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install package with test dependencies
run: python -m pip install --upgrade pip && pip install -e .[isapi]
run: python -m pip install --upgrade pip && pip install -e .

- name: Run tests
run: python -m unittest discover -s test -v
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Code is licensed under the MIT license.

* Python 3.10+
* [requests](https://pypi.org/project/requests/) >= 2.20.0
* [xmltodict](https://pypi.org/project/xmltodict/) >= 0.13.0 - used by `ISAPIClient`

Optional:
* `xmltodict` >= 0.13.0 - required for `ISAPIClient` (install with the `isapi` extra)
* [pyDispatcher](https://pypi.org/project/PyDispatcher/) 2.0.5 - only needed if you want `HikCamera` to also broadcast updates via `pydispatch` signals; the built-in callback mechanism (`add_update_callback`) works without it

# Installation
Expand All @@ -24,11 +24,7 @@ Optional:
pip install pyhik
```

To also use `ISAPIClient`:

```
pip install pyhik[isapi]
```
`ISAPIClient` is included. (`pip install pyhik[isapi]` still works, but the extra is no longer needed.)

# Usage - Event streaming (`HikCamera`)

Expand Down
16 changes: 1 addition & 15 deletions pyhik/isapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import requests
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
from requests.structures import CaseInsensitiveDict
import xmltodict

from pyhik.image import (
ImageChannelInfo,
Expand All @@ -32,11 +33,6 @@
parse_response_status,
)

try:
import xmltodict
except ImportError:
xmltodict = None

_LOGGER = logging.getLogger(__name__)

# ISAPI Endpoints
Expand Down Expand Up @@ -353,23 +349,13 @@ def _check_digest_auth(self) -> Optional[HTTPDigestAuth]:

def _parse_xml(self, text: str) -> Dict[str, Any]:
"""Parse XML response to dictionary."""
if xmltodict is None:
raise ISAPIError(
"xmltodict is required for ISAPI client. "
"Install it with: pip install xmltodict"
)
try:
return xmltodict.parse(text)
except Exception:
return {"raw": text}

def _unparse_xml(self, data: Dict[str, Any]) -> str:
"""Convert dictionary to XML string."""
if xmltodict is None:
raise ISAPIError(
"xmltodict is required for ISAPI client. "
"Install it with: pip install xmltodict"
)
return xmltodict.unparse(data)

def request(
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
python_requires='>=3.10',
install_requires=[
'requests>=2.20.0',
'xmltodict>=0.13.0',
],
extras_require={
'isapi': ['xmltodict>=0.13.0'],
# xmltodict is now always installed; the extra stays so that
# 'pip install pyHik[isapi]' keeps working.
'isapi': [],
},
)
4 changes: 0 additions & 4 deletions test/test_isapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import requests
from requests.auth import HTTPBasicAuth, HTTPDigestAuth

# xmltodict is an optional extra (pip install pyHik[isapi]); tests that need
# response parsing are skipped when it isn't installed.
from pyhik.isapi import xmltodict
from pyhik.isapi import (
ISAPIClient,
ISAPIError,
Expand Down Expand Up @@ -181,7 +178,6 @@ def test_context_manager(self):
class TestISAPIClientRequests(unittest.TestCase):
"""Test ISAPIClient HTTP request handling."""

@unittest.skipIf(xmltodict is None, "requires the isapi extra")
def test_auth_detection_digest(self, mock_session_class):
"""Test digest auth detection."""
session = mock_session_class.return_value
Expand Down
Loading