Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
443f8518
Commit
443f8518
authored
Jan 24, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consequently Ua and not UA in code
parent
00ad7301
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
70 additions
and
70 deletions
+70
-70
opcua/client/binary_client.py
opcua/client/binary_client.py
+2
-2
opcua/client/client.py
opcua/client/client.py
+2
-2
opcua/common/create_nodes.py
opcua/common/create_nodes.py
+2
-2
opcua/common/node.py
opcua/common/node.py
+1
-1
opcua/common/uaerrors.py
opcua/common/uaerrors.py
+3
-3
opcua/common/utils.py
opcua/common/utils.py
+4
-4
opcua/crypto/security_policies.py
opcua/crypto/security_policies.py
+2
-2
opcua/server/binary_server.py
opcua/server/binary_server.py
+2
-2
opcua/server/binary_server_asyncio.py
opcua/server/binary_server_asyncio.py
+2
-2
opcua/server/uaprocessor.py
opcua/server/uaprocessor.py
+1
-1
opcua/ua/status_codes.py
opcua/ua/status_codes.py
+1
-1
opcua/ua/uaprotocol_auto.py
opcua/ua/uaprotocol_auto.py
+2
-2
opcua/ua/uaprotocol_hand.py
opcua/ua/uaprotocol_hand.py
+10
-10
opcua/ua/uatypes.py
opcua/ua/uatypes.py
+11
-11
tests/tests.py
tests/tests.py
+25
-25
No files found.
opcua/client/binary_client.py
View file @
443f8518
...
...
@@ -106,13 +106,13 @@ class UASocketClient(object):
elif
isinstance
(
msg
,
ua
.
ErrorMessage
):
self
.
logger
.
warning
(
"Received an error: {}"
.
format
(
msg
))
else
:
raise
ua
.
U
A
Error
(
"Unsupported message type: {}"
.
format
(
msg
))
raise
ua
.
U
a
Error
(
"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
.
U
A
Error
(
"No future object found for request: {}, callbacks in list are {}"
.
format
(
request_id
,
self
.
_callbackmap
.
keys
()))
raise
ua
.
U
a
Error
(
"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
):
...
...
opcua/client/client.py
View file @
443f8518
...
...
@@ -123,7 +123,7 @@ class Client(object):
return
parts
=
string
.
split
(
','
)
if
len
(
parts
)
<
4
:
raise
U
A
Error
(
'Wrong format: `{}`, expected at least 4 '
raise
U
a
Error
(
'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
U
A
Error
(
"Server certificate mismatch"
)
raise
U
a
Error
(
"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
...
...
opcua/common/create_nodes.py
View file @
443f8518
...
...
@@ -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
.
U
A
Error
(
"Cannot guess DataType from Null ExtensionObject"
)
raise
ua
.
U
a
Error
(
"Cannot guess DataType from Null ExtensionObject"
)
if
type
(
variant
.
Value
)
in
(
list
,
tuple
):
if
len
(
variant
.
Value
)
==
0
:
raise
ua
.
U
A
Error
(
"Cannot guess DataType from Null ExtensionObject"
)
raise
ua
.
U
a
Error
(
"Cannot guess DataType from Null ExtensionObject"
)
extobj
=
variant
.
Value
[
0
]
else
:
extobj
=
variant
.
Value
...
...
opcua/common/node.py
View file @
443f8518
...
...
@@ -24,7 +24,7 @@ class Node(object):
elif
isinstance
(
nodeid
,
int
):
self
.
nodeid
=
ua
.
NodeId
(
nodeid
,
0
)
else
:
raise
ua
.
U
A
Error
(
"argument to node must be a NodeId object or a string defining a nodeid found {} of type {}"
.
format
(
nodeid
,
type
(
nodeid
)))
raise
ua
.
U
a
Error
(
"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
:
...
...
opcua/common/uaerrors.py
View file @
443f8518
...
...
@@ -3,13 +3,13 @@ Define exceptions to be raised at various places in the stack
"""
class
U
A
Error
(
RuntimeError
):
class
U
a
Error
(
RuntimeError
):
pass
class
U
AStatusCodeError
(
UA
Error
):
class
U
aStatusCodeError
(
Ua
Error
):
pass
class
U
AStringParsingError
(
UA
Error
):
class
U
aStringParsingError
(
Ua
Error
):
pass
opcua/common/utils.py
View file @
443f8518
...
...
@@ -11,20 +11,20 @@ except ImportError:
import
trollius
as
asyncio
from
opcua.common.uaerrors
import
U
A
Error
from
opcua.common.uaerrors
import
U
a
Error
class
ServiceError
(
U
A
Error
):
class
ServiceError
(
U
a
Error
):
def
__init__
(
self
,
code
):
super
(
ServiceError
,
self
).
__init__
(
'UA Service Error'
)
self
.
code
=
code
class
NotEnoughData
(
U
A
Error
):
class
NotEnoughData
(
U
a
Error
):
pass
class
SocketClosedException
(
U
A
Error
):
class
SocketClosedException
(
U
a
Error
):
pass
...
...
opcua/crypto/security_policies.py
View file @
443f8518
from
abc
import
ABCMeta
,
abstractmethod
from
opcua.ua
import
CryptographyNone
,
SecurityPolicy
from
opcua.ua
import
MessageSecurityMode
from
opcua.ua
import
U
A
Error
from
opcua.ua
import
U
a
Error
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
U
A
Error
(
"Can't use {}, cryptography module is not installed"
.
format
(
obj
.
__class__
.
__name__
))
raise
U
a
Error
(
"Can't use {}, cryptography module is not installed"
.
format
(
obj
.
__class__
.
__name__
))
class
Signer
(
object
):
...
...
opcua/server/binary_server.py
View file @
443f8518
...
...
@@ -10,7 +10,7 @@ from threading import Thread
from
threading
import
Condition
from
opcua
import
ua
from
opcua.uaprocessor
import
U
A
Processor
from
opcua.uaprocessor
import
U
a
Processor
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -61,7 +61,7 @@ class UAHandler(socketserver.BaseRequestHandler):
def
handle
(
self
):
sock
=
ua
.
utils
.
SocketWrapper
(
self
.
request
)
processor
=
U
A
Processor
(
self
.
server
.
internal_server
,
sock
,
self
.
client_address
)
processor
=
U
a
Processor
(
self
.
server
.
internal_server
,
sock
,
self
.
client_address
)
try
:
while
True
:
hdr
=
ua
.
Header
.
from_string
(
sock
)
...
...
opcua/server/binary_server_asyncio.py
View file @
443f8518
...
...
@@ -10,7 +10,7 @@ except ImportError:
from
opcua
import
ua
from
opcua.server.uaprocessor
import
U
A
Processor
from
opcua.server.uaprocessor
import
U
a
Processor
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
=
U
A
Processor
(
self
.
iserver
,
self
.
transport
)
self
.
processor
=
U
a
Processor
(
self
.
iserver
,
self
.
transport
)
self
.
processor
.
set_policies
(
self
.
policies
)
self
.
data
=
b""
...
...
opcua/server/uaprocessor.py
View file @
443f8518
...
...
@@ -15,7 +15,7 @@ class PublishRequestData(object):
self
.
seqhdr
=
None
class
U
A
Processor
(
object
):
class
U
a
Processor
(
object
):
def
__init__
(
self
,
internal_server
,
socket
):
self
.
logger
=
logging
.
getLogger
(
__name__
)
...
...
opcua/ua/status_codes.py
View file @
443f8518
#AUTOGENERATED!!!
from
opcua.common.uaerrors
import
U
A
StatusCodeError
from
opcua.common.uaerrors
import
U
a
StatusCodeError
class
StatusCodes
(
object
):
Good
=
0
...
...
opcua/ua/uaprotocol_auto.py
View file @
443f8518
...
...
@@ -6,7 +6,7 @@ from datetime import datetime
from
enum
import
Enum
,
IntEnum
from
opcua.common.utils
import
Buffer
from
opcua.common.uaerrors
import
U
A
Error
from
opcua.common.uaerrors
import
U
a
Error
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
U
A
Error
(
"parsing ExtensionObject {} without data"
.
format
(
klass
.
__name__
))
raise
U
a
Error
(
"parsing ExtensionObject {} without data"
.
format
(
klass
.
__name__
))
return
klass
.
from_binary
(
body
)
...
...
opcua/ua/uaprotocol_hand.py
View file @
443f8518
...
...
@@ -380,7 +380,7 @@ class MessageChunk(uatypes.FrozenClass):
elif
msg_type
==
MessageType
.
SecureOpen
:
self
.
SecurityHeader
=
AsymmetricAlgorithmHeader
()
else
:
raise
U
A
Error
(
"Unsupported message type: {}"
.
format
(
msg_type
))
raise
U
a
Error
(
"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
U
A
Error
(
"Unsupported message type: {}"
.
format
(
header
.
MessageType
))
raise
U
a
Error
(
"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
U
A
Error
(
"No matching policy: {}, {}"
.
format
(
uri
,
mode
))
raise
U
a
Error
(
"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
U
A
Error
(
"Wrong channel id {}, expected {}"
.
format
(
raise
U
a
Error
(
"Wrong channel id {}, expected {}"
.
format
(
chunk
.
MessageHeader
.
ChannelId
,
self
.
_security_token
.
ChannelId
))
if
chunk
.
SecurityHeader
.
TokenId
!=
self
.
_security_token
.
TokenId
:
raise
U
A
Error
(
"Wrong token id {}, expected {}"
.
format
(
raise
U
a
Error
(
"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
U
A
Error
(
"Wrong request id {}, expected {}"
.
format
(
raise
U
a
Error
(
"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
U
A
Error
(
raise
U
a
Error
(
"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
U
A
Error
(
"Unsupported message type {}"
.
format
(
header
.
MessageType
))
raise
U
a
Error
(
"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
U
A
Error
(
"{} bytes expected, {} available"
.
format
(
header
.
body_size
,
len
(
body
)))
raise
U
a
Error
(
"{} 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
U
A
Error
(
"Unsupported chunk type: {}"
.
format
(
msg
))
raise
U
a
Error
(
"Unsupported chunk type: {}"
.
format
(
msg
))
# FIXES for missing switchfield in NodeAttributes classes
...
...
opcua/ua/uatypes.py
View file @
443f8518
...
...
@@ -13,8 +13,8 @@ if sys.version_info.major > 2:
unicode
=
str
from
opcua.ua
import
status_codes
from
opcua.common.uaerrors
import
U
A
Error
from
opcua.common.uaerrors
import
U
A
StatusCodeError
from
opcua.common.uaerrors
import
U
a
Error
from
opcua.common.uaerrors
import
U
a
StatusCodeError
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
U
A
Error
(
"can not unpack unknown uatype %s"
%
uatype
)
raise
U
a
Error
(
"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
U
A
StatusCodeError
(
"{}({})"
.
format
(
self
.
doc
,
self
.
name
))
raise
U
a
StatusCodeError
(
"{}({})"
.
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
U
A
Error
(
"NodeId: Could not guess type of NodeId, set NodeIdType"
)
raise
U
a
Error
(
"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
U
A
Error
(
"Could not parse nodeid string: "
+
string
)
raise
U
a
Error
(
"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
U
A
Error
(
"Unknown NodeId encoding: "
+
str
(
nid
.
NodeIdType
))
raise
U
a
Error
(
"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
U
A
Error
(
"namespaceidx must be an int"
)
raise
U
a
Error
(
"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
U
A
Error
(
"Cannot create VariantType. VariantType must be %s > x > %s"
,
0b111111
,
25
)
raise
U
a
Error
(
"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
U
A
Error
(
"could not guess UA variable type"
)
raise
U
a
Error
(
"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
U
A
Error
(
"Could not guess UA type of {} with type {}, specify UA type"
.
format
(
val
,
type
(
val
)))
raise
U
a
Error
(
"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
)
...
...
tests/tests.py
View file @
443f8518
...
...
@@ -135,7 +135,7 @@ class Unit(unittest.TestCase):
self
.
assertEqual
(
l
,
l2
)
def
test_custom_variant
(
self
):
with
self
.
assertRaises
(
ua
.
U
A
Error
):
with
self
.
assertRaises
(
ua
.
U
a
Error
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
bad
.
get_browse_name
()
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
bad
.
set_value
(
89
)
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
bad
.
add_object
(
0
,
"0:myobj"
)
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
sub
.
unsubscribe
(
999
)
# non existing handle
sub
.
unsubscribe
(
handle1
)
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
sub
.
unsubscribe
(
handle1
)
# second try should fail
sub
.
delete
()
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
sub
.
unsubscribe
(
999
)
# non existing handle
sub
.
unsubscribe
(
handle1
)
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
sub
.
unsubscribe
(
handle1
)
# second try should fail
sub
.
delete
()
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
# FIXME: we should raise a more precise exception
result
=
o
.
call_method
(
"2:ServerMethod"
,
2.1
,
89
,
9
)
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
self
.
clt
.
bclient
.
_uasocket
.
send_request
(
request
)
def
test_objects_anonymous
(
self
):
objects
=
self
.
ro_clt
.
get_objects_node
()
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
objects
.
set_attribute
(
ua
.
AttributeIds
.
WriteMask
,
ua
.
DataValue
(
999
))
with
self
.
assertRaises
(
ua
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
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
.
U
A
StatusCodeError
):
with
self
.
assertRaises
(
ua
.
U
a
StatusCodeError
):
v_ro
.
set_value
(
9
)
self
.
assertEqual
(
v_ro
.
get_value
(),
2
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment