Skip to content

Commit 02e15e3

Browse files
author
Lukas Kaupp
committed
ruff formatted
1 parent 85fa3d6 commit 02e15e3

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

asyncua/client/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ..common.ua_utils import value_to_datavalue, copy_dataclass_attr
2424
from ..crypto import uacrypto, security_policies
2525
from ..crypto.validator import CertificateValidatorMethod
26+
from ..ua.ua_binary import LowApiConfig
2627

2728
_logger = logging.getLogger(__name__)
2829

@@ -41,7 +42,7 @@ class Client:
4142
_password: Optional[str] = None
4243
strip_url_credentials: bool = True
4344

44-
def __init__(self, url: str, timeout: float = 4, watchdog_intervall: float = 1.0):
45+
def __init__(self, url: str, timeout: float = 4, watchdog_intervall: float = 1.0, encoding="utf-8"):
4546
"""
4647
:param url: url of the server.
4748
if you are unsure of url, write at least hostname
@@ -91,6 +92,7 @@ def __init__(self, url: str, timeout: float = 4, watchdog_intervall: float = 1.0
9192
self._closing: bool = False
9293
self.certificate_validator: Optional[CertificateValidatorMethod] = None
9394
"""hook to validate a certificate, raises a ServiceError when not valid"""
95+
LowApiConfig.String_Encoding = encoding
9496

9597
async def __aenter__(self):
9698
await self.connect()

asyncua/client/ua_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from asyncua.common.session_interface import AbstractSession
1212
from ..common.utils import wait_for
1313
from asyncua.ua.uaerrors._base import UaError
14-
from ..ua.ua_binary import struct_from_binary, uatcp_to_binary, struct_to_binary, nodeid_from_binary, \
15-
header_from_binary, LowApiConfig
14+
from ..ua.ua_binary import struct_from_binary, uatcp_to_binary, struct_to_binary, nodeid_from_binary, header_from_binary
1615
from ..ua.uaerrors import BadTimeout, BadNoSubscription, BadSessionClosed, BadUserAccessDenied, UaStructParsingError
1716
from ..ua.uaprotocol_auto import OpenSecureChannelResult, SubscriptionAcknowledgement
1817
from ..common.connection import SecureConnection, TransportLimits
@@ -289,7 +288,7 @@ class UaClient(AbstractSession):
289288
uaprotocol_auto.py and uaprotocol_hand.py available under asyncua.ua
290289
"""
291290

292-
def __init__(self, timeout: float = 1.0, encoding = "utf-8"):
291+
def __init__(self, timeout: float = 1.0):
293292
"""
294293
:param timeout: Timout in seconds
295294
"""
@@ -301,7 +300,6 @@ def __init__(self, timeout: float = 1.0, encoding = "utf-8"):
301300
self._publish_task = None
302301
self._pre_request_hook: Optional[Callable[[], Awaitable[None]]] = None
303302
self._closing: bool = False
304-
LowApiConfig.String_Encoding = encoding
305303

306304
def set_security(self, policy: security_policies.SecurityPolicy):
307305
self.security_policy = policy

asyncua/server/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Server:
8585
server listens on some internal IP.
8686
"""
8787

88-
def __init__(self, iserver: InternalServer = None, user_manager=None, encoding = "utf-8"):
88+
def __init__(self, iserver: InternalServer = None, user_manager=None, encoding="utf-8"):
8989
self.endpoint = urlparse("opc.tcp://0.0.0.0:4840/freeopcua/server/")
9090
self._application_uri = "urn:freeopcua:python:server"
9191
self.product_uri = "urn:freeopcua.github.io:python:server"

asyncua/ua/ua_binary.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,24 @@ def unpack(data):
7070
return None
7171
return data.read(length)
7272

73+
7374
class LowApiConfig:
7475
String_Encoding: str = "utf-8"
7576

77+
7678
class _String:
7779
@staticmethod
7880
def pack(string):
7981
if string is not None:
80-
string = string.encode(LowApiConfig.String_Encoding, errors='surrogateescape')
82+
string = string.encode(LowApiConfig.String_Encoding, errors="surrogateescape")
8183
return _Bytes.pack(string)
8284

8385
@staticmethod
8486
def unpack(data):
8587
b = _Bytes.unpack(data)
8688
if b is None:
8789
return b
88-
return b.decode(LowApiConfig.String_Encoding, errors='surrogateescape') # not need to be strict here, this is user data
90+
return b.decode(LowApiConfig.String_Encoding, errors="surrogateescape")
8991

9092

9193
class _Null:

0 commit comments

Comments
 (0)