Skip to content

Commit 8fed719

Browse files
committed
Fixes for #26 and #23
1 parent 73f1f0d commit 8fed719

File tree

20 files changed

+131
-68
lines changed

20 files changed

+131
-68
lines changed

kepconfig/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020
"""
2121
__version__ = "1.2.0"
2222
from . import connection, error
23-
from .utils import path_split
2423

kepconfig/admin/ua_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Union
1111
from ..error import KepHTTPError, KepError
1212
from ..connection import server
13+
from ..utils import _url_parse_object
1314

1415

1516
UA_ROOT = '/admin/ua_endpoints'
@@ -24,7 +25,7 @@ def _create_url(endpoint = None):
2425
if endpoint == None:
2526
return UA_ROOT
2627
else:
27-
return '{}/{}'.format(UA_ROOT,endpoint)
28+
return '{}/{}'.format(UA_ROOT, _url_parse_object(endpoint))
2829

2930
def add_endpoint(server: server, DATA: Union[dict, list]) -> Union[bool, list]:
3031
'''Add an `"endpoint"` or multiple `"endpoint"` objects to Kepware UA Server by passing a

kepconfig/admin/user_groups.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Union
1111
from ..error import KepHTTPError, KepError
1212
from ..connection import server
13+
from ..utils import _url_parse_object
1314

1415

1516
USERGROUPS_ROOT = '/admin/server_usergroups'
@@ -25,7 +26,7 @@ def _create_url(user_group = None):
2526
if user_group == None:
2627
return USERGROUPS_ROOT
2728
else:
28-
return '{}/{}'.format(USERGROUPS_ROOT,user_group)
29+
return '{}/{}'.format(USERGROUPS_ROOT, _url_parse_object(user_group))
2930

3031
def add_user_group(server: server, DATA: Union[dict, list]) -> Union[bool, list]:
3132
'''Add a `"user group"` or multiple `"user group"` objects to Kepware User Manager by passing a

kepconfig/admin/users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Union
1111
from ..error import KepError, KepHTTPError
1212
from ..connection import server
13+
from ..utils import _url_parse_object
1314

1415

1516
USERS_ROOT = '/admin/server_users'
@@ -25,7 +26,7 @@ def _create_url(user = None):
2526
if user == None:
2627
return USERS_ROOT
2728
else:
28-
return '{}/{}'.format(USERS_ROOT,user)
29+
return '{}/{}'.format(USERS_ROOT, _url_parse_object(user))
2930

3031
def add_user(server: server, DATA: Union[dict, list]) -> Union[bool, list]:
3132
'''Add a `"user"` or multiple `"user"` objects to Kepware User Manager by passing a

kepconfig/connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ def __connect(self,request_obj):
431431
# Fucntion used to ensure special characters are handled in the URL
432432
# Ex: Space will be turned to %20
433433
def __url_validate(self, url):
434-
parsed_url = parse.urlparse(url)
434+
# Configuration API does not use fragments in URL so ignore to allow # as a character
435+
# Objects in Kepware can include # as part of the object names
436+
parsed_url = parse.urlparse(url, allow_fragments= False)
435437
# Added % for scenarios where special characters have already been escaped with %
436438
updated_path = parse.quote(parsed_url.path, safe = '/%')
437439

kepconfig/connectivity/channel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import inspect
1414
from ..connection import server
1515
from ..error import KepHTTPError, KepError
16+
from ..utils import _url_parse_object
1617
from typing import Union
1718
from . import device
1819

@@ -28,7 +29,7 @@ def _create_url(channel = None):
2829
if channel == None:
2930
return CHANNEL_ROOT
3031
else:
31-
return '{}/{}'.format(CHANNEL_ROOT,channel)
32+
return '{}/{}'.format(CHANNEL_ROOT,_url_parse_object(channel))
3233

3334
def add_channel(server: server, DATA: Union[dict, list]) -> Union[bool, list]:
3435
'''Add a `"channel"` or multiple `"channel"` objects to Kepware. Can be used to pass children of a channel object
@@ -84,7 +85,7 @@ def modify_channel(server: server, DATA: dict, *, channel: str = None, force: bo
8485
8586
:param server: instance of the `server` class
8687
:param DATA: Dict of the `channel` properties to be modified
87-
:param channel: *(optional)* - name of channel to modify. Only needed if not existing in `"DATA"`
88+
:param channel: *(optional)* name of channel to modify. Only needed if not existing in `"DATA"`
8889
:param force: *(optional)* if True, will force the configuration update to the Kepware server
8990
9091
:return: True - If a "HTTP 200 - OK" is received from Kepware server

kepconfig/connectivity/device.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from ..connection import KepServiceResponse, server
1313
from ..error import KepHTTPError, KepError
14+
from ..utils import _url_parse_object, path_split
1415
from typing import Union
15-
import kepconfig
1616
from . import channel, tag
1717
import inspect
1818

@@ -28,7 +28,7 @@ def _create_url(device = None):
2828
if device == None:
2929
return DEVICE_ROOT
3030
else:
31-
return '{}/{}'.format(DEVICE_ROOT,device)
31+
return '{}/{}'.format(DEVICE_ROOT,_url_parse_object(device))
3232

3333
def add_device(server: server, channel_name: str, DATA: Union[dict, list]) -> Union[bool, list]:
3434
'''Add a `"device"` or multiple `"device"` objects to a channel in Kepware. Can be used to pass children of a device object
@@ -74,7 +74,7 @@ def del_device(server: server, device_path: str) -> bool:
7474
:raises KepURLError: If urllib provides an URLError
7575
'''
7676

77-
path_obj = kepconfig.path_split(device_path)
77+
path_obj = path_split(device_path)
7878
try:
7979
r = server._config_del(server.url + channel._create_url(path_obj['channel']) + _create_url(path_obj['device']))
8080
if r.code == 200: return True
@@ -100,7 +100,7 @@ def modify_device(server: server, device_path: str, DATA: dict, *, force: bool =
100100

101101
device_data = server._force_update_check(force, DATA)
102102

103-
path_obj = kepconfig.path_split(device_path)
103+
path_obj = path_split(device_path)
104104
try:
105105
r = server._config_update(server.url + channel._create_url(path_obj['channel']) + _create_url(path_obj['device']), device_data)
106106
if r.code == 200: return True
@@ -122,7 +122,7 @@ def get_device(server: server, device_path: str) -> dict:
122122
:raises KepURLError: If urllib provides an URLError
123123
'''
124124

125-
path_obj = kepconfig.path_split(device_path)
125+
path_obj = path_split(device_path)
126126
try:
127127
r = server._config_get(server.url + channel._create_url(path_obj['channel']) + _create_url(path_obj['device']))
128128
return r.payload
@@ -164,7 +164,7 @@ def auto_tag_gen(server: server, device_path: str, job_ttl: int = None) -> KepSe
164164
:raises KepURLError: If urllib provides an URLError
165165
'''
166166

167-
path_obj = kepconfig.path_split(device_path)
167+
path_obj = path_split(device_path)
168168
try:
169169
url = server.url +channel._create_url(path_obj['channel']) + _create_url(path_obj['device']) + ATG_URL
170170
job = server._kep_service_execute(url, None, job_ttl)

kepconfig/connectivity/egd/exchange.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
exchange objects for EGD devices within the Kepware Configuration API
1010
"""
1111

12-
from ... import path_split
1312
from ...connection import server
1413
from ...error import KepHTTPError, KepError
14+
from ...utils import _url_parse_object, path_split
1515
from typing import Union
1616
from .. import egd as EGD, channel, device
1717

@@ -34,9 +34,9 @@ def _create_url(device_path, ex_type, exchange_name = None):
3434
return device_root + PRODUCER_ROOT
3535
else:
3636
if ex_type.upper() == EGD.CONSUMER_EXCHANGE:
37-
return '{}{}/{}'.format(device_root,CONSUMER_ROOT,exchange_name)
37+
return '{}{}/{}'.format(device_root,CONSUMER_ROOT,_url_parse_object(exchange_name))
3838
else:
39-
return '{}{}/{}'.format(device_root,PRODUCER_ROOT,exchange_name)
39+
return '{}{}/{}'.format(device_root,PRODUCER_ROOT,_url_parse_object(exchange_name))
4040

4141
def add_exchange(server: server, device_path: str, ex_type: str, DATA: Union[dict, list]) -> Union[bool, list]:
4242
'''Add a `"exchange"` or multiple `"exchange"` objects to Kepware. Can be used to pass children of a exchange object

kepconfig/connectivity/egd/name.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
name resolution objects for EGD devices within the Kepware Configuration API
1010
"""
1111

12-
from ... import path_split
12+
from ...utils import _url_parse_object, path_split
1313
from ...connection import server
1414
from ...error import KepHTTPError, KepError
1515
from typing import Union
@@ -29,7 +29,7 @@ def _create_url(device_path, name = None):
2929
if name == None:
3030
return '{}/{}'.format(device_root, NAMES_ROOT)
3131
else:
32-
return '{}/{}/{}'.format(device_root, NAMES_ROOT, name)
32+
return '{}/{}/{}'.format(device_root, NAMES_ROOT, _url_parse_object(name))
3333

3434
def add_name_resolution(server: server, device_path: str, DATA: Union[dict, list]) -> Union[bool, list]:
3535
'''Add a `"name resolution"` or multiple `"name resolution"` objects to Kepware. This allows you to

kepconfig/connectivity/egd/range.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .. import egd as EGD
1414
from ...connection import server
1515
from ...error import KepError, KepHTTPError
16+
from ...utils import _url_parse_object
1617

1718
RANGES_ROOT = '/ranges'
1819

@@ -27,7 +28,7 @@ def _create_url(device_path, ex_type, exchange_name, range = None):
2728
if range == None:
2829
return '{}{}'.format(exchange_root, RANGES_ROOT)
2930
else:
30-
return '{}{}/{}'.format(exchange_root, RANGES_ROOT, range)
31+
return '{}{}/{}'.format(exchange_root, RANGES_ROOT, _url_parse_object(range))
3132

3233
def add_range(server: server, device_path: str, ex_type: str, exchange_name: str, DATA: Union[dict, list]) -> Union[bool, list]:
3334
'''Add a `"range"` or multiple `"range"` objects to Kepware. This allows you to

0 commit comments

Comments
 (0)