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
8673ab97
Kaydet (Commit)
8673ab97
authored
Şub 02, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #11159: SAX parser now supports unicode file names.
üst
6e7da152
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
6 deletions
+79
-6
test_sax.py
Lib/test/test_sax.py
+50
-0
expatreader.py
Lib/xml/sax/expatreader.py
+4
-1
saxutils.py
Lib/xml/sax/saxutils.py
+23
-5
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_sax.py
Dosyayı görüntüle @
8673ab97
...
@@ -14,6 +14,8 @@ from xml.sax.expatreader import create_parser
...
@@ -14,6 +14,8 @@ from xml.sax.expatreader import create_parser
from
xml.sax.handler
import
feature_namespaces
from
xml.sax.handler
import
feature_namespaces
from
xml.sax.xmlreader
import
InputSource
,
AttributesImpl
,
AttributesNSImpl
from
xml.sax.xmlreader
import
InputSource
,
AttributesImpl
,
AttributesNSImpl
from
cStringIO
import
StringIO
from
cStringIO
import
StringIO
import
shutil
import
test.test_support
as
support
from
test.test_support
import
findfile
,
run_unittest
from
test.test_support
import
findfile
,
run_unittest
import
unittest
import
unittest
...
@@ -384,6 +386,22 @@ class ExpatReaderTest(XmlTestBase):
...
@@ -384,6 +386,22 @@ class ExpatReaderTest(XmlTestBase):
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
@unittest.skipUnless
(
hasattr
(
support
,
'TESTFN_UNICODE'
),
'Requires unicode filenames support'
)
def
test_expat_file_unicode
(
self
):
fname
=
support
.
TESTFN_UNICODE
shutil
.
copyfile
(
TEST_XMLFILE
,
fname
)
self
.
addCleanup
(
support
.
unlink
,
fname
)
parser
=
create_parser
()
result
=
StringIO
()
xmlgen
=
XMLGenerator
(
result
)
parser
.
setContentHandler
(
xmlgen
)
parser
.
parse
(
open
(
fname
))
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
# ===== DTDHandler support
# ===== DTDHandler support
class
TestDTDHandler
:
class
TestDTDHandler
:
...
@@ -523,6 +541,22 @@ class ExpatReaderTest(XmlTestBase):
...
@@ -523,6 +541,22 @@ class ExpatReaderTest(XmlTestBase):
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
@unittest.skipUnless
(
hasattr
(
support
,
'TESTFN_UNICODE'
),
'Requires unicode filenames support'
)
def
test_expat_inpsource_sysid_unicode
(
self
):
fname
=
support
.
TESTFN_UNICODE
shutil
.
copyfile
(
TEST_XMLFILE
,
fname
)
self
.
addCleanup
(
support
.
unlink
,
fname
)
parser
=
create_parser
()
result
=
StringIO
()
xmlgen
=
XMLGenerator
(
result
)
parser
.
setContentHandler
(
xmlgen
)
parser
.
parse
(
InputSource
(
fname
))
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
def
test_expat_inpsource_stream
(
self
):
def
test_expat_inpsource_stream
(
self
):
parser
=
create_parser
()
parser
=
create_parser
()
result
=
StringIO
()
result
=
StringIO
()
...
@@ -596,6 +630,22 @@ class ExpatReaderTest(XmlTestBase):
...
@@ -596,6 +630,22 @@ class ExpatReaderTest(XmlTestBase):
self
.
assertEqual
(
parser
.
getSystemId
(),
TEST_XMLFILE
)
self
.
assertEqual
(
parser
.
getSystemId
(),
TEST_XMLFILE
)
self
.
assertEqual
(
parser
.
getPublicId
(),
None
)
self
.
assertEqual
(
parser
.
getPublicId
(),
None
)
@unittest.skipUnless
(
hasattr
(
support
,
'TESTFN_UNICODE'
),
'Requires unicode filenames support'
)
def
test_expat_locator_withinfo_unicode
(
self
):
fname
=
support
.
TESTFN_UNICODE
shutil
.
copyfile
(
TEST_XMLFILE
,
fname
)
self
.
addCleanup
(
support
.
unlink
,
fname
)
result
=
StringIO
()
xmlgen
=
XMLGenerator
(
result
)
parser
=
create_parser
()
parser
.
setContentHandler
(
xmlgen
)
parser
.
parse
(
fname
)
self
.
assertEqual
(
parser
.
getSystemId
(),
fname
)
self
.
assertEqual
(
parser
.
getPublicId
(),
None
)
# ===========================================================================
# ===========================================================================
#
#
...
...
Lib/xml/sax/expatreader.py
Dosyayı görüntüle @
8673ab97
...
@@ -108,7 +108,10 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
...
@@ -108,7 +108,10 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
def
prepareParser
(
self
,
source
):
def
prepareParser
(
self
,
source
):
if
source
.
getSystemId
()
is
not
None
:
if
source
.
getSystemId
()
is
not
None
:
self
.
_parser
.
SetBase
(
source
.
getSystemId
())
base
=
source
.
getSystemId
()
if
isinstance
(
base
,
unicode
):
base
=
base
.
encode
(
'utf-8'
)
self
.
_parser
.
SetBase
(
base
)
# Redefined setContentHandler to allow changing handlers during parsing
# Redefined setContentHandler to allow changing handlers during parsing
...
...
Lib/xml/sax/saxutils.py
Dosyayı görüntüle @
8673ab97
...
@@ -4,6 +4,7 @@ convenience of application and driver writers.
...
@@ -4,6 +4,7 @@ convenience of application and driver writers.
"""
"""
import
os
,
urlparse
,
urllib
,
types
import
os
,
urlparse
,
urllib
,
types
import
sys
import
handler
import
handler
import
xmlreader
import
xmlreader
...
@@ -293,14 +294,31 @@ def prepare_input_source(source, base = ""):
...
@@ -293,14 +294,31 @@ def prepare_input_source(source, base = ""):
source
.
setSystemId
(
f
.
name
)
source
.
setSystemId
(
f
.
name
)
if
source
.
getByteStream
()
is
None
:
if
source
.
getByteStream
()
is
None
:
sysid
=
source
.
getSystemId
()
try
:
basehead
=
os
.
path
.
dirname
(
os
.
path
.
normpath
(
base
))
sysid
=
source
.
getSystemId
()
sysidfilename
=
os
.
path
.
join
(
basehead
,
sysid
)
basehead
=
os
.
path
.
dirname
(
os
.
path
.
normpath
(
base
))
if
os
.
path
.
isfile
(
sysidfilename
):
encoding
=
sys
.
getfilesystemencoding
()
if
isinstance
(
sysid
,
unicode
):
if
not
isinstance
(
basehead
,
unicode
):
try
:
basehead
=
basehead
.
decode
(
encoding
)
except
UnicodeDecodeError
:
sysid
=
sysid
.
encode
(
encoding
)
else
:
if
isinstance
(
basehead
,
unicode
):
try
:
sysid
=
sysid
.
decode
(
encoding
)
except
UnicodeDecodeError
:
basehead
=
basehead
.
encode
(
encoding
)
sysidfilename
=
os
.
path
.
join
(
basehead
,
sysid
)
isfile
=
os
.
path
.
isfile
(
sysidfilename
)
except
UnicodeError
:
isfile
=
False
if
isfile
:
source
.
setSystemId
(
sysidfilename
)
source
.
setSystemId
(
sysidfilename
)
f
=
open
(
sysidfilename
,
"rb"
)
f
=
open
(
sysidfilename
,
"rb"
)
else
:
else
:
source
.
setSystemId
(
urlparse
.
urljoin
(
base
,
s
ysid
))
source
.
setSystemId
(
urlparse
.
urljoin
(
base
,
s
ource
.
getSystemId
()
))
f
=
urllib
.
urlopen
(
source
.
getSystemId
())
f
=
urllib
.
urlopen
(
source
.
getSystemId
())
source
.
setByteStream
(
f
)
source
.
setByteStream
(
f
)
...
...
Misc/NEWS
Dosyayı görüntüle @
8673ab97
...
@@ -202,6 +202,8 @@ Core and Builtins
...
@@ -202,6 +202,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #11159: SAX parser now supports unicode file names.
- Issue #6972: The zipfile module no longer overwrites files outside of
- Issue #6972: The zipfile module no longer overwrites files outside of
its destination path when extracting malicious zip files.
its destination path when extracting malicious zip files.
...
...
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