Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7fbc85c5
Commit
7fbc85c5
authored
Sep 23, 2000
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename the public interface from "pyexpat" to "xml.parsers.expat".
parent
003b9250
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
36 deletions
+34
-36
Doc/lib/libpyexpat.tex
Doc/lib/libpyexpat.tex
+24
-26
Lib/test/test_pyexpat.py
Lib/test/test_pyexpat.py
+10
-10
No files found.
Doc/lib/libpyexpat.tex
View file @
7fbc85c5
\section
{
\module
{
py
expat
}
---
Fast XML parsing using the Expat
C
library
}
\section
{
\module
{
xml.parsers.
expat
}
---
Fast XML parsing using the Expat library
}
\declaremodule
{
builtin
}{
py
expat
}
\modulesynopsis
{
An interface to the Expat XML parser.
}
\declaremodule
{
standard
}{
xml.parsers.
expat
}
\modulesynopsis
{
An interface to the Expat
non-validating
XML parser.
}
\moduleauthor
{
Paul Prescod
}{
paul@prescod.net
}
\sectionauthor
{
A.M. Kuchling
}{
amk1@bigfoot.com
}
The
\module
{
pyexpat
}
module is a Python interface to the Expat
\versionadded
{
2.0
}
The
\module
{
xml.parsers.expat
}
module is a Python interface to the Expat
non-validating XML parser.
The module provides a single extension type,
\class
{
xmlparser
}
, that
represents the current state of an XML parser. After an
...
...
@@ -14,8 +16,12 @@ represents the current state of an XML parser. After an
can be set to handler functions. When an XML document is then fed to
the parser, the handler functions are called for the character data
and markup in the XML document.
This module uses the
\module
{
pyexpat
}
\refbimodindex
{
pyexpat
}
module to
provide access to the Expat parser. Direct use of the
\module
{
pyexpat
}
module is deprecated.
The
\module
{
py
expat
}
module contains two functions:
The
\module
{
xml.parsers.
expat
}
module contains two functions:
\begin{funcdesc}
{
ErrorString
}{
errno
}
Returns an explanatory string for a given error number
\var
{
errno
}
.
...
...
@@ -103,7 +109,7 @@ containing UTF-8 encoded data will be passed to the handlers.
The following attributes contain values relating to the most recent
error encountered by an
\class
{
xmlparser
}
object, and will only have
correct values once a call to
\method
{
Parse()
}
or
\method
{
ParseFile()
}
has raised a
\exception
{
py
expat.error
}
exception.
has raised a
\exception
{
xml.parsers.
expat.error
}
exception.
\begin{datadesc}
{
ErrorByteIndex
}
Byte index at which an error occurred.
...
...
@@ -112,7 +118,7 @@ Byte index at which an error occurred.
\begin{datadesc}
{
ErrorCode
}
Numeric code specifying the problem. This value can be passed to the
\function
{
ErrorString()
}
function, or compared to one of the constants
defined in the
\module
{
pyexpat.errors
}
submodule
.
defined in the
\module
{
errors
}
object
.
\end{datadesc}
\begin{datadesc}
{
ErrorColumnNumber
}
...
...
@@ -199,14 +205,13 @@ Called for references to external entities.
\end{methoddesc}
\subsection
{
Example
\label
{
py
expat-example
}}
\subsection
{
Example
\label
{
expat-example
}}
The following program defines three handlers that just print out their
arguments.
\begin{verbatim}
import pyexpat
import xml.parsers.expat
# 3 handler functions
def start
_
element(name, attrs):
...
...
@@ -216,11 +221,11 @@ def end_element(name):
def char
_
data(data):
print 'Character data:', repr(data)
p
=py
expat.ParserCreate()
p
= xml.parsers.
expat.ParserCreate()
p.StartElementHandler = start
_
element
p.EndElementHandler
= end
_
element
p.CharacterDataHandler= char
_
data
p.EndElementHandler = end
_
element
p.CharacterDataHandler
= char
_
data
p.Parse("""<?xml version="1.0"?>
<parent id="top"><child1 name="paul">Text goes here</child1>
...
...
@@ -244,21 +249,15 @@ End element: parent
\end{verbatim}
\section
{
\module
{
pyexpat.errors
}
--- Error constants
}
\declaremodule
{
builtin
}{
pyexpat.errors
}
\modulesynopsis
{
Error constants defined for the Expat parser
}
\moduleauthor
{
Paul Prescod
}{
paul@prescod.net
}
\subsection
{
Expat error constants
\label
{
expat-errors
}}
\sectionauthor
{
A.M. Kuchling
}{
amk1@bigfoot.com
}
The following table lists the error constants in the
\module
{
pyexpat.errors
}
submodule, available once the
\refmodule
{
pyexpat
}
module has been imported.
Note that this module cannot be imported directly until
\refmodule
{
pyexpat
}
has been imported.
\code
{
errors
}
object of the
\module
{
xml.parsers.expat
}
module. These
constants are useful in interpreting some of the attributes of the
parser object after an error has occurred.
The
following constants are defined
:
The
\code
{
errors
}
object has the following attributes
:
\begin{datadesc}
{
XML
_
ERROR
_
ASYNC
_
ENTITY
}
\end{datadesc}
...
...
@@ -323,4 +322,3 @@ A reference was made to a entity which was not defined.
\begin{datadesc}
{
XML
_
ERROR
_
UNKNOWN
_
ENCODING
}
The document encoding is not supported by Expat.
\end{datadesc}
Lib/test/test_pyexpat.py
View file @
7fbc85c5
...
...
@@ -3,7 +3,7 @@
# XXX TypeErrors on calling handlers, or on bad return values from a
# handler, are obscure and unhelpful.
import
py
expat
from
xml.parsers
import
expat
class
Outputter
:
def
StartElementHandler
(
self
,
name
,
attrs
):
...
...
@@ -67,7 +67,7 @@ def confirm(ok):
print
"Not OK."
out
=
Outputter
()
parser
=
py
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
=
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
# Test getting/setting returns_unicode
parser
.
returns_unicode
=
0
;
confirm
(
parser
.
returns_unicode
==
0
)
...
...
@@ -115,28 +115,28 @@ data = '''\
parser
.
returns_unicode
=
0
try
:
parser
.
Parse
(
data
,
1
)
except
py
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
py
expat
.
ErrorString
(
parser
.
ErrorCode
)
except
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
# Try the parse again, this time producing Unicode output
parser
=
py
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
=
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
.
returns_unicode
=
1
for
name
in
HANDLER_NAMES
:
setattr
(
parser
,
name
,
getattr
(
out
,
name
))
try
:
parser
.
Parse
(
data
,
1
)
except
py
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
py
expat
.
ErrorString
(
parser
.
ErrorCode
)
except
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
# Try parsing a file
parser
=
py
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
=
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
.
returns_unicode
=
1
for
name
in
HANDLER_NAMES
:
...
...
@@ -145,8 +145,8 @@ import StringIO
file
=
StringIO
.
StringIO
(
data
)
try
:
parser
.
ParseFile
(
file
)
except
py
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
py
expat
.
ErrorString
(
parser
.
ErrorCode
)
except
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
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