Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
962c9e7f
Kaydet (Commit)
962c9e7f
authored
Eki 06, 2000
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add SAXReaderNotAvailable, and use it to distinguish between an
ImportError, and a missing driver.
üst
75698a49
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
5 deletions
+44
-5
test_sax
Lib/test/output/test_sax
+2
-1
test_sax.py
Lib/test/test_sax.py
+17
-1
__init__.py
Lib/xml/sax/__init__.py
+11
-2
_exceptions.py
Lib/xml/sax/_exceptions.py
+10
-0
expatreader.py
Lib/xml/sax/expatreader.py
+4
-1
No files found.
Lib/test/output/test_sax
Dosyayı görüntüle @
962c9e7f
...
@@ -14,6 +14,7 @@ Passed test_expat_inpsource_sysid
...
@@ -14,6 +14,7 @@ Passed test_expat_inpsource_sysid
Passed test_expat_nsattrs_empty
Passed test_expat_nsattrs_empty
Passed test_expat_nsattrs_wattr
Passed test_expat_nsattrs_wattr
Passed test_filter_basic
Passed test_filter_basic
Passed test_make_parser
Passed test_nsattrs_empty
Passed test_nsattrs_empty
Passed test_nsattrs_wattr
Passed test_nsattrs_wattr
Passed test_xmlgen_basic
Passed test_xmlgen_basic
...
@@ -22,4 +23,4 @@ Passed test_xmlgen_content_escape
...
@@ -22,4 +23,4 @@ Passed test_xmlgen_content_escape
Passed test_xmlgen_ignorable
Passed test_xmlgen_ignorable
Passed test_xmlgen_ns
Passed test_xmlgen_ns
Passed test_xmlgen_pi
Passed test_xmlgen_pi
2
3
tests, 0 failures
2
4
tests, 0 failures
Lib/test/test_sax.py
Dosyayı görüntüle @
962c9e7f
...
@@ -2,10 +2,15 @@
...
@@ -2,10 +2,15 @@
# regression test for SAX 2.0
# regression test for SAX 2.0
# $Id$
# $Id$
from
xml.sax
import
make_parser
,
ContentHandler
try
:
make_parser
()
except
xml
.
sax
.
SAXReaderNotAvailable
:
# don't try to test this module if we cannot create a parser
raise
ImportError
(
"no XML parsers available"
)
from
xml.sax.saxutils
import
XMLGenerator
,
escape
,
XMLFilterBase
from
xml.sax.saxutils
import
XMLGenerator
,
escape
,
XMLFilterBase
from
xml.sax.expatreader
import
create_parser
from
xml.sax.expatreader
import
create_parser
from
xml.sax.xmlreader
import
InputSource
,
AttributesImpl
,
AttributesNSImpl
from
xml.sax.xmlreader
import
InputSource
,
AttributesImpl
,
AttributesNSImpl
from
xml.sax.handler
import
ContentHandler
from
cStringIO
import
StringIO
from
cStringIO
import
StringIO
from
test_support
import
verbose
,
TestFailed
,
findfile
from
test_support
import
verbose
,
TestFailed
,
findfile
...
@@ -41,6 +46,17 @@ def test_escape_all():
...
@@ -41,6 +46,17 @@ def test_escape_all():
def
test_escape_extra
():
def
test_escape_extra
():
return
escape
(
"Hei p deg"
,
{
""
:
"å"
})
==
"Hei på deg"
return
escape
(
"Hei p deg"
,
{
""
:
"å"
})
==
"Hei på deg"
def
test_make_parser
():
try
:
# Creating a parser should succeed - it should fall back
# to the expatreader
p
=
make_parser
([
'xml.parsers.no_such_parser'
])
except
:
return
0
else
:
return
p
# ===== XMLGenerator
# ===== XMLGenerator
start
=
'<?xml version="1.0" encoding="iso-8859-1"?>
\n
'
start
=
'<?xml version="1.0" encoding="iso-8859-1"?>
\n
'
...
...
Lib/xml/sax/__init__.py
Dosyayı görüntüle @
962c9e7f
...
@@ -22,7 +22,8 @@ expatreader -- Driver that allows use of the Expat parser with SAX.
...
@@ -22,7 +22,8 @@ expatreader -- Driver that allows use of the Expat parser with SAX.
from
xmlreader
import
InputSource
from
xmlreader
import
InputSource
from
handler
import
ContentHandler
,
ErrorHandler
from
handler
import
ContentHandler
,
ErrorHandler
from
_exceptions
import
SAXException
,
SAXNotRecognizedException
,
\
from
_exceptions
import
SAXException
,
SAXNotRecognizedException
,
\
SAXParseException
,
SAXNotSupportedException
SAXParseException
,
SAXNotSupportedException
,
\
SAXReaderNotAvailable
def
parse
(
source
,
handler
,
errorHandler
=
ErrorHandler
()):
def
parse
(
source
,
handler
,
errorHandler
=
ErrorHandler
()):
...
@@ -74,9 +75,17 @@ def make_parser(parser_list = []):
...
@@ -74,9 +75,17 @@ def make_parser(parser_list = []):
try
:
try
:
return
_create_parser
(
parser_name
)
return
_create_parser
(
parser_name
)
except
ImportError
,
e
:
except
ImportError
,
e
:
import
sys
if
sys
.
modules
.
has_key
(
parser_name
):
# The parser module was found, but importing it
# failed unexpectedly, pass this exception through
raise
except
SAXReaderNotAvailable
:
# The parser module detected that it won't work properly,
# so try the next one
pass
pass
raise
SAX
Exception
(
"No parsers found"
,
None
)
raise
SAX
ReaderNotAvailable
(
"No parsers found"
,
None
)
# --- Internal utility methods used by make_parser
# --- Internal utility methods used by make_parser
...
...
Lib/xml/sax/_exceptions.py
Dosyayı görüntüle @
962c9e7f
...
@@ -104,3 +104,13 @@ class SAXNotSupportedException(SAXException):
...
@@ -104,3 +104,13 @@ class SAXNotSupportedException(SAXException):
perform is requested (specifically setting a state or value). SAX
perform is requested (specifically setting a state or value). SAX
applications and extensions may use this class for similar
applications and extensions may use this class for similar
purposes."""
purposes."""
# ===== SAXNOTSUPPORTEDEXCEPTION =====
class
SAXReaderNotAvailable
(
SAXNotSupportedException
):
"""Exception class for a missing driver.
An XMLReader module (driver) should raise this exception when it
is first imported, e.g. when a support module cannot be imported.
It also may be raised during parsing, e.g. if executing an external
program is not permitted."""
Lib/xml/sax/expatreader.py
Dosyayı görüntüle @
962c9e7f
...
@@ -6,7 +6,10 @@ pyexpat.__version__ == '2.22'.
...
@@ -6,7 +6,10 @@ pyexpat.__version__ == '2.22'.
version
=
"0.20"
version
=
"0.20"
from
xml.sax._exceptions
import
*
from
xml.sax._exceptions
import
*
from
xml.parsers
import
expat
try
:
from
xml.parsers
import
expat
except
ImportError
:
raise
SAXReaderNotAvailable
(
"expat not supported"
,
None
)
from
xml.sax
import
xmlreader
,
saxutils
,
handler
from
xml.sax
import
xmlreader
,
saxutils
,
handler
AttributesImpl
=
xmlreader
.
AttributesImpl
AttributesImpl
=
xmlreader
.
AttributesImpl
...
...
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