Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
ciksemel
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ç
SulinOS
ciksemel
Commits
7ffa26b6
Kaydet (Commit)
7ffa26b6
authored
Ara 04, 2016
tarafından
Suleyman Poyraz
Kaydeden (comit)
GitHub
Ara 04, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add files via upload
üst
5146a1e6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
257 additions
and
0 deletions
+257
-0
generate.py
tests/generate.py
+94
-0
iteration.py
tests/iteration.py
+51
-0
root.py
tests/root.py
+26
-0
traverse.py
tests/traverse.py
+86
-0
No files found.
tests/generate.py
0 → 100644
Dosyayı görüntüle @
7ffa26b6
#!/usr/bin/python
import
piksemel
as
iks
doc_xml
=
"""
<test>
<a><b><c/></b></a>
<item foo="lala">
<tuktuk>blah & bleh</tuktuk>
<nanuk/>
</item>
<a/>
</test>
"""
.
strip
()
doc
=
iks
.
newDocument
(
"test"
)
doc
.
insertData
(
"
\n
"
)
a
=
doc
.
insertTag
(
"a"
)
a
.
insertTag
(
"b"
)
.
insertTag
(
"c"
)
doc
.
insertData
(
"
\n
"
)
item
=
doc
.
insertTag
(
"item"
)
item
.
setAttribute
(
"foo"
,
"lala"
)
item
.
insertData
(
"
\n
"
)
item
.
insertTag
(
"tuktuk"
)
.
insertData
(
"blah & bleh"
)
item
.
insertData
(
"
\n
"
)
item
.
insertTag
(
"nanuk"
)
item
.
insertData
(
"
\n
"
)
doc
.
insertData
(
"
\n
"
)
a
=
doc
.
insertTag
(
"a"
)
doc
.
insertData
(
"
\n
"
)
assert
(
doc
.
toString
()
==
doc_xml
)
# append test
doc
=
iks
.
newDocument
(
"lala"
)
a
=
doc
.
insertTag
(
"nanik"
)
b
=
a
.
appendData
(
"lala"
)
a
=
b
.
appendTag
(
"lolo"
)
a
=
a
.
appendTag
(
"iki"
)
b
.
appendData
(
"hede"
)
doc
.
firstChild
()
.
appendData
(
"fii"
)
assert
(
doc
.
toString
()
==
"<lala><nanik/>fiilalahede<lolo/><iki/></lala>"
)
# prepend test
doc
=
iks
.
newDocument
(
"lala"
)
a
=
doc
.
insertTag
(
"foo"
)
a
=
a
.
prependTag
(
"a"
)
a
=
a
.
prependTag
(
"b"
)
a
.
prependData
(
"hihi"
)
.
prependData
(
"oh"
)
.
appendData
(
"i"
)
a
.
appendTag
(
"c"
)
assert
(
doc
.
toString
()
==
"<lala>ohihihi<b/><c/><a/><foo/></lala>"
)
# insertNode test
doc
=
iks
.
newDocument
(
"a"
)
b
=
iks
.
newDocument
(
"b"
)
b
.
setAttribute
(
"lal"
,
"foo"
)
b
=
doc
.
insertNode
(
b
)
b
.
setAttribute
(
"lal"
,
"foofff"
)
assert
(
doc
.
toString
()
==
'<a><b lal="foofff"/></a>'
)
# now with append, prepend and insertNode
doc
=
iks
.
newDocument
(
"test"
)
a
=
iks
.
newDocument
(
"a"
)
a
.
insertTag
(
"b"
)
.
insertTag
(
"c"
)
item
=
iks
.
newDocument
(
"item"
)
node
=
item
.
insertData
(
"
\n
"
)
node
.
appendTag
(
"tuktuk"
)
.
insertData
(
"blah & bleh"
)
node
=
item
.
insertData
(
"
\n
"
)
node
.
appendTag
(
"nanuk"
)
.
appendData
(
"
\n
"
)
doc
.
insertNode
(
a
)
.
appendData
(
"
\n
"
)
doc
.
getTag
(
"a"
)
.
prependData
(
"
\n
"
)
del
a
node
=
doc
.
insertNode
(
item
)
node
.
setAttribute
(
"foo"
,
"lala"
)
del
item
node
=
doc
.
insertData
(
"
\n
"
)
node
.
appendTag
(
"a"
)
.
appendData
(
"
\n
"
)
assert
(
doc
.
toString
()
==
doc_xml
)
# setData test
doc
=
iks
.
newDocument
(
"a"
)
x
=
doc
.
insertTag
(
"b"
)
x
.
insertTag
(
"lala"
)
y
=
x
.
insertTag
(
"bibi"
)
y
.
prependData
(
"hodo"
)
assert
(
x
.
toString
()
==
"<b><lala/>hodo<bibi/></b>"
)
x
.
setData
(
"merhaba"
)
assert
(
x
.
toString
()
==
"<b>merhaba</b>"
)
tests/iteration.py
0 → 100644
Dosyayı görüntüle @
7ffa26b6
#!/usr/bin/python
import
piksemel
as
iks
doc_xml
=
"""
<test>
<a/>
<item id="1"/>
<a/>
<foo/>
<item id="2">
<tuktuk>blah & bleh</tuktuk>
<a foo="bleh"/>
<nanuk/>
</item>
<a/>
<bar/>
<item/>
<item id="4"/>
<a/>
</test>
"""
doc
=
iks
.
parseString
(
doc_xml
)
count
=
0
for
node
in
doc
:
assert
(
node
.
type
()
==
iks
.
TAG
or
node
.
type
()
==
iks
.
DATA
)
count
+=
1
assert
(
count
==
21
)
count
=
0
for
node
in
doc
.
tags
():
assert
(
node
.
type
()
==
iks
.
TAG
)
count
+=
1
assert
(
count
==
10
)
count
=
0
for
node
in
doc
.
tags
(
"a"
):
assert
(
node
.
type
()
==
iks
.
TAG
)
assert
(
node
.
name
()
==
"a"
)
assert
(
node
.
getAttribute
(
"foo"
)
==
None
)
count
+=
1
assert
(
count
==
4
)
count
=
0
for
node
in
doc
.
tags
(
"item"
):
assert
(
node
.
type
()
==
iks
.
TAG
)
assert
(
node
.
name
()
==
"item"
)
count
+=
1
assert
(
count
==
4
)
tests/root.py
0 → 100644
Dosyayı görüntüle @
7ffa26b6
#!/usr/bin/python
import
piksemel
doc
=
piksemel
.
newDocument
(
"lala"
)
try
:
doc
.
appendTag
(
"lala"
)
except
piksemel
.
NotTag
:
pass
try
:
doc
.
appendData
(
"lala"
)
except
piksemel
.
NotTag
:
pass
try
:
doc
.
prependTag
(
"lala"
)
except
piksemel
.
NotTag
:
pass
try
:
doc
.
prependData
(
"lala"
)
except
piksemel
.
NotTag
:
pass
tests/traverse.py
0 → 100644
Dosyayı görüntüle @
7ffa26b6
#!/usr/bin/python
import
piksemel
as
iks
doc_xml
=
"""
<test>
<item id="1"/>
<foo/>
<item id="2">
<tuktuk>blah & bleh</tuktuk>
<nanuk/>
</item>
<bar/>
<item/>
<item id="4"/>
</test>
"""
doc
=
iks
.
parseString
(
doc_xml
)
# sibling nodes
node
=
doc
.
firstChild
()
last
=
None
count
=
0
while
node
:
last
=
node
count
+=
1
node
=
node
.
next
()
assert
(
count
==
13
)
node
=
last
while
node
:
count
-=
1
node
=
node
.
previous
()
assert
(
count
==
0
)
# sibling tags
item
=
doc
.
getTag
(
"item"
)
last
=
None
while
item
:
last
=
item
assert
(
item
.
type
()
==
iks
.
TAG
)
assert
(
item
.
name
()
==
"item"
)
count
+=
1
item
=
item
.
nextTag
(
"item"
)
assert
(
count
==
4
)
item
=
last
while
item
:
assert
(
item
.
type
()
==
iks
.
TAG
)
assert
(
item
.
name
()
==
"item"
)
count
-=
1
item
=
item
.
previousTag
(
"item"
)
assert
(
count
==
0
)
node
=
doc
.
getTag
(
"item"
)
last
=
None
while
node
:
last
=
node
assert
(
node
.
type
()
==
iks
.
TAG
)
count
+=
1
node
=
node
.
nextTag
()
assert
(
count
==
6
)
node
=
last
while
node
:
assert
(
node
.
type
()
==
iks
.
TAG
)
count
-=
1
node
=
node
.
previousTag
()
assert
(
count
==
0
)
# parent/child
node
=
doc
.
getTag
(
"item"
)
.
nextTag
()
.
nextTag
()
.
getTag
(
"nanuk"
)
assert
(
node
.
type
()
==
iks
.
TAG
)
assert
(
node
.
name
()
==
"nanuk"
)
item
=
node
.
parent
()
assert
(
item
.
type
()
==
iks
.
TAG
)
assert
(
item
.
name
()
==
"item"
)
top
=
node
.
root
()
assert
(
top
.
type
()
==
iks
.
TAG
)
assert
(
top
.
name
()
==
"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