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
e6568694
Kaydet (Commit)
e6568694
authored
Agu 07, 2007
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Change dumbdbm to use bytes keys.
üst
45d569b8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
18 deletions
+21
-18
dumbdbm.py
Lib/dumbdbm.py
+5
-2
test_dumbdbm.py
Lib/test/test_dumbdbm.py
+15
-15
test_whichdb.py
Lib/test/test_whichdb.py
+1
-1
No files found.
Lib/dumbdbm.py
Dosyayı görüntüle @
e6568694
...
...
@@ -115,6 +115,7 @@ class _Database(UserDict.DictMixin):
sync
=
_commit
def
__getitem__
(
self
,
key
):
key
=
key
.
decode
(
"latin-1"
)
pos
,
siz
=
self
.
_index
[
key
]
# may raise KeyError
f
=
_io
.
open
(
self
.
_datfile
,
'rb'
)
f
.
seek
(
pos
)
...
...
@@ -159,8 +160,9 @@ class _Database(UserDict.DictMixin):
f
.
close
()
def
__setitem__
(
self
,
key
,
val
):
if
not
isinstance
(
key
,
basestring
):
raise
TypeError
(
"keys must be strings"
)
if
not
isinstance
(
key
,
bytes
):
raise
TypeError
(
"keys must be bytes"
)
key
=
key
.
decode
(
"latin-1"
)
# hashable bytes
if
not
isinstance
(
val
,
(
str8
,
bytes
)):
raise
TypeError
(
"values must be byte strings"
)
if
key
not
in
self
.
_index
:
...
...
@@ -188,6 +190,7 @@ class _Database(UserDict.DictMixin):
# (so that _commit() never gets called).
def
__delitem__
(
self
,
key
):
key
=
key
.
decode
(
"latin-1"
)
# The blocks used by the associated value are lost.
del
self
.
_index
[
key
]
# XXX It's unclear why we do a _commit() here (the code always
...
...
Lib/test/test_dumbdbm.py
Dosyayı görüntüle @
e6568694
...
...
@@ -35,7 +35,7 @@ class DumbDBMTestCase(unittest.TestCase):
f
=
dumbdbm
.
open
(
_fname
,
'c'
)
self
.
assertEqual
(
list
(
f
.
keys
()),
[])
for
key
in
self
.
_dict
:
f
[
key
]
=
self
.
_dict
[
key
]
f
[
key
.
encode
(
"ascii"
)
]
=
self
.
_dict
[
key
]
self
.
read_helper
(
f
)
f
.
close
()
...
...
@@ -65,15 +65,15 @@ class DumbDBMTestCase(unittest.TestCase):
def
test_close_twice
(
self
):
f
=
dumbdbm
.
open
(
_fname
)
f
[
'a'
]
=
b
'b'
self
.
assertEqual
(
f
[
'a'
],
b
'b'
)
f
[
b
'a'
]
=
b
'b'
self
.
assertEqual
(
f
[
b
'a'
],
b
'b'
)
f
.
close
()
f
.
close
()
def
test_dumbdbm_modification
(
self
):
self
.
init_db
()
f
=
dumbdbm
.
open
(
_fname
,
'w'
)
self
.
_dict
[
'g'
]
=
f
[
'g'
]
=
b
"indented"
self
.
_dict
[
'g'
]
=
f
[
b
'g'
]
=
b
"indented"
self
.
read_helper
(
f
)
f
.
close
()
...
...
@@ -92,8 +92,8 @@ class DumbDBMTestCase(unittest.TestCase):
def
test_write_write_read
(
self
):
# test for bug #482460
f
=
dumbdbm
.
open
(
_fname
)
f
[
'1'
]
=
b
'hello'
f
[
'1'
]
=
b
'hello2'
f
[
b
'1'
]
=
b
'hello'
f
[
b
'1'
]
=
b
'hello2'
f
.
close
()
f
=
dumbdbm
.
open
(
_fname
)
self
.
assertEqual
(
f
[
'1'
],
b
'hello2'
)
...
...
@@ -103,8 +103,8 @@ class DumbDBMTestCase(unittest.TestCase):
# test for bug #1172763: dumbdbm would die if the line endings
# weren't what was expected.
f
=
dumbdbm
.
open
(
_fname
)
f
[
'1'
]
=
b
'hello'
f
[
'2'
]
=
b
'hello2'
f
[
b
'1'
]
=
b
'hello'
f
[
b
'2'
]
=
b
'hello2'
f
.
close
()
# Mangle the file by adding \r before each newline
...
...
@@ -113,23 +113,23 @@ class DumbDBMTestCase(unittest.TestCase):
io
.
open
(
_fname
+
'.dir'
,
'wb'
)
.
write
(
data
)
f
=
dumbdbm
.
open
(
_fname
)
self
.
assertEqual
(
f
[
'1'
],
b
'hello'
)
self
.
assertEqual
(
f
[
'2'
],
b
'hello2'
)
self
.
assertEqual
(
f
[
b
'1'
],
b
'hello'
)
self
.
assertEqual
(
f
[
b
'2'
],
b
'hello2'
)
def
read_helper
(
self
,
f
):
keys
=
self
.
keys_helper
(
f
)
for
key
in
self
.
_dict
:
self
.
assertEqual
(
self
.
_dict
[
key
],
f
[
key
])
self
.
assertEqual
(
self
.
_dict
[
key
],
f
[
key
.
encode
(
"ascii"
)
])
def
init_db
(
self
):
f
=
dumbdbm
.
open
(
_fname
,
'w'
)
for
k
in
self
.
_dict
:
f
[
k
]
=
self
.
_dict
[
k
]
f
[
k
.
encode
(
"ascii"
)
]
=
self
.
_dict
[
k
]
f
.
close
()
def
keys_helper
(
self
,
f
):
keys
=
sorted
(
f
.
keys
())
keys
=
sorted
(
k
.
decode
(
"ascii"
)
for
k
in
f
.
keys
())
dkeys
=
sorted
(
self
.
_dict
.
keys
())
self
.
assertEqual
(
keys
,
dkeys
)
return
keys
...
...
@@ -146,11 +146,11 @@ class DumbDBMTestCase(unittest.TestCase):
if
random
.
random
()
<
0.2
:
if
k
in
d
:
del
d
[
k
]
del
f
[
k
]
del
f
[
k
.
encode
(
"ascii"
)
]
else
:
v
=
random
.
choice
((
b
'a'
,
b
'b'
,
b
'c'
))
*
random
.
randrange
(
10000
)
d
[
k
]
=
v
f
[
k
]
=
v
f
[
k
.
encode
(
"ascii"
)
]
=
v
self
.
assertEqual
(
f
[
k
],
v
)
f
.
close
()
...
...
Lib/test/test_whichdb.py
Dosyayı görüntüle @
e6568694
...
...
@@ -51,7 +51,7 @@ for name in anydbm._names:
self
.
assertEqual
(
name
,
whichdb
.
whichdb
(
_fname
))
# Now add a key
f
=
mod
.
open
(
_fname
,
'w'
)
f
[
"1"
]
=
b
"1"
f
[
b
"1"
]
=
b
"1"
f
.
close
()
self
.
assertEqual
(
name
,
whichdb
.
whichdb
(
_fname
))
setattr
(
WhichDBTestCase
,
"test_whichdb_
%
s"
%
name
,
test_whichdb_name
)
...
...
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