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
a5981724
Commit
a5981724
authored
Dec 12, 2009
by
Nicolas Delaby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* rename file variable to file_object
* use expatreader to parse xml trees for better performances
parent
022e2bc0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
xml_marshaller/xml_marshaller.py
xml_marshaller/xml_marshaller.py
+10
-10
No files found.
xml_marshaller/xml_marshaller.py
View file @
a5981724
...
...
@@ -11,8 +11,8 @@ Patched by Nicolas Delaby nicolas@nexedi.com to support namespaces
# dumps(value), loads(string)
from
types
import
ClassType
import
sys
from
xml.sax
import
make_parser
from
xml.sax.saxutils
import
escape
,
unescape
import
lxml.sax
from
lxml.sax
import
ElementTreeContentHandler
from
lxml
import
etree
from
lxml.builder
import
ElementMaker
...
...
@@ -293,31 +293,31 @@ class Unmarshaller(ElementTreeContentHandler):
self
.
kw
=
{}
self
.
accumulating_chars
=
0
def
load
(
self
,
file
):
def
load
(
self
,
file
_object
):
"Unmarshal one value, reading it from a file-like object"
# Instantiate a new object; unmarshalling isn't thread-safe
# because it modifies attributes on the object.
m
=
self
.
__class__
()
return
m
.
_load
(
file
)
return
m
.
_load
(
file
_object
)
def
loads
(
self
,
string
):
"Unmarshal one value from a string"
# Instantiate a new object; unmarshalling isn't thread-safe
# because it modifies attributes on the object.
m
=
self
.
__class__
()
file
=
StringIO
(
string
)
return
m
.
_load
(
file
)
file
_object
=
StringIO
(
string
)
return
m
.
_load
(
file
_object
)
# Basic unmarshalling routine; it creates a SAX XML parser,
# registers self as the SAX handler, parses it, and returns
# the only thing on the data stack.
def
_load
(
self
,
file
):
def
_load
(
self
,
file
_object
):
"Read one value from the open file"
lxml
.
sax
.
saxify
(
lxml
.
etree
.
parse
(
file
),
self
)
#p = saxexts.make_parser(
)
#p.setDocum
entHandler(self)
#p.parseFile(file
)
parser
=
make_parser
(
)
parser
.
setFeature
(
'http://xml.org/sax/features/namespaces'
,
True
)
parser
.
setCont
entHandler
(
self
)
parser
.
parse
(
file_object
)
assert
len
(
self
.
data_stack
)
==
1
# leave the instance in a steady state
result
=
self
.
data_stack
[
0
]
...
...
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