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
5c6198b3
Kaydet (Commit)
5c6198b3
authored
Ock 24, 2013
tarafından
Eli Bendersky
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #12323: Strengthen error checking of the position XPath selectors
üst
7ff241d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
test_xml_etree.py
Lib/test/test_xml_etree.py
+5
-0
ElementPath.py
Lib/xml/etree/ElementPath.py
+7
-2
No files found.
Lib/test/test_xml_etree.py
Dosyayı görüntüle @
5c6198b3
...
...
@@ -1793,6 +1793,11 @@ class ElementFindTest(unittest.TestCase):
self
.
assertEqual
(
e
.
find
(
'./tag[last()-1]'
)
.
attrib
[
'class'
],
'c'
)
self
.
assertEqual
(
e
.
find
(
'./tag[last()-2]'
)
.
attrib
[
'class'
],
'b'
)
self
.
assertRaisesRegex
(
SyntaxError
,
'XPath'
,
e
.
find
,
'./tag[0]'
)
self
.
assertRaisesRegex
(
SyntaxError
,
'XPath'
,
e
.
find
,
'./tag[-1]'
)
self
.
assertRaisesRegex
(
SyntaxError
,
'XPath'
,
e
.
find
,
'./tag[last()-0]'
)
self
.
assertRaisesRegex
(
SyntaxError
,
'XPath'
,
e
.
find
,
'./tag[last()+1]'
)
def
test_findall
(
self
):
e
=
ET
.
XML
(
SAMPLE_XML
)
e
[
2
]
=
ET
.
XML
(
SAMPLE_SECTION
)
...
...
Lib/xml/etree/ElementPath.py
Dosyayı görüntüle @
5c6198b3
...
...
@@ -174,7 +174,7 @@ def prepare_predicate(next, token):
if
elem
.
get
(
key
)
==
value
:
yield
elem
return
select
if
signature
==
"-"
and
not
re
.
match
(
"
\
d+$"
,
predicate
[
0
]):
if
signature
==
"-"
and
not
re
.
match
(
"
\
-?
\
d+$"
,
predicate
[
0
]):
# [tag]
tag
=
predicate
[
0
]
def
select
(
context
,
result
):
...
...
@@ -182,7 +182,7 @@ def prepare_predicate(next, token):
if
elem
.
find
(
tag
)
is
not
None
:
yield
elem
return
select
if
signature
==
"-='"
and
not
re
.
match
(
"
\
d+$"
,
predicate
[
0
]):
if
signature
==
"-='"
and
not
re
.
match
(
"
\
-?
\
d+$"
,
predicate
[
0
]):
# [tag='value']
tag
=
predicate
[
0
]
value
=
predicate
[
-
1
]
...
...
@@ -196,7 +196,10 @@ def prepare_predicate(next, token):
if
signature
==
"-"
or
signature
==
"-()"
or
signature
==
"-()-"
:
# [index] or [last()] or [last()-index]
if
signature
==
"-"
:
# [index]
index
=
int
(
predicate
[
0
])
-
1
if
index
<
0
:
raise
SyntaxError
(
"XPath position >= 1 expected"
)
else
:
if
predicate
[
0
]
!=
"last"
:
raise
SyntaxError
(
"unsupported function"
)
...
...
@@ -205,6 +208,8 @@ def prepare_predicate(next, token):
index
=
int
(
predicate
[
2
])
-
1
except
ValueError
:
raise
SyntaxError
(
"unsupported expression"
)
if
index
>
-
2
:
raise
SyntaxError
(
"XPath offset from last() must be negative"
)
else
:
index
=
-
1
def
select
(
context
,
result
):
...
...
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