Skip to content

Commit df16c68

Browse files
committed
Use only bundled WSDL files, reduce file IO operations
1 parent 7eb2eec commit df16c68

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

onvif/cli.py

-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import argparse
44
import ast
55
import cmd
6-
import os.path
76
import re
87

98
import zeep.exceptions
@@ -50,7 +49,6 @@ def setup(self, args):
5049
args.port,
5150
args.user,
5251
args.password,
53-
args.wsdl,
5452
use_token_digest=args.encrypt,
5553
)
5654

@@ -181,12 +179,6 @@ def create_parser():
181179
required=True,
182180
help='Password for authentication',
183181
)
184-
parser.add_argument(
185-
'-w',
186-
'--wsdl',
187-
default=os.path.join(os.path.dirname(os.path.dirname(__file__)), 'wsdl'),
188-
help='directory to store ONVIF WSDL documents',
189-
)
190182
parser.add_argument(
191183
'-e',
192184
'--encrypt',

onvif/client.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
import logging
3-
import os.path
3+
import os
44
import typing
55

66
import zeep.client
@@ -103,9 +103,6 @@ def __init__(
103103
use_token_digest: bool = True,
104104
device_time_drift: typing.Optional[datetime.timedelta] = None,
105105
):
106-
if not os.path.isfile(url):
107-
raise exceptions.ONVIFError(f"{url!r} doesn't exist!")
108-
109106
self.url = url
110107
self.xaddr = xaddr
111108

@@ -204,7 +201,6 @@ class ONVIFCamera:
204201
:param port: Camera port.
205202
:param username: Camera username.
206203
:param password: Camera user password.
207-
:param wsdl_dir: Directory with WSDL definitions, use the bundled one by default.
208204
:param use_token_digest: Use password digest for WSSE authentication.
209205
:param adjust_time: Allows authentication on cameras without being time synchronized.
210206
NOTE: Please note that using NTP on both end is the recommended
@@ -218,7 +214,6 @@ def __init__(
218214
port: int,
219215
username: str,
220216
password: str,
221-
wsdl_dir: typing.Optional[str] = None,
222217
use_token_digest: bool = True,
223218
adjust_time: bool = False,
224219
):
@@ -230,7 +225,6 @@ def __init__(
230225
self._port = port
231226
self._username = username
232227
self._password = password
233-
self._wsdl_dir = wsdl_dir
234228
self._use_token_digest = use_token_digest
235229
self._adjust_time = adjust_time
236230

@@ -245,10 +239,6 @@ def __init__(
245239

246240
self.to_dict = ONVIFService.to_dict
247241

248-
# TODO: Better to handle with pathlib
249-
if self._wsdl_dir is None:
250-
self._wsdl_dir = os.path.join(os.path.dirname(__file__), 'wsdl')
251-
252242
async def update_xaddrs(self):
253243
"""Update xaddrs for services."""
254244

@@ -306,9 +296,7 @@ def get_definition(self, name, port_type=None):
306296
namespace += '/' + port_type
307297

308298
# TODO: Cache or load asynchronously
309-
wsdlpath = os.path.join(self._wsdl_dir, wsdl_file)
310-
if not os.path.isfile(wsdlpath):
311-
raise exceptions.ONVIFError(f'No such file: {wsdlpath!r}')
299+
wsdl_path = str(wsdl.WSDL_DIR / wsdl_file)
312300

313301
# XAddr for devicemgmt is fixed
314302
if name == 'devicemgmt':
@@ -318,14 +306,14 @@ def get_definition(self, name, port_type=None):
318306
host = f'http://{self._host}'
319307

320308
xaddr = f'{host}:{self._port}/onvif/device_service'
321-
return xaddr, wsdlpath, binding_name
309+
return xaddr, wsdl_path, binding_name
322310

323311
# Get XAddr
324312
xaddr = self._xaddrs.get(namespace)
325313
if not xaddr:
326314
raise exceptions.ONVIFError(f"Device doesn't support service: {name!r}")
327315

328-
return xaddr, wsdlpath, binding_name
316+
return xaddr, wsdl_path, binding_name
329317

330318
def create_onvif_service(
331319
self,

onvif/wsdl/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import pathlib
2+
3+
4+
WSDL_DIR = pathlib.Path(__file__).parent
15
SERVICES = {
26
'devicemgmt': {
37
'ns': 'http://www.onvif.org/ver10/device/wsdl',

0 commit comments

Comments
 (0)