Commit 443f8518 authored by olivier R-D's avatar olivier R-D

Consequently Ua and not UA in code

parent 00ad7301
......@@ -106,13 +106,13 @@ class UASocketClient(object):
elif isinstance(msg, ua.ErrorMessage):
self.logger.warning("Received an error: {}".format(msg))
else:
raise ua.UAError("Unsupported message type: {}".format(msg))
raise ua.UaError("Unsupported message type: {}".format(msg))
def _call_callback(self, request_id, body):
with self._lock:
future = self._callbackmap.pop(request_id, None)
if future is None:
raise ua.UAError("No future object found for request: {}, callbacks in list are {}".format(request_id, self._callbackmap.keys()))
raise ua.UaError("No future object found for request: {}, callbacks in list are {}".format(request_id, self._callbackmap.keys()))
future.set_result(body)
def _create_request_header(self, timeout=1000):
......
......@@ -123,7 +123,7 @@ class Client(object):
return
parts = string.split(',')
if len(parts) < 4:
raise UAError('Wrong format: `{}`, expected at least 4 '
raise UaError('Wrong format: `{}`, expected at least 4 '
'comma-separated values'.format(string))
policy_class = getattr(security_policies, 'SecurityPolicy' + parts[0])
mode = getattr(ua.MessageSecurityMode, parts[1])
......@@ -314,7 +314,7 @@ class Client(object):
if not self.security_policy.server_certificate:
self.security_policy.server_certificate = response.ServerCertificate
elif self.security_policy.server_certificate != response.ServerCertificate:
raise UAError("Server certificate mismatch")
raise UaError("Server certificate mismatch")
# remember PolicyId's: we will use them in activate_session()
ep = Client.find_endpoint(response.ServerEndpoints, self.security_policy.Mode, self.security_policy.URI)
self._policy_ids = ep.UserIdentityTokens
......
......@@ -194,10 +194,10 @@ def _vtype_to_argument(vtype):
def _guess_uatype(variant):
if variant.VariantType == ua.VariantType.ExtensionObject:
if variant.Value is None:
raise ua.UAError("Cannot guess DataType from Null ExtensionObject")
raise ua.UaError("Cannot guess DataType from Null ExtensionObject")
if type(variant.Value) in (list, tuple):
if len(variant.Value) == 0:
raise ua.UAError("Cannot guess DataType from Null ExtensionObject")
raise ua.UaError("Cannot guess DataType from Null ExtensionObject")
extobj = variant.Value[0]
else:
extobj = variant.Value
......
......@@ -24,7 +24,7 @@ class Node(object):
elif isinstance(nodeid, int):
self.nodeid = ua.NodeId(nodeid, 0)
else:
raise ua.UAError("argument to node must be a NodeId object or a string defining a nodeid found {} of type {}".format(nodeid, type(nodeid)))
raise ua.UaError("argument to node must be a NodeId object or a string defining a nodeid found {} of type {}".format(nodeid, type(nodeid)))
def __eq__(self, other):
if isinstance(other, Node) and self.nodeid == other.nodeid:
......
......@@ -3,13 +3,13 @@ Define exceptions to be raised at various places in the stack
"""
class UAError(RuntimeError):
class UaError(RuntimeError):
pass
class UAStatusCodeError(UAError):
class UaStatusCodeError(UaError):
pass
class UAStringParsingError(UAError):
class UaStringParsingError(UaError):
pass
......@@ -11,20 +11,20 @@ except ImportError:
import trollius as asyncio
from opcua.common.uaerrors import UAError
from opcua.common.uaerrors import UaError
class ServiceError(UAError):
class ServiceError(UaError):
def __init__(self, code):
super(ServiceError, self).__init__('UA Service Error')
self.code = code
class NotEnoughData(UAError):
class NotEnoughData(UaError):
pass
class SocketClosedException(UAError):
class SocketClosedException(UaError):
pass
......
from abc import ABCMeta, abstractmethod
from opcua.ua import CryptographyNone, SecurityPolicy
from opcua.ua import MessageSecurityMode
from opcua.ua import UAError
from opcua.ua import UaError
try:
from opcua.crypto import uacrypto
CRYPTOGRAPHY_AVAILABLE = True
......@@ -15,7 +15,7 @@ def require_cryptography(obj):
Call this function in constructors.
"""
if not CRYPTOGRAPHY_AVAILABLE:
raise UAError("Can't use {}, cryptography module is not installed".format(obj.__class__.__name__))
raise UaError("Can't use {}, cryptography module is not installed".format(obj.__class__.__name__))
class Signer(object):
......
......@@ -10,7 +10,7 @@ from threading import Thread
from threading import Condition
from opcua import ua
from opcua.uaprocessor import UAProcessor
from opcua.uaprocessor import UaProcessor
logger = logging.getLogger(__name__)
......@@ -61,7 +61,7 @@ class UAHandler(socketserver.BaseRequestHandler):
def handle(self):
sock = ua.utils.SocketWrapper(self.request)
processor = UAProcessor(self.server.internal_server, sock, self.client_address)
processor = UaProcessor(self.server.internal_server, sock, self.client_address)
try:
while True:
hdr = ua.Header.from_string(sock)
......
......@@ -10,7 +10,7 @@ except ImportError:
from opcua import ua
from opcua.server.uaprocessor import UAProcessor
from opcua.server.uaprocessor import UaProcessor
logger = logging.getLogger(__name__)
......@@ -49,7 +49,7 @@ class BinaryServer(object):
self.peername = transport.get_extra_info('peername')
self.logger.info('New connection from %s', self.peername)
self.transport = transport
self.processor = UAProcessor(self.iserver, self.transport)
self.processor = UaProcessor(self.iserver, self.transport)
self.processor.set_policies(self.policies)
self.data = b""
......
......@@ -15,7 +15,7 @@ class PublishRequestData(object):
self.seqhdr = None
class UAProcessor(object):
class UaProcessor(object):
def __init__(self, internal_server, socket):
self.logger = logging.getLogger(__name__)
......
#AUTOGENERATED!!!
from opcua.common.uaerrors import UAStatusCodeError
from opcua.common.uaerrors import UaStatusCodeError
class StatusCodes(object):
Good = 0
......
......@@ -6,7 +6,7 @@ from datetime import datetime
from enum import Enum, IntEnum
from opcua.common.utils import Buffer
from opcua.common.uaerrors import UAError
from opcua.common.uaerrors import UaError
from opcua.ua.uatypes import *
from opcua.ua.object_ids import ObjectIds
......@@ -14321,7 +14321,7 @@ def extensionobject_from_binary(data):
return e
klass = ExtensionClasses[TypeId.Identifier]
if body is None:
raise UAError("parsing ExtensionObject {} without data".format(klass.__name__))
raise UaError("parsing ExtensionObject {} without data".format(klass.__name__))
return klass.from_binary(body)
......
......@@ -380,7 +380,7 @@ class MessageChunk(uatypes.FrozenClass):
elif msg_type == MessageType.SecureOpen:
self.SecurityHeader = AsymmetricAlgorithmHeader()
else:
raise UAError("Unsupported message type: {}".format(msg_type))
raise UaError("Unsupported message type: {}".format(msg_type))
self.SequenceHeader = SequenceHeader()
self.Body = body
self._security_policy = security_policy
......@@ -402,7 +402,7 @@ class MessageChunk(uatypes.FrozenClass):
security_header = AsymmetricAlgorithmHeader.from_binary(data)
crypto = security_policy.asymmetric_cryptography
else:
raise UAError("Unsupported message type: {}".format(header.MessageType))
raise UaError("Unsupported message type: {}".format(header.MessageType))
obj = MessageChunk(crypto)
obj.MessageHeader = header
obj.SecurityHeader = security_header
......@@ -532,7 +532,7 @@ class SecureConnection(object):
return
if self._security_policy.URI != uri or (mode is not None and
self._security_policy.Mode != mode):
raise UAError("No matching policy: {}, {}".format(uri, mode))
raise UaError("No matching policy: {}, {}".format(uri, mode))
def set_security_token(self, tok):
self._security_token = tok
......@@ -572,16 +572,16 @@ class SecureConnection(object):
assert isinstance(chunk, MessageChunk), "Expected chunk, got: {}".format(chunk)
if chunk.MessageHeader.MessageType != MessageType.SecureOpen:
if chunk.MessageHeader.ChannelId != self._security_token.ChannelId:
raise UAError("Wrong channel id {}, expected {}".format(
raise UaError("Wrong channel id {}, expected {}".format(
chunk.MessageHeader.ChannelId,
self._security_token.ChannelId))
if chunk.SecurityHeader.TokenId != self._security_token.TokenId:
raise UAError("Wrong token id {}, expected {}".format(
raise UaError("Wrong token id {}, expected {}".format(
chunk.SecurityHeader.TokenId,
self._security_token.TokenId))
if self._incoming_parts:
if self._incoming_parts[0].SequenceHeader.RequestId != chunk.SequenceHeader.RequestId:
raise UAError("Wrong request id {}, expected {}".format(
raise UaError("Wrong request id {}, expected {}".format(
chunk.SequenceHeader.RequestId,
self._incoming_parts[0].SequenceHeader.RequestId))
......@@ -595,7 +595,7 @@ class SecureConnection(object):
logger.debug("Sequence number wrapped: %d -> %d",
self._peer_sequence_number, num)
else:
raise UAError(
raise UaError(
"Wrong sequence {} -> {} (server bug or replay attack)"
.format(self._peer_sequence_number, num))
self._peer_sequence_number = num
......@@ -630,7 +630,7 @@ class SecureConnection(object):
logger.warning("Received an error: {}".format(msg))
return msg
else:
raise UAError("Unsupported message type {}".format(header.MessageType))
raise UaError("Unsupported message type {}".format(header.MessageType))
def receive_from_socket(self, socket):
"""
......@@ -643,7 +643,7 @@ class SecureConnection(object):
logger.info("received header: %s", header)
body = socket.read(header.body_size)
if len(body) != header.body_size:
raise UAError("{} bytes expected, {} available".format(header.body_size, len(body)))
raise UaError("{} bytes expected, {} available".format(header.body_size, len(body)))
return self.receive_from_header_and_body(header, utils.Buffer(body))
def _receive(self, msg):
......@@ -663,7 +663,7 @@ class SecureConnection(object):
self._incoming_parts = []
return message
else:
raise UAError("Unsupported chunk type: {}".format(msg))
raise UaError("Unsupported chunk type: {}".format(msg))
# FIXES for missing switchfield in NodeAttributes classes
......
......@@ -13,8 +13,8 @@ if sys.version_info.major > 2:
unicode = str
from opcua.ua import status_codes
from opcua.common.uaerrors import UAError
from opcua.common.uaerrors import UAStatusCodeError
from opcua.common.uaerrors import UaError
from opcua.common.uaerrors import UaStatusCodeError
logger = logging.getLogger('opcua.uaprotocol')
......@@ -171,7 +171,7 @@ def unpack_uatype(uatype, data):
klass = glbs[uatype]
if hasattr(klass, 'from_binary'):
return klass.from_binary(data)
raise UAError("can not unpack unknown uatype %s" % uatype)
raise UaError("can not unpack unknown uatype %s" % uatype)
def unpack_uatype_array(uatype, data):
......@@ -319,7 +319,7 @@ class StatusCode(FrozenClass):
use is is_good() method if not exception is desired
"""
if self.value != 0:
raise UAStatusCodeError("{}({})".format(self.doc, self.name))
raise UaStatusCodeError("{}({})".format(self.doc, self.name))
def is_good(self):
"""
......@@ -383,7 +383,7 @@ class NodeId(FrozenClass):
elif isinstance(self.Identifier, bytes):
self.NodeIdType = NodeIdType.ByteString
else:
raise UAError("NodeId: Could not guess type of NodeId, set NodeIdType")
raise UaError("NodeId: Could not guess type of NodeId, set NodeIdType")
def __key(self):
if self.NodeIdType in (NodeIdType.TwoByte, NodeIdType.FourByte, NodeIdType.Numeric): # twobyte, fourbyte and numeric may represent the same node
......@@ -430,7 +430,7 @@ class NodeId(FrozenClass):
elif k == "nsu":
nsu = v
if identifier is None:
raise UAError("Could not parse nodeid string: " + string)
raise UaError("Could not parse nodeid string: " + string)
nodeid = NodeId(identifier, namespace, ntype)
nodeid.NamespaceUri = nsu
nodeid.ServerIndex = srv
......@@ -504,7 +504,7 @@ class NodeId(FrozenClass):
nid.NamespaceIndex = uatype_UInt16.unpack(data.read(2))[0]
nid.Identifier = Guid.from_binary(data)
else:
raise UAError("Unknown NodeId encoding: " + str(nid.NodeIdType))
raise UaError("Unknown NodeId encoding: " + str(nid.NodeIdType))
if test_bit(encoding, 7):
nid.NamespaceUri = unpack_string(data)
......@@ -561,7 +561,7 @@ class QualifiedName(FrozenClass):
def __init__(self, name="", namespaceidx=0):
if not isinstance(namespaceidx, int):
raise UAError("namespaceidx must be an int")
raise UaError("namespaceidx must be an int")
self.NamespaceIndex = namespaceidx
self.Name = name
self._freeze = True
......@@ -777,7 +777,7 @@ class VariantTypeCustom(object):
self.name = "Custom"
self.value = val
if self.value > 0b00111111:
raise UAError("Cannot create VariantType. VariantType must be %s > x > %s", 0b111111, 25)
raise UaError("Cannot create VariantType. VariantType must be %s > x > %s", 0b111111, 25)
def __str__(self):
return "VariantType.Custom:{}".format(self.value)
......@@ -824,7 +824,7 @@ class Variant(FrozenClass):
def _guess_type(self, val):
while isinstance(val, (list, tuple)):
if len(val) == 0:
raise UAError("could not guess UA variable type")
raise UaError("could not guess UA variable type")
val = val[0]
if val is None:
return VariantType.Null
......@@ -847,7 +847,7 @@ class Variant(FrozenClass):
except AttributeError:
return VariantType.ExtensionObject
else:
raise UAError("Could not guess UA type of {} with type {}, specify UA type".format(val, type(val)))
raise UaError("Could not guess UA type of {} with type {}, specify UA type".format(val, type(val)))
def __str__(self):
return "Variant(val:{!s},type:{})".format(self.Value, self.VariantType)
......
......@@ -135,7 +135,7 @@ class Unit(unittest.TestCase):
self.assertEqual(l, l2)
def test_custom_variant(self):
with self.assertRaises(ua.UAError):
with self.assertRaises(ua.UaError):
v = ua.Variant(b"ljsdfljds", ua.VariantTypeCustom(89))
v = ua.Variant(b"ljsdfljds", ua.VariantTypeCustom(61))
v2 = ua.Variant.from_binary(ua.utils.Buffer(v.to_binary()))
......@@ -464,11 +464,11 @@ class CommonTests(object):
def test_subscribe_events_to_wrong_node(self):
sub = self.opc.create_subscription(100, sclt)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
handle = sub.subscribe_events(self.opc.get_node("i=85"))
o = self.opc.get_objects_node()
v = o.add_variable(3, 'VariableNoEventNofierAttribute', 4)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
handle = sub.subscribe_events(v)
sub.delete()
......@@ -522,12 +522,12 @@ class CommonTests(object):
def test_non_existing_path(self):
root = self.opc.get_root_node()
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
server_time_node = root.get_child(['0:Objects', '0:Server', '0:nonexistingnode'])
def test_bad_attribute(self):
root = self.opc.get_root_node()
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
root.set_value(99)
def test_get_node_by_nodeid(self):
......@@ -677,7 +677,7 @@ class CommonTests(object):
def test_add_exception(self):
objects = self.opc.get_objects_node()
o = objects.add_object('ns=2;i=103;', '2:AddReadObject')
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
o2 = objects.add_object('ns=2;i=103;', '2:AddReadObject')
def test_negative_value(self):
......@@ -694,13 +694,13 @@ class CommonTests(object):
def test_bad_node(self):
bad = self.opc.get_node(ua.NodeId(999, 999))
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
bad.get_browse_name()
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
bad.set_value(89)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
bad.add_object(0, "0:myobj")
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
bad.get_child("0:myobj")
def test_value(self):
......@@ -759,7 +759,7 @@ class CommonTests(object):
msclt = MySubHandler()
o = self.opc.get_objects_node()
sub = self.opc.create_subscription(100, msclt)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
handle1 = sub.subscribe_data_change(o) # we can only subscribe to variables so this should fail
sub.delete()
......@@ -830,13 +830,13 @@ class CommonTests(object):
self.assertEqual(node, v1)
self.assertEqual(val, [5])
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(999) # non existing handle
sub.unsubscribe(handle1)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(handle1) # second try should fail
sub.delete()
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(handle1) # sub does not exist anymore
def test_subscription_data_change(self):
......@@ -870,13 +870,13 @@ class CommonTests(object):
self.assertEqual(node, v1)
self.assertEqual(val, [5])
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(999) # non existing handle
sub.unsubscribe(handle1)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(handle1) # second try should fail
sub.delete()
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
sub.unsubscribe(handle1) # sub does not exist anymore
......@@ -980,10 +980,10 @@ class CommonTests(object):
m = o.get_child("2:ServerMethod")
result = o.call_method("2:ServerMethod", 2.1)
self.assertEqual(result, 4.2)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
# FIXME: we should raise a more precise exception
result = o.call_method("2:ServerMethod", 2.1, 89, 9)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
result = o.call_method(ua.NodeId(999), 2.1) # non existing method
def test_method_array(self):
......@@ -1073,14 +1073,14 @@ class AdminTestClient(unittest.TestCase, CommonTests):
def test_service_fault(self):
request = ua.ReadRequest()
request.TypeId = ua.FourByteNodeId(999) # bad type!
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
self.clt.bclient._uasocket.send_request(request)
def test_objects_anonymous(self):
objects = self.ro_clt.get_objects_node()
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
objects.set_attribute(ua.AttributeIds.WriteMask, ua.DataValue(999))
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
f = objects.add_folder(3, 'MyFolder')
def test_folder_anonymous(self):
......@@ -1088,7 +1088,7 @@ class AdminTestClient(unittest.TestCase, CommonTests):
f = objects.add_folder(3, 'MyFolderRO')
f_ro = self.ro_clt.get_node(f.nodeid)
self.assertEqual(f, f_ro)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
f2 = f_ro.add_folder(3, 'MyFolder2')
def test_variable_anonymous(self):
......@@ -1096,14 +1096,14 @@ class AdminTestClient(unittest.TestCase, CommonTests):
v = objects.add_variable(3, 'MyROVariable', 6)
v.set_value(4) #this should work
v_ro = self.ro_clt.get_node(v.nodeid)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
v_ro.set_value(2)
self.assertEqual(v_ro.get_value(), 4)
v.set_writable(True)
v_ro.set_value(2) #now it should work
self.assertEqual(v_ro.get_value(), 2)
v.set_writable(False)
with self.assertRaises(ua.UAStatusCodeError):
with self.assertRaises(ua.UaStatusCodeError):
v_ro.set_value(9)
self.assertEqual(v_ro.get_value(), 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment