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
Show 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
}
---
\section
{
\module
{
xml.parsers.
expat
}
---
Fast XML parsing using the Expat
C
library
}
Fast XML parsing using the Expat library
}
\declaremodule
{
builtin
}{
py
expat
}
\declaremodule
{
standard
}{
xml.parsers.
expat
}
\modulesynopsis
{
An interface to the Expat XML parser.
}
\modulesynopsis
{
An interface to the Expat
non-validating
XML parser.
}
\moduleauthor
{
Paul Prescod
}{
paul@prescod.net
}
\moduleauthor
{
Paul Prescod
}{
paul@prescod.net
}
\sectionauthor
{
A.M. Kuchling
}{
amk1@bigfoot.com
}
\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.
non-validating XML parser.
The module provides a single extension type,
\class
{
xmlparser
}
, that
The module provides a single extension type,
\class
{
xmlparser
}
, that
represents the current state of an XML parser. After an
represents the current state of an XML parser. After an
...
@@ -15,7 +17,11 @@ can be set to handler functions. When an XML document is then fed to
...
@@ -15,7 +17,11 @@ 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
the parser, the handler functions are called for the character data
and markup in the XML document.
and markup in the XML document.
The
\module
{
pyexpat
}
module contains two functions:
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
{
xml.parsers.expat
}
module contains two functions:
\begin{funcdesc}
{
ErrorString
}{
errno
}
\begin{funcdesc}
{
ErrorString
}{
errno
}
Returns an explanatory string for a given error number
\var
{
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.
...
@@ -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
The following attributes contain values relating to the most recent
error encountered by an
\class
{
xmlparser
}
object, and will only have
error encountered by an
\class
{
xmlparser
}
object, and will only have
correct values once a call to
\method
{
Parse()
}
or
\method
{
ParseFile()
}
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
}
\begin{datadesc}
{
ErrorByteIndex
}
Byte index at which an error occurred.
Byte index at which an error occurred.
...
@@ -112,7 +118,7 @@ Byte index at which an error occurred.
...
@@ -112,7 +118,7 @@ Byte index at which an error occurred.
\begin{datadesc}
{
ErrorCode
}
\begin{datadesc}
{
ErrorCode
}
Numeric code specifying the problem. This value can be passed to the
Numeric code specifying the problem. This value can be passed to the
\function
{
ErrorString()
}
function, or compared to one of the constants
\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}
\end{datadesc}
\begin{datadesc}
{
ErrorColumnNumber
}
\begin{datadesc}
{
ErrorColumnNumber
}
...
@@ -199,14 +205,13 @@ Called for references to external entities.
...
@@ -199,14 +205,13 @@ Called for references to external entities.
\end{methoddesc}
\end{methoddesc}
\subsection
{
Example
\label
{
py
expat-example
}}
\subsection
{
Example
\label
{
expat-example
}}
The following program defines three handlers that just print out their
The following program defines three handlers that just print out their
arguments.
arguments.
\begin{verbatim}
\begin{verbatim}
import xml.parsers.expat
import pyexpat
# 3 handler functions
# 3 handler functions
def start
_
element(name, attrs):
def start
_
element(name, attrs):
...
@@ -216,11 +221,11 @@ def end_element(name):
...
@@ -216,11 +221,11 @@ def end_element(name):
def char
_
data(data):
def char
_
data(data):
print 'Character data:', repr(data)
print 'Character data:', repr(data)
p
=py
expat.ParserCreate()
p
= xml.parsers.
expat.ParserCreate()
p.StartElementHandler = start
_
element
p.StartElementHandler = start
_
element
p.EndElementHandler = end
_
element
p.EndElementHandler = end
_
element
p.CharacterDataHandler= char
_
data
p.CharacterDataHandler
= char
_
data
p.Parse("""<?xml version="1.0"?>
p.Parse("""<?xml version="1.0"?>
<parent id="top"><child1 name="paul">Text goes here</child1>
<parent id="top"><child1 name="paul">Text goes here</child1>
...
@@ -244,21 +249,15 @@ End element: parent
...
@@ -244,21 +249,15 @@ End element: parent
\end{verbatim}
\end{verbatim}
\section
{
\module
{
pyexpat.errors
}
--- Error constants
}
\subsection
{
Expat error constants
\label
{
expat-errors
}}
\declaremodule
{
builtin
}{
pyexpat.errors
}
\modulesynopsis
{
Error constants defined for the Expat parser
}
\moduleauthor
{
Paul Prescod
}{
paul@prescod.net
}
\sectionauthor
{
A.M. Kuchling
}{
amk1@bigfoot.com
}
\sectionauthor
{
A.M. Kuchling
}{
amk1@bigfoot.com
}
The following table lists the error constants in the
The following table lists the error constants in the
\module
{
pyexpat.errors
}
submodule, available once the
\code
{
errors
}
object of the
\module
{
xml.parsers.expat
}
module. These
\refmodule
{
pyexpat
}
module has been imported.
constants are useful in interpreting some of the attributes of the
parser object after an error has occurred.
Note that this module cannot be imported directly until
\refmodule
{
pyexpat
}
has been imported.
The
following constants are defined
:
The
\code
{
errors
}
object has the following attributes
:
\begin{datadesc}
{
XML
_
ERROR
_
ASYNC
_
ENTITY
}
\begin{datadesc}
{
XML
_
ERROR
_
ASYNC
_
ENTITY
}
\end{datadesc}
\end{datadesc}
...
@@ -323,4 +322,3 @@ A reference was made to a entity which was not defined.
...
@@ -323,4 +322,3 @@ A reference was made to a entity which was not defined.
\begin{datadesc}
{
XML
_
ERROR
_
UNKNOWN
_
ENCODING
}
\begin{datadesc}
{
XML
_
ERROR
_
UNKNOWN
_
ENCODING
}
The document encoding is not supported by Expat.
The document encoding is not supported by Expat.
\end{datadesc}
\end{datadesc}
Lib/test/test_pyexpat.py
View file @
7fbc85c5
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
# XXX TypeErrors on calling handlers, or on bad return values from a
# XXX TypeErrors on calling handlers, or on bad return values from a
# handler, are obscure and unhelpful.
# handler, are obscure and unhelpful.
import
py
expat
from
xml.parsers
import
expat
class
Outputter
:
class
Outputter
:
def
StartElementHandler
(
self
,
name
,
attrs
):
def
StartElementHandler
(
self
,
name
,
attrs
):
...
@@ -67,7 +67,7 @@ def confirm(ok):
...
@@ -67,7 +67,7 @@ def confirm(ok):
print
"Not OK."
print
"Not OK."
out
=
Outputter
()
out
=
Outputter
()
parser
=
py
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
=
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
# Test getting/setting returns_unicode
# Test getting/setting returns_unicode
parser
.
returns_unicode
=
0
;
confirm
(
parser
.
returns_unicode
==
0
)
parser
.
returns_unicode
=
0
;
confirm
(
parser
.
returns_unicode
==
0
)
...
@@ -115,28 +115,28 @@ data = '''\
...
@@ -115,28 +115,28 @@ data = '''\
parser
.
returns_unicode
=
0
parser
.
returns_unicode
=
0
try
:
try
:
parser
.
Parse
(
data
,
1
)
parser
.
Parse
(
data
,
1
)
except
py
expat
.
error
:
except
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
py
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Error'
,
parser
.
ErrorCode
,
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
print
'** Byte'
,
parser
.
ErrorByteIndex
# Try the parse again, this time producing Unicode output
# Try the parse again, this time producing Unicode output
parser
=
py
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
=
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
.
returns_unicode
=
1
parser
.
returns_unicode
=
1
for
name
in
HANDLER_NAMES
:
for
name
in
HANDLER_NAMES
:
setattr
(
parser
,
name
,
getattr
(
out
,
name
))
setattr
(
parser
,
name
,
getattr
(
out
,
name
))
try
:
try
:
parser
.
Parse
(
data
,
1
)
parser
.
Parse
(
data
,
1
)
except
py
expat
.
error
:
except
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
py
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Error'
,
parser
.
ErrorCode
,
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
print
'** Byte'
,
parser
.
ErrorByteIndex
# Try parsing a file
# Try parsing a file
parser
=
py
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
=
expat
.
ParserCreate
(
namespace_separator
=
'!'
)
parser
.
returns_unicode
=
1
parser
.
returns_unicode
=
1
for
name
in
HANDLER_NAMES
:
for
name
in
HANDLER_NAMES
:
...
@@ -145,8 +145,8 @@ import StringIO
...
@@ -145,8 +145,8 @@ import StringIO
file
=
StringIO
.
StringIO
(
data
)
file
=
StringIO
.
StringIO
(
data
)
try
:
try
:
parser
.
ParseFile
(
file
)
parser
.
ParseFile
(
file
)
except
py
expat
.
error
:
except
expat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
py
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Error'
,
parser
.
ErrorCode
,
expat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
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