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
466e159e
Commit
466e159e
authored
Oct 24, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small refactor xml import ext obj
parent
29fc4f64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
32 deletions
+32
-32
opcua/common/xmlimporter.py
opcua/common/xmlimporter.py
+28
-32
opcua/common/xmlparser.py
opcua/common/xmlparser.py
+4
-0
No files found.
opcua/common/xmlimporter.py
View file @
466e159e
...
...
@@ -12,14 +12,6 @@ from opcua import ua
from
opcua.common
import
xmlparser
def
to_python
(
val
,
obj
,
attname
):
if
isinstance
(
obj
,
ua
.
NodeId
)
and
attname
==
"Identifier"
:
raise
RuntimeError
(
"Error we should parse a NodeId here"
)
return
ua
.
NodeId
.
from_string
(
val
)
else
:
return
xmlparser
.
ua_type_to_python
(
val
,
obj
.
ua_types
[
attname
])
class
XmlImporter
(
object
):
def
__init__
(
self
,
server
):
...
...
@@ -200,32 +192,36 @@ class XmlImporter(object):
raise
Exception
(
"Error val should a dict"
,
name
,
val
)
else
:
for
attname
,
v
in
val
:
# tow possible values:
# either we get value directly
# or a dict if it s an object or a list
if
isinstance
(
v
,
str
):
setattr
(
ext
,
attname
,
to_python
(
v
,
ext
,
attname
))
else
:
# so we have either an object or a list...
obj2
=
getattr
(
ext
,
attname
)
if
isinstance
(
obj2
,
ua
.
NodeId
):
for
attname2
,
v2
in
v
:
if
attname2
==
"Identifier"
:
obj2
=
ua
.
NodeId
.
from_string
(
v2
)
setattr
(
ext
,
attname
,
obj2
)
break
elif
not
isinstance
(
obj2
,
ua
.
NodeId
)
and
not
hasattr
(
obj2
,
"ua_types"
):
# we probably have a list
my_list
=
[]
for
vtype
,
v2
in
v
:
my_list
.
append
(
xmlparser
.
ua_type_to_python
(
v2
,
vtype
))
setattr
(
ext
,
attname
,
my_list
)
else
:
for
attname2
,
v2
in
v
:
setattr
(
obj2
,
attname2
,
to_python
(
v2
,
obj2
,
attname2
))
setattr
(
ext
,
attname
,
obj2
)
self
.
_set_attr
(
ext
,
attname
,
v
)
return
ext
def
_set_attr
(
self
,
obj
,
attname
,
val
):
# tow possible values:
# either we get value directly
# or a dict if it s an object or a list
if
isinstance
(
val
,
str
):
pval
=
xmlparser
.
ua_type_to_python
(
val
,
obj
.
ua_types
[
attname
])
setattr
(
obj
,
attname
,
pval
)
else
:
# so we have either an object or a list...
obj2
=
getattr
(
obj
,
attname
)
if
isinstance
(
obj2
,
ua
.
NodeId
):
# NodeId representation does not follow common rules!!
for
attname2
,
v2
in
val
:
if
attname2
==
"Identifier"
:
obj2
=
ua
.
NodeId
.
from_string
(
v2
)
setattr
(
obj
,
attname
,
obj2
)
break
elif
not
isinstance
(
obj2
,
ua
.
NodeId
)
and
not
hasattr
(
obj2
,
"ua_types"
):
# we probably have a list
my_list
=
[]
for
vtype
,
v2
in
val
:
my_list
.
append
(
xmlparser
.
ua_type_to_python
(
v2
,
vtype
))
setattr
(
obj
,
attname
,
my_list
)
else
:
for
attname2
,
v2
in
val
:
self
.
_set_attr
(
obj2
,
attname2
,
v2
)
setattr
(
obj
,
attname
,
obj2
)
def
_add_variable_value
(
self
,
obj
):
"""
Returns the value for a Variable based on the objects value type.
...
...
opcua/common/xmlparser.py
View file @
466e159e
...
...
@@ -85,6 +85,10 @@ class ExtObj(object):
self
.
bodytype
=
None
self
.
body
=
{}
def
__str__
(
self
):
return
"ExtObj({}, {})"
.
format
(
self
.
objname
,
self
.
body
)
__repr__
=
__str__
class
XMLParser
(
object
):
...
...
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