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
e46d352b
Commit
e46d352b
authored
Jan 07, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raise UAStatusCodeError from StatsuCode check, move errors definition to their own files
parent
19ce5407
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
49 additions
and
60 deletions
+49
-60
opcua/common/uaerrors.py
opcua/common/uaerrors.py
+15
-0
opcua/common/utils.py
opcua/common/utils.py
+1
-2
opcua/ua/status_codes.py
opcua/ua/status_codes.py
+1
-0
opcua/ua/uaprotocol_auto.py
opcua/ua/uaprotocol_auto.py
+1
-0
opcua/ua/uatypes.py
opcua/ua/uatypes.py
+3
-2
schemas/generate_protocol_python.py
schemas/generate_protocol_python.py
+1
-0
schemas/generate_statuscode.py
schemas/generate_statuscode.py
+1
-30
schemas/uaprotocol_auto_add.py
schemas/uaprotocol_auto_add.py
+2
-2
tests/tests.py
tests/tests.py
+24
-24
No files found.
opcua/common/uaerrors.py
0 → 100644
View file @
e46d352b
"""
Define exceptions to be raised at various places in the stack
"""
class
UAError
(
RuntimeError
):
pass
class
UAStatusCodeError
(
UAError
):
pass
class
UAStringParsingError
(
UAError
):
pass
opcua/common/utils.py
View file @
e46d352b
...
...
@@ -11,8 +11,7 @@ except ImportError:
import
trollius
as
asyncio
class
UAError
(
RuntimeError
):
pass
from
opcua.common.uaerrors
import
UAError
class
ServiceError
(
UAError
):
...
...
opcua/ua/status_codes.py
View file @
e46d352b
#AUTOGENERATED!!!
from
opcua.common.uaerrors
import
UAStatusCodeError
class
StatusCodes
(
object
):
Good
=
0
...
...
opcua/ua/uaprotocol_auto.py
View file @
e46d352b
...
...
@@ -6,6 +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.ua.uatypes
import
*
from
opcua.ua.object_ids
import
ObjectIds
...
...
opcua/ua/uatypes.py
View file @
e46d352b
...
...
@@ -13,7 +13,8 @@ if sys.version_info.major > 2:
unicode
=
str
from
opcua.ua
import
status_codes
from
opcua.common.utils
import
UAError
from
opcua.common.uaerrors
import
UAError
from
opcua.common.uaerrors
import
UAStatusCodeError
logger
=
logging
.
getLogger
(
'opcua.uaprotocol'
)
...
...
@@ -310,7 +311,7 @@ class StatusCode(FrozenClass):
use is is_good() method if not exception is desired
"""
if
self
.
value
!=
0
:
raise
UAError
(
"{}({})"
.
format
(
self
.
doc
,
self
.
name
))
raise
UA
StatusCode
Error
(
"{}({})"
.
format
(
self
.
doc
,
self
.
name
))
def
is_good
(
self
):
"""
...
...
schemas/generate_protocol_python.py
View file @
e46d352b
...
...
@@ -59,6 +59,7 @@ class CodeGenerator(object):
self
.
write
(
"from enum import Enum, IntEnum"
)
self
.
write
(
""
)
self
.
write
(
"from opcua.common.utils import Buffer"
)
self
.
write
(
"from opcua.common.uaerrors import UAError"
)
self
.
write
(
"from opcua.ua.uatypes import *"
)
self
.
write
(
"from opcua.ua.object_ids import ObjectIds"
)
...
...
schemas/generate_statuscode.py
View file @
e46d352b
...
...
@@ -22,6 +22,7 @@ if __name__ == "__main__":
outputfile
=
open
(
"../opcua/ua/status_codes.py"
,
"w"
)
outputfile
.
write
(
"#AUTOGENERATED!!!
\
n
"
)
outputfile
.
write
(
"
\
n
"
)
outputfile
.
write
(
"from opcua.common.uaerrors import UAStatusCodeError
\
n
"
)
#outputfile.write("from enum import Enum\n")
outputfile
.
write
(
"
\
n
"
)
...
...
@@ -47,36 +48,6 @@ if __name__ == "__main__":
else:
return 'UnknownUaError', 'Unknown StatusCode value: {}'.format(val)
"""
)
'''
outputfile.write("class StatusCode(Enum):
\
n
")
outputfile.write(" Good = 0
\
n
")
for line in inputfile:
name, val, doc = line.split(",", maxsplit=2)
doc = doc.strip()
outputfile.write(" {} = {}
\
n
".format(name, val))
outputfile.write("""
def __new__(self, value=0):
Enum.__new__(self, value)
def to_binary(self):
return struct.pack("!I", self.value)
@staticmethod
def from_binary(data):
val = struct.unpack("!I", data.read(4))[0]
sc = StatusCode(val)
return sc
def check(self):
if self.value.name != "Good":
raise Exception(self.name)
""")
#outputfile.write("
\
n
")
#outputfile.write("
\
n
")
#outputfile.write("def CheckStatusCode(statuscode):
\
n
")
#outputfile.write(" if statuscode.data == {}
\
n
")
'''
schemas/uaprotocol_auto_add.py
View file @
e46d352b
...
...
@@ -17,10 +17,10 @@ def extensionobject_from_binary(data):
if
TypeId
.
Identifier
==
0
:
return
None
elif
TypeId
.
Identifier
not
in
ExtensionClasses
:
raise
Exception
(
"unknown ExtensionObject Type: {}"
.
format
(
TypeId
))
raise
UAError
(
"unknown ExtensionObject Type: {}"
.
format
(
TypeId
))
klass
=
ExtensionClasses
[
TypeId
.
Identifier
]
if
body
is
None
:
raise
Exception
(
"parsing ExtensionObject {} without data"
.
format
(
klass
.
__name__
))
raise
UAError
(
"parsing ExtensionObject {} without data"
.
format
(
klass
.
__name__
))
return
klass
.
from_binary
(
body
)
...
...
tests/tests.py
View file @
e46d352b
...
...
@@ -386,11 +386,11 @@ class CommonTests(object):
def
test_subscribe_events_to_wrong_node
(
self
):
sub
=
self
.
opc
.
create_subscription
(
100
,
sclt
)
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
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
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
handle
=
sub
.
subscribe_events
(
v
)
sub
.
delete
()
...
...
@@ -444,12 +444,12 @@ class CommonTests(object):
def
test_non_existing_path
(
self
):
root
=
self
.
opc
.
get_root_node
()
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
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
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
root
.
set_value
(
99
)
def
test_get_node_by_nodeid
(
self
):
...
...
@@ -578,7 +578,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
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
o2
=
objects
.
add_object
(
'ns=2;i=103;'
,
'2:AddReadObject'
)
def
test_negative_value
(
self
):
...
...
@@ -595,13 +595,13 @@ class CommonTests(object):
def
test_bad_node
(
self
):
bad
=
self
.
opc
.
get_node
(
ua
.
NodeId
(
999
,
999
))
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
bad
.
get_browse_name
()
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
bad
.
set_value
(
89
)
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
bad
.
add_object
(
0
,
"0:myobj"
)
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
bad
.
get_child
(
"0:myobj"
)
def
test_value
(
self
):
...
...
@@ -660,7 +660,7 @@ class CommonTests(object):
msclt
=
MySubHandler
()
o
=
self
.
opc
.
get_objects_node
()
sub
=
self
.
opc
.
create_subscription
(
100
,
msclt
)
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
handle1
=
sub
.
subscribe_data_change
(
o
)
# we can only subscribe to variables so this should fail
sub
.
delete
()
...
...
@@ -722,13 +722,13 @@ class CommonTests(object):
self
.
assertEqual
(
node
,
v1
)
self
.
assertEqual
(
val
,
[
5
])
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
sub
.
unsubscribe
(
999
)
# non existing handle
sub
.
unsubscribe
(
handle1
)
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
sub
.
unsubscribe
(
handle1
)
# second try should fail
sub
.
delete
()
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
sub
.
unsubscribe
(
handle1
)
# sub does not exist anymore
def
test_subscription_data_change
(
self
):
...
...
@@ -762,13 +762,13 @@ class CommonTests(object):
self
.
assertEqual
(
node
,
v1
)
self
.
assertEqual
(
val
,
[
5
])
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
sub
.
unsubscribe
(
999
)
# non existing handle
sub
.
unsubscribe
(
handle1
)
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
sub
.
unsubscribe
(
handle1
)
# second try should fail
sub
.
delete
()
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
sub
.
unsubscribe
(
handle1
)
# sub does not exist anymore
...
...
@@ -872,10 +872,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
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
# FIXME: we should raise a more precise exception
result
=
o
.
call_method
(
"2:ServerMethod"
,
2.1
,
89
,
9
)
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
result
=
o
.
call_method
(
ua
.
NodeId
(
999
),
2.1
)
# non existing method
def
test_method_array
(
self
):
...
...
@@ -965,14 +965,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
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
self
.
clt
.
bclient
.
_uasocket
.
send_request
(
request
)
def
test_objects_anonymous
(
self
):
objects
=
self
.
ro_clt
.
get_objects_node
()
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
objects
.
set_attribute
(
ua
.
AttributeIds
.
WriteMask
,
ua
.
DataValue
(
999
))
with
self
.
assertRaises
(
ua
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
f
=
objects
.
add_folder
(
3
,
'MyFolder'
)
def
test_folder_anonymous
(
self
):
...
...
@@ -980,7 +980,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
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
f2
=
f_ro
.
add_folder
(
3
,
'MyFolder2'
)
def
test_variable_anonymous
(
self
):
...
...
@@ -988,14 +988,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
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
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
.
UAError
):
with
self
.
assertRaises
(
ua
.
UA
StatusCode
Error
):
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