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
a12adfe4
Kaydet (Commit)
a12adfe4
authored
Eyl 18, 2000
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Reduce the number of imports needed.
Make the code conform better to the Python style guide.
üst
480abc27
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
20 deletions
+23
-20
saxutils.py
Lib/xml/sax/saxutils.py
+23
-20
No files found.
Lib/xml/sax/saxutils.py
Dosyayı görüntüle @
a12adfe4
"""
A library of useful helper classes to the
sax
classes, for the
"""
\
A library of useful helper classes to the
SAX
classes, for the
convenience of application and driver writers.
$Id$
"""
import
types
,
string
,
sys
import
handler
def
escape
(
data
,
entities
=
{}):
def
escape
(
data
,
entities
=
{}):
"""Escape &, <, and > in a string of data.
You can escape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
data
=
string
.
replace
(
data
,
"&"
,
"&"
)
data
=
string
.
replace
(
data
,
"<"
,
"<"
)
data
=
string
.
replace
(
data
,
">"
,
">"
)
data
=
data
.
replace
(
"&"
,
"&"
)
data
=
data
.
replace
(
"<"
,
"<"
)
data
=
data
.
replace
(
">"
,
">"
)
for
chars
,
entity
in
entities
.
items
():
data
=
string
.
replace
(
data
,
chars
,
entity
)
data
=
data
.
replace
(
chars
,
entity
)
return
data
class
XMLGenerator
(
handler
.
ContentHandler
):
def
__init__
(
self
,
out
=
sys
.
stdout
):
def
__init__
(
self
,
out
=
None
):
if
out
is
None
:
import
sys
out
=
sys
.
stdout
handler
.
ContentHandler
.
__init__
(
self
)
self
.
_out
=
out
# ContentHandler methods
def
startDocument
(
self
):
self
.
_out
.
write
(
'<?xml version="1.0" encoding="iso-8859-1"?>
\n
'
)
...
...
@@ -39,9 +42,9 @@ class XMLGenerator(handler.ContentHandler):
pass
def
startElement
(
self
,
name
,
attrs
):
if
type
(
name
)
==
type
(()):
uri
,
localname
,
prefix
=
name
name
=
"
%
s:
%
s"
%
(
prefix
,
localname
)
if
type
(
name
)
is
type
(()):
uri
,
localname
,
prefix
=
name
name
=
"
%
s:
%
s"
%
(
prefix
,
localname
)
self
.
_out
.
write
(
'<'
+
name
)
for
(
name
,
value
)
in
attrs
.
items
():
self
.
_out
.
write
(
'
%
s="
%
s"'
%
(
name
,
escape
(
value
)))
...
...
@@ -56,10 +59,11 @@ class XMLGenerator(handler.ContentHandler):
def
ignorableWhitespace
(
self
,
content
):
self
.
_out
.
write
(
content
)
def
processingInstruction
(
self
,
target
,
data
):
self
.
_out
.
write
(
'<?
%
s
%
s?>'
%
(
target
,
data
))
class
XMLFilterBase
:
"""This class is designed to sit between an XMLReader and the
client application's event handlers. By default, it does nothing
...
...
@@ -80,10 +84,10 @@ class XMLFilterBase:
self
.
_err_handler
.
warning
(
exception
)
# ContentHandler methods
def
setDocumentLocator
(
self
,
locator
):
self
.
_cont_handler
.
setDocumentLocator
(
locator
)
def
startDocument
(
self
):
self
.
_cont_handler
.
startDocument
()
...
...
@@ -138,7 +142,7 @@ class XMLFilterBase:
def
setLocale
(
self
,
locale
):
self
.
_parent
.
setLocale
(
locale
)
def
getFeature
(
self
,
name
):
return
self
.
_parent
.
getFeature
(
name
)
...
...
@@ -150,4 +154,3 @@ class XMLFilterBase:
def
setProperty
(
self
,
name
,
value
):
self
.
_parent
.
setProperty
(
name
,
value
)
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