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
882a4169
Kaydet (Commit)
882a4169
authored
Şub 07, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
üst
017b6a3a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
45 deletions
+14
-45
UserList.py
Lib/UserList.py
+5
-1
UserString.py
Lib/UserString.py
+9
-2
test_iterlen.py
Lib/test/test_iterlen.py
+0
-42
No files found.
Lib/UserList.py
Dosyayı görüntüle @
882a4169
"""A more or less complete user-defined wrapper around list objects."""
class
UserList
:
import
collections
class
UserList
(
collections
.
MutableSequence
):
def
__init__
(
self
,
initlist
=
None
):
self
.
data
=
[]
if
initlist
is
not
None
:
...
...
@@ -83,3 +85,5 @@ class UserList:
self
.
data
.
extend
(
other
.
data
)
else
:
self
.
data
.
extend
(
other
)
collections
.
MutableSequence
.
register
(
UserList
)
Lib/UserString.py
Dosyayı görüntüle @
882a4169
...
...
@@ -6,10 +6,11 @@ Note: string objects have grown methods in Python 1.6
This module requires Python 1.6 or later.
"""
import
sys
import
collections
__all__
=
[
"UserString"
,
"MutableString"
]
class
UserString
:
class
UserString
(
collections
.
Sequence
)
:
def
__init__
(
self
,
seq
):
if
isinstance
(
seq
,
basestring
):
self
.
data
=
seq
...
...
@@ -129,7 +130,9 @@ class UserString:
def
upper
(
self
):
return
self
.
__class__
(
self
.
data
.
upper
())
def
zfill
(
self
,
width
):
return
self
.
__class__
(
self
.
data
.
zfill
(
width
))
class
MutableString
(
UserString
):
collections
.
Sequence
.
register
(
UserString
)
class
MutableString
(
UserString
,
collections
.
MutableSequence
):
"""mutable string objects
Python strings are immutable objects. This has the advantage, that
...
...
@@ -208,6 +211,10 @@ class MutableString(UserString):
def
__imul__
(
self
,
n
):
self
.
data
*=
n
return
self
def
insert
(
self
,
index
,
value
):
self
[
index
:
index
]
=
value
collections
.
MutableSequence
.
register
(
MutableString
)
if
__name__
==
"__main__"
:
# execute the regression test to stdout, if called as a script:
...
...
Lib/test/test_iterlen.py
Dosyayı görüntüle @
882a4169
...
...
@@ -45,7 +45,6 @@ import unittest
from
test
import
test_support
from
itertools
import
repeat
from
collections
import
deque
from
UserList
import
UserList
from
__builtin__
import
len
as
_len
n
=
10
...
...
@@ -196,45 +195,6 @@ class TestListReversed(TestInvariantWithoutMutations):
d
.
extend
(
xrange
(
20
))
self
.
assertEqual
(
len
(
it
),
0
)
class
TestSeqIter
(
TestInvariantWithoutMutations
):
def
setUp
(
self
):
self
.
it
=
iter
(
UserList
(
range
(
n
)))
def
test_mutation
(
self
):
d
=
UserList
(
range
(
n
))
it
=
iter
(
d
)
it
.
next
()
it
.
next
()
self
.
assertEqual
(
len
(
it
),
n
-
2
)
d
.
append
(
n
)
self
.
assertEqual
(
len
(
it
),
n
-
1
)
# grow with append
d
[
1
:]
=
[]
self
.
assertEqual
(
len
(
it
),
0
)
self
.
assertEqual
(
list
(
it
),
[])
d
.
extend
(
xrange
(
20
))
self
.
assertEqual
(
len
(
it
),
0
)
class
TestSeqIterReversed
(
TestInvariantWithoutMutations
):
def
setUp
(
self
):
self
.
it
=
reversed
(
UserList
(
range
(
n
)))
def
test_mutation
(
self
):
d
=
UserList
(
range
(
n
))
it
=
reversed
(
d
)
it
.
next
()
it
.
next
()
self
.
assertEqual
(
len
(
it
),
n
-
2
)
d
.
append
(
n
)
self
.
assertEqual
(
len
(
it
),
n
-
2
)
# ignore append
d
[
1
:]
=
[]
self
.
assertEqual
(
len
(
it
),
0
)
self
.
assertEqual
(
list
(
it
),
[])
# confirm invariant
d
.
extend
(
xrange
(
20
))
self
.
assertEqual
(
len
(
it
),
0
)
def
test_main
():
unittests
=
[
TestRepeat
,
...
...
@@ -249,8 +209,6 @@ def test_main():
TestSet
,
TestList
,
TestListReversed
,
TestSeqIter
,
TestSeqIterReversed
,
]
test_support
.
run_unittest
(
*
unittests
)
...
...
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