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
b0b44829
Commit
b0b44829
authored
Oct 10, 2016
by
mvdweert
Committed by
ORD
Oct 14, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate browsename namespace when importing to correct index
parent
ae98a12d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
7 deletions
+72
-7
opcua/common/xmlparser.py
opcua/common/xmlparser.py
+15
-3
tests/custom_nodesns.xml
tests/custom_nodesns.xml
+36
-0
tests/tests_xml.py
tests/tests_xml.py
+21
-4
No files found.
opcua/common/xmlparser.py
View file @
b0b44829
...
...
@@ -44,8 +44,8 @@ class NodeData(object):
# referencetype
self
.
inversename
=
""
self
.
abstract
=
False
self
.
symmetric
=
False
self
.
abstract
=
False
self
.
symmetric
=
False
# datatype
self
.
definition
=
[]
...
...
@@ -204,6 +204,18 @@ class XMLParser(object):
result
=
"ns={};i={}"
.
format
(
ns_server
[
0
],
node_id
)
return
result
def
_parse_bname
(
self
,
bname
):
"""
Parse a browsename and correct the namespace index.
"""
if
bname
.
find
(
':'
)
!=
-
1
:
browse_ns
,
browse_name
=
bname
.
split
(
':'
)
if
browse_ns
:
ns_server
=
self
.
namespaces
.
get
(
int
(
browse_ns
),
None
)
if
ns_server
:
return
'%d:%s'
%
(
ns_server
[
0
],
browse_name
)
return
bname
def
_parse_node
(
self
,
name
,
child
):
"""
Parse a XML node and create a NodeData object.
...
...
@@ -223,7 +235,7 @@ class XMLParser(object):
obj
.
nodeid
=
self
.
_get_node_id
(
val
)
print
(
"PARSING"
,
obj
.
nodeid
)
elif
key
==
"BrowseName"
:
obj
.
browsename
=
val
obj
.
browsename
=
self
.
_parse_bname
(
val
)
elif
key
==
"SymbolicName"
:
obj
.
symname
=
val
elif
key
==
"ParentNodeId"
:
...
...
tests/custom_nodesns.xml
0 → 100644
View file @
b0b44829
<?xml version="1.0" encoding="utf-8"?>
<UANodeSet
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
Version=
"1.02"
LastModified=
"2013-03-06T05:36:44.0862658Z"
xmlns=
"http://opcfoundation.org/UA/2011/03/UANodeSet.xsd"
xmlns:uax=
"http://opcfoundation.org/UA/2008/02/Types.xsd"
>
<NamespaceUris>
<Uri>
http://examples.freeopcua.github.io/
</Uri>
</NamespaceUris>
<Aliases>
<Alias
Alias=
"LocalizedText"
>
i=21
</Alias>
<Alias
Alias=
"HasModellingRule"
>
i=37
</Alias>
<Alias
Alias=
"HasTypeDefinition"
>
i=40
</Alias>
<Alias
Alias=
"HasSubtype"
>
i=45
</Alias>
<Alias
Alias=
"HasProperty"
>
i=46
</Alias>
<Alias
Alias=
"MyCustomString"
>
ns=1;i=3008
</Alias>
<Alias
Alias=
"MyEnum"
>
ns=1;i=3010
</Alias>
<Alias
Alias=
"MyEnumVal"
>
ns=1;i=3011
</Alias>
</Aliases>
<UAObject
NodeId=
"ns=1;i=5002"
BrowseName=
"1:MyBaseObject"
>
<DisplayName>
MyBaseObject
</DisplayName>
<References>
<Reference
ReferenceType=
"Organizes"
IsForward=
"false"
>
i=85
</Reference>
<Reference
ReferenceType=
"HasComponent"
>
ns=1;i=6001
</Reference>
</References>
</UAObject>
<UAVariable
DataType=
"Int32"
ParentNodeId=
"ns=1;i=5002"
NodeId=
"ns=1;i=6001"
BrowseName=
"1:MyVar"
>
<DisplayName>
MyVar
</DisplayName>
<References>
<Reference
ReferenceType=
"HasTypeDefinition"
>
i=63
</Reference>
<Reference
ReferenceType=
"HasComponent"
IsForward=
"false"
>
ns=1;i=5002
</Reference>
</References>
<Value>
<uax:Int32>
0
</uax:Int32>
</Value>
</UAVariable>
</UANodeSet>
tests/tests_xml.py
View file @
b0b44829
...
...
@@ -35,6 +35,22 @@ class XmlTests(object):
input_arg
=
o
.
get_data_value
().
Value
.
Value
[
0
]
self
.
assertEqual
(
input_arg
.
Name
,
'Context'
)
def
test_xml_import_additional_ns
(
self
):
self
.
srv
.
register_namespace
(
'http://placeholder.toincrease.nsindex'
)
# if not already shift the new namespaces
# "tests/custom_nodes.xml" isn't created with namespaces in mind, provide new test file
self
.
srv
.
import_xml
(
"tests/custom_nodesns.xml"
)
# the ns=1 in to file now should be mapped to ns=2
ns
=
self
.
srv
.
get_namespace_index
(
"http://examples.freeopcua.github.io/"
)
o
=
self
.
opc
.
get_objects_node
()
o2
=
o
.
get_child
([
"%d:MyBaseObject"
%
ns
])
self
.
assertIsNotNone
(
o2
)
v1
=
o
.
get_child
([
"%d:MyBaseObject"
%
ns
,
"%d:MyVar"
%
ns
])
self
.
assertIsNotNone
(
v1
)
def
test_xml_method
(
self
):
o
=
self
.
opc
.
nodes
.
objects
.
add_object
(
2
,
"xmlexportobj"
)
m
=
o
.
add_method
(
2
,
"callme"
,
func
,
[
ua
.
VariantType
.
Double
,
ua
.
VariantType
.
String
],
[
ua
.
VariantType
.
Float
])
...
...
@@ -49,8 +65,8 @@ class XmlTests(object):
desc
=
b"My nce description"
val
[
0
].
Description
=
ua
.
LocalizedText
(
desc
)
inputs
.
set_value
(
val
)
#get all nodes and export
#
get all nodes and export
nodes
=
[
o
,
m
]
nodes
.
extend
(
m
.
get_children
())
self
.
opc
.
export_xml
(
nodes
,
"export.xml"
)
...
...
@@ -58,10 +74,11 @@ class XmlTests(object):
self
.
opc
.
delete_nodes
(
nodes
)
self
.
opc
.
import_xml
(
"export.xml"
)
# now see if our nodes are here
val
=
inputs
.
get_value
()
self
.
assertEqual
(
len
(
val
),
2
)
self
.
assertEqual
(
val
[
0
].
ArrayDimensions
,
[
2
,
2
])
self
.
assertEqual
(
val
[
0
].
Description
.
Text
,
desc
)
self
.
assertEqual
(
v
.
get_value
(),
6.78
)
...
...
@@ -74,7 +91,7 @@ class XmlTests(object):
self
.
assertEqual
(
a2
.
get_value
(),
[[]])
self
.
assertEqual
(
a2
.
get_data_type
(),
ua
.
NodeId
(
ua
.
ObjectIds
.
ByteString
))
self
.
assertIn
(
a2
.
get_value_rank
(),
(
0
,
2
))
self
.
assertEqual
(
a2
.
get_attribute
(
ua
.
AttributeIds
.
ArrayDimensions
).
Value
.
Value
,
[
1
,
0
])
self
.
assertEqual
(
a2
.
get_attribute
(
ua
.
AttributeIds
.
ArrayDimensions
).
Value
.
Value
,
[
1
,
0
])
def
test_export_import_ext_obj
(
self
):
arg
=
ua
.
Argument
()
...
...
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