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
32bf12eb
Kaydet (Commit)
32bf12eb
authored
Eyl 24, 2000
tarafından
Lars Gustäbel
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Updated to final Attributes interface (patch 101632).
üst
e84bf751
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
13 deletions
+72
-13
expatreader.py
Lib/xml/sax/expatreader.py
+17
-4
xmlreader.py
Lib/xml/sax/xmlreader.py
+55
-9
No files found.
Lib/xml/sax/expatreader.py
Dosyayı görüntüle @
32bf12eb
...
...
@@ -20,6 +20,9 @@ from xml.sax._exceptions import *
from
xml.parsers
import
expat
from
xml.sax
import
xmlreader
AttributesImpl
=
xmlreader
.
AttributesImpl
AttributesNSImpl
=
xmlreader
.
AttributesNSImpl
# --- ExpatParser
class
ExpatParser
(
xmlreader
.
IncrementalParser
,
xmlreader
.
Locator
):
...
...
@@ -31,7 +34,6 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
self
.
_parser
=
None
self
.
_namespaces
=
namespaceHandling
self
.
_parsing
=
0
self
.
_attrs
=
xmlreader
.
AttributesImpl
({},
{})
# XMLReader methods
...
...
@@ -137,7 +139,7 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
# event handlers
def
start_element
(
self
,
name
,
attrs
):
self
.
_cont_handler
.
startElement
(
name
,
self
.
_attrs
)
self
.
_cont_handler
.
startElement
(
name
,
AttributesImpl
(
attrs
)
)
def
end_element
(
self
,
name
):
self
.
_cont_handler
.
endElement
(
name
)
...
...
@@ -147,12 +149,23 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
if
len
(
pair
)
==
1
:
pair
=
(
None
,
name
)
self
.
_cont_handler
.
startElementNS
(
pair
,
None
,
self
.
_attrs
)
newattrs
=
{}
for
(
aname
,
value
)
in
attrs
.
items
():
apair
=
aname
.
split
()
if
len
(
apair
)
==
1
:
apair
=
(
None
,
aname
)
else
:
apair
=
tuple
(
apair
)
newattrs
[
apair
]
=
value
self
.
_cont_handler
.
startElementNS
(
pair
,
None
,
AttributesNSImpl
(
newattrs
,
{}))
def
end_element_ns
(
self
,
name
):
pair
=
name
.
split
()
if
len
(
pair
)
==
1
:
name
=
(
None
,
name
)
pair
=
(
None
,
name
)
self
.
_cont_handler
.
endElementNS
(
pair
,
None
)
...
...
Lib/xml/sax/xmlreader.py
Dosyayı görüntüle @
32bf12eb
...
...
@@ -151,6 +151,7 @@ class IncrementalParser(XMLReader):
raise
NotImplementedError
(
"This method must be implemented!"
)
# ===== LOCATOR =====
class
Locator
:
"""Interface for associating a SAX event with a document
location. A locator object will return valid results only during
...
...
@@ -173,11 +174,15 @@ class Locator:
"Return the system identifier for the current event."
return
None
# --- AttributesImpl
# ===== ATTRIBUTESIMPL =====
class
AttributesImpl
:
def
__init__
(
self
,
attrs
,
rawnames
):
def
__init__
(
self
,
attrs
):
"""Non-NS-aware implementation.
attrs should be of the form {name : value}."""
self
.
_attrs
=
attrs
self
.
_rawnames
=
rawnames
def
getLength
(
self
):
return
len
(
self
.
_attrs
)
...
...
@@ -189,16 +194,23 @@ class AttributesImpl:
return
self
.
_attrs
[
name
]
def
getValueByQName
(
self
,
name
):
return
self
.
_attrs
[
self
.
_rawnames
[
name
]
]
return
self
.
_attrs
[
name
]
def
getNameByQName
(
self
,
name
):
return
self
.
_rawnames
[
name
]
if
not
self
.
_attrs
.
has_key
(
name
):
raise
KeyError
return
name
def
getQNameByName
(
self
,
name
):
if
not
self
.
_attrs
.
has_key
(
name
):
raise
KeyError
return
name
def
getNames
(
self
):
return
self
.
_attrs
.
keys
()
def
getQNames
(
self
):
return
self
.
_
rawname
s
.
keys
()
return
self
.
_
attr
s
.
keys
()
def
__len__
(
self
):
return
len
(
self
.
_attrs
)
...
...
@@ -216,7 +228,7 @@ class AttributesImpl:
return
self
.
_attrs
.
get
(
name
,
alternative
)
def
copy
(
self
):
return
self
.
__class__
(
self
.
_attrs
,
self
.
_rawnames
)
return
self
.
__class__
(
self
.
_attrs
)
def
items
(
self
):
return
self
.
_attrs
.
items
()
...
...
@@ -224,12 +236,46 @@ class AttributesImpl:
def
values
(
self
):
return
self
.
_attrs
.
values
()
# ===== ATTRIBUTESNSIMPL =====
class
AttributesNSImpl
(
AttributesImpl
):
def
__init__
(
self
,
attrs
,
qnames
):
"""NS-aware implementation.
attrs should be of the form {(ns_uri, lname): value, ...}.
qnames of the form {(ns_uri, lname): qname, ...}."""
self
.
_attrs
=
attrs
self
.
_qnames
=
qnames
def
getValueByQName
(
self
,
name
):
for
(
nsname
,
qname
)
in
self
.
_qnames
.
items
():
if
qname
==
name
:
return
self
.
_attrs
[
nsname
]
raise
KeyError
def
getNameByQName
(
self
,
name
):
for
(
nsname
,
qname
)
in
self
.
_qnames
.
items
():
if
qname
==
name
:
return
nsname
raise
KeyError
def
getQNameByName
(
self
,
name
):
return
self
.
_qnames
[
name
]
def
getQNames
(
self
):
return
self
.
_qnames
.
values
()
def
copy
(
self
):
return
self
.
__class__
(
self
.
_attrs
,
self
.
_qnames
)
def
_test
():
XMLReader
()
IncrementalParser
()
Locator
()
AttributesImpl
()
if
__name__
==
"__main__"
:
_test
()
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