Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xml_marshaller
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
0
Merge Requests
0
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
nexedi
xml_marshaller
Commits
20736bda
Commit
20736bda
authored
Jul 20, 2010
by
Nicolas Delaby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support of set type
parent
d9034195
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletion
+33
-1
xml_marshaller/xml_marshaller.py
xml_marshaller/xml_marshaller.py
+33
-1
No files found.
xml_marshaller/xml_marshaller.py
View file @
20736bda
...
...
@@ -57,6 +57,7 @@ class Marshaller(object):
self
.
tag_code
=
E
.
code
self
.
tag_none
=
E
.
none
self
.
tag_instance
=
E
.
object
self
.
tag_set
=
E
.
set
# The four basic functions that form the caller's interface
def
dump
(
self
,
value
,
file
):
...
...
@@ -189,6 +190,16 @@ class Marshaller(object):
xml_tree
.
append
(
self
.
_marshal
(
v
,
kw
))
return
xml_tree
def
m_set
(
self
,
value
,
kw
):
kw
[
'id'
]
+=
1
i
=
str
(
kw
[
'id'
])
kw
[
str
(
id
(
value
))]
=
i
kw
[
i
]
=
value
xml_tree
=
self
.
tag_set
(
id
=
'i%s'
%
i
)
for
elem
in
value
:
xml_tree
.
append
(
self
.
_marshal
(
elem
,
kw
))
return
xml_tree
# Python 2.2 renames dictionary to dict.
def
m_dict
(
self
,
value
,
kw
):
return
self
.
m_dictionary
(
value
,
kw
)
...
...
@@ -250,6 +261,7 @@ class Marshaller(object):
TUPLE
=
{}
LIST
=
{}
DICT
=
{}
SET
=
{}
class
Unmarshaller
(
ElementTreeContentHandler
):
# This dictionary maps element names to the names of starting and ending
...
...
@@ -270,7 +282,8 @@ class Unmarshaller(ElementTreeContentHandler):
'reference'
:
(
'um_start_reference'
,
None
),
'code'
:
(
'um_start_code'
,
'um_end_code'
),
'none'
:
(
'um_start_none'
,
'um_end_none'
),
'object'
:
(
'um_start_instance'
,
'um_end_instance'
)
'object'
:
(
'um_start_instance'
,
'um_end_instance'
),
'set'
:
(
'um_start_set'
,
'um_end_set'
),
}
def
__init__
(
self
):
...
...
@@ -476,6 +489,14 @@ class Unmarshaller(ElementTreeContentHandler):
self
.
kw
[
id
]
=
L
self
.
data_stack
.
append
(
L
)
def
um_start_set
(
self
,
name
,
attrs
):
self
.
data_stack
.
append
(
SET
)
S
=
set
()
if
'id'
in
attrs
:
id
=
attrs
[
'id'
]
self
.
kw
[
id
]
=
S
self
.
data_stack
.
append
(
S
)
def
um_end_list
(
self
,
name
):
ds
=
self
.
data_stack
for
index
in
range
(
len
(
ds
)
-
1
,
-
1
,
-
1
):
...
...
@@ -486,6 +507,16 @@ class Unmarshaller(ElementTreeContentHandler):
L
[:]
=
ds
[
index
+
2
:
len
(
ds
)]
ds
[
index
:]
=
[
L
]
def
um_end_set
(
self
,
name
):
ds
=
self
.
data_stack
for
index
in
range
(
len
(
ds
)
-
1
,
-
1
,
-
1
):
if
ds
[
index
]
is
SET
:
break
assert
index
!=
-
1
S
=
ds
[
index
+
1
]
[
S
.
add
(
item
)
for
item
in
ds
[
index
+
2
:
len
(
ds
)]]
ds
[
index
:]
=
[
S
]
def
um_start_tuple
(
self
,
name
,
attrs
):
self
.
data_stack
.
append
(
TUPLE
)
...
...
@@ -611,6 +642,7 @@ def runtests(namespace_uri=None):
[
'alpha'
,
'beta'
,
'gamma'
],
{
'key'
:
'value'
,
1
:
2
},
'éàù^ç'
.
decode
(
'utf-8'
),
set
((
'a'
,
1
,)),
]
if
namespace_uri
:
test
(
load
,
loads
,
dump_ns
,
dumps_ns
,
L
)
...
...
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