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
3203efb5
Kaydet (Commit)
3203efb5
authored
Agu 26, 2004
tarafından
Dave Cole
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1014930. Expose current parse location to XMLParser.
üst
0d58e2be
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
0 deletions
+76
-0
libpyexpat.tex
Doc/lib/libpyexpat.tex
+20
-0
test_pyexpat.py
Lib/test/test_pyexpat.py
+39
-0
NEWS
Misc/NEWS
+3
-0
pyexpat.c
Modules/pyexpat.c
+14
-0
No files found.
Doc/lib/libpyexpat.tex
Dosyayı görüntüle @
3203efb5
...
@@ -257,6 +257,26 @@ Column number at which an error occurred.
...
@@ -257,6 +257,26 @@ Column number at which an error occurred.
Line number at which an error occurred.
Line number at which an error occurred.
\end{memberdesc}
\end{memberdesc}
The following attributes contain values relating to the current parse
location in an
\class
{
xmlparser
}
object. During a callback reporting
a parse event they indicate the location of the first of the sequence
of characters that generated the event. When called outside of a
callback, the position indicated will be just past the last parse
event (regardless of whether there was an associated callback).
\versionadded
{
2.4
}
\begin{memberdesc}
[xmlparser]
{
CurrentByteIndex
}
Current byte index in the parser input.
\end{memberdesc}
\begin{memberdesc}
[xmlparser]
{
CurrentColumnNumber
}
Current column number in the parser input.
\end{memberdesc}
\begin{memberdesc}
[xmlparser]
{
CurrentLineNumber
}
Current line number in the parser input.
\end{memberdesc}
Here is the list of handlers that can be set. To set a handler on an
Here is the list of handlers that can be set. To set a handler on an
\class
{
xmlparser
}
object
\var
{
o
}
, use
\class
{
xmlparser
}
object
\var
{
o
}
, use
\code
{
\var
{
o
}
.
\var
{
handlername
}
=
\var
{
func
}}
.
\var
{
handlername
}
must
\code
{
\var
{
o
}
.
\var
{
handlername
}
=
\var
{
func
}}
.
\var
{
handlername
}
must
...
...
Lib/test/test_pyexpat.py
Dosyayı görüntüle @
3203efb5
...
@@ -326,3 +326,42 @@ except RuntimeError, e:
...
@@ -326,3 +326,42 @@ except RuntimeError, e:
print
"Expected RuntimeError for element 'a'; found
%
r"
%
e
.
args
[
0
]
print
"Expected RuntimeError for element 'a'; found
%
r"
%
e
.
args
[
0
]
else
:
else
:
print
"Expected RuntimeError for 'a'"
print
"Expected RuntimeError for 'a'"
# Test Current* members:
class
PositionTest
:
def
__init__
(
self
,
expected_list
,
parser
):
self
.
parser
=
parser
self
.
parser
.
StartElementHandler
=
self
.
StartElementHandler
self
.
parser
.
EndElementHandler
=
self
.
EndElementHandler
self
.
expected_list
=
expected_list
self
.
upto
=
0
def
StartElementHandler
(
self
,
name
,
attrs
):
self
.
check_pos
(
's'
)
def
EndElementHandler
(
self
,
name
):
self
.
check_pos
(
'e'
)
def
check_pos
(
self
,
event
):
pos
=
(
event
,
self
.
parser
.
CurrentByteIndex
,
self
.
parser
.
CurrentLineNumber
,
self
.
parser
.
CurrentColumnNumber
)
require
(
self
.
upto
<
len
(
self
.
expected_list
),
'too many parser events'
)
expected
=
self
.
expected_list
[
self
.
upto
]
require
(
pos
==
expected
,
'expected position
%
s, got
%
s'
%
(
expected
,
pos
))
self
.
upto
+=
1
parser
=
expat
.
ParserCreate
()
handler
=
PositionTest
([(
's'
,
0
,
1
,
0
),
(
's'
,
5
,
2
,
1
),
(
's'
,
11
,
3
,
2
),
(
'e'
,
15
,
3
,
6
),
(
'e'
,
17
,
4
,
1
),
(
'e'
,
22
,
5
,
0
)],
parser
)
parser
.
Parse
(
'''<a>
<b>
<c/>
</b>
</a>'''
,
1
)
Misc/NEWS
Dosyayı görüntüle @
3203efb5
...
@@ -54,6 +54,9 @@ Extension modules
...
@@ -54,6 +54,9 @@ Extension modules
-
Added
socket
.
socketpair
().
-
Added
socket
.
socketpair
().
-
Added
CurrentByteIndex
,
CurrentColumnNumber
,
CurrentLineNumber
members
to
xml
.
parsers
.
expat
.
XMLParser
object
.
Library
Library
-------
-------
...
...
Modules/pyexpat.c
Dosyayı görüntüle @
3203efb5
...
@@ -1455,6 +1455,17 @@ xmlparse_getattr(xmlparseobject *self, char *name)
...
@@ -1455,6 +1455,17 @@ xmlparse_getattr(xmlparseobject *self, char *name)
return
PyInt_FromLong
((
long
)
return
PyInt_FromLong
((
long
)
XML_GetErrorByteIndex
(
self
->
itself
));
XML_GetErrorByteIndex
(
self
->
itself
));
}
}
if
(
name
[
0
]
==
'C'
)
{
if
(
strcmp
(
name
,
"CurrentLineNumber"
)
==
0
)
return
PyInt_FromLong
((
long
)
XML_GetCurrentLineNumber
(
self
->
itself
));
if
(
strcmp
(
name
,
"CurrentColumnNumber"
)
==
0
)
return
PyInt_FromLong
((
long
)
XML_GetCurrentColumnNumber
(
self
->
itself
));
if
(
strcmp
(
name
,
"CurrentByteIndex"
)
==
0
)
return
PyInt_FromLong
((
long
)
XML_GetCurrentByteIndex
(
self
->
itself
));
}
if
(
name
[
0
]
==
'b'
)
{
if
(
name
[
0
]
==
'b'
)
{
if
(
strcmp
(
name
,
"buffer_size"
)
==
0
)
if
(
strcmp
(
name
,
"buffer_size"
)
==
0
)
return
PyInt_FromLong
((
long
)
self
->
buffer_size
);
return
PyInt_FromLong
((
long
)
self
->
buffer_size
);
...
@@ -1503,6 +1514,9 @@ xmlparse_getattr(xmlparseobject *self, char *name)
...
@@ -1503,6 +1514,9 @@ xmlparse_getattr(xmlparseobject *self, char *name)
APPEND
(
rc
,
"ErrorLineNumber"
);
APPEND
(
rc
,
"ErrorLineNumber"
);
APPEND
(
rc
,
"ErrorColumnNumber"
);
APPEND
(
rc
,
"ErrorColumnNumber"
);
APPEND
(
rc
,
"ErrorByteIndex"
);
APPEND
(
rc
,
"ErrorByteIndex"
);
APPEND
(
rc
,
"CurrentLineNumber"
);
APPEND
(
rc
,
"CurrentColumnNumber"
);
APPEND
(
rc
,
"CurrentByteIndex"
);
APPEND
(
rc
,
"buffer_size"
);
APPEND
(
rc
,
"buffer_size"
);
APPEND
(
rc
,
"buffer_text"
);
APPEND
(
rc
,
"buffer_text"
);
APPEND
(
rc
,
"buffer_used"
);
APPEND
(
rc
,
"buffer_used"
);
...
...
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