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
33ad0968
Kaydet (Commit)
33ad0968
authored
Haz 25, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #21729: Used the "with" statement in the dbm.dumb module to ensure
files closing. Patch by Claudiu Popa.
üst
6d52ced4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
33 deletions
+32
-33
dumbdbm.py
Lib/dumbdbm.py
+29
-33
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/dumbdbm.py
Dosyayı görüntüle @
33ad0968
...
@@ -68,9 +68,10 @@ class _Database(UserDict.DictMixin):
...
@@ -68,9 +68,10 @@ class _Database(UserDict.DictMixin):
try
:
try
:
f
=
_open
(
self
.
_datfile
,
'r'
)
f
=
_open
(
self
.
_datfile
,
'r'
)
except
IOError
:
except
IOError
:
f
=
_open
(
self
.
_datfile
,
'w'
)
with
_open
(
self
.
_datfile
,
'w'
)
as
f
:
self
.
_chmod
(
self
.
_datfile
)
self
.
_chmod
(
self
.
_datfile
)
f
.
close
()
else
:
f
.
close
()
self
.
_update
()
self
.
_update
()
# Read directory file into the in-memory index dict.
# Read directory file into the in-memory index dict.
...
@@ -81,11 +82,11 @@ class _Database(UserDict.DictMixin):
...
@@ -81,11 +82,11 @@ class _Database(UserDict.DictMixin):
except
IOError
:
except
IOError
:
pass
pass
else
:
else
:
for
line
in
f
:
with
f
:
line
=
line
.
rstrip
()
for
line
in
f
:
key
,
pos_and_siz_pair
=
eval
(
line
)
line
=
line
.
rstrip
(
)
self
.
_index
[
key
]
=
pos_and_siz_pair
key
,
pos_and_siz_pair
=
eval
(
line
)
f
.
close
()
self
.
_index
[
key
]
=
pos_and_siz_pair
# Write the index dict to the directory file. The original directory
# Write the index dict to the directory file. The original directory
# file (if any) is renamed with a .bak extension first. If a .bak
# file (if any) is renamed with a .bak extension first. If a .bak
...
@@ -107,20 +108,18 @@ class _Database(UserDict.DictMixin):
...
@@ -107,20 +108,18 @@ class _Database(UserDict.DictMixin):
except
self
.
_os
.
error
:
except
self
.
_os
.
error
:
pass
pass
f
=
self
.
_open
(
self
.
_dirfile
,
'w'
)
with
self
.
_open
(
self
.
_dirfile
,
'w'
)
as
f
:
self
.
_chmod
(
self
.
_dirfile
)
self
.
_chmod
(
self
.
_dirfile
)
for
key
,
pos_and_siz_pair
in
self
.
_index
.
iteritems
():
for
key
,
pos_and_siz_pair
in
self
.
_index
.
iteritems
():
f
.
write
(
"
%
r,
%
r
\n
"
%
(
key
,
pos_and_siz_pair
))
f
.
write
(
"
%
r,
%
r
\n
"
%
(
key
,
pos_and_siz_pair
))
f
.
close
()
sync
=
_commit
sync
=
_commit
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
pos
,
siz
=
self
.
_index
[
key
]
# may raise KeyError
pos
,
siz
=
self
.
_index
[
key
]
# may raise KeyError
f
=
_open
(
self
.
_datfile
,
'rb'
)
with
_open
(
self
.
_datfile
,
'rb'
)
as
f
:
f
.
seek
(
pos
)
f
.
seek
(
pos
)
dat
=
f
.
read
(
siz
)
dat
=
f
.
read
(
siz
)
f
.
close
()
return
dat
return
dat
# Append val to the data file, starting at a _BLOCKSIZE-aligned
# Append val to the data file, starting at a _BLOCKSIZE-aligned
...
@@ -128,14 +127,13 @@ class _Database(UserDict.DictMixin):
...
@@ -128,14 +127,13 @@ class _Database(UserDict.DictMixin):
# to get to an aligned offset. Return pair
# to get to an aligned offset. Return pair
# (starting offset of val, len(val))
# (starting offset of val, len(val))
def
_addval
(
self
,
val
):
def
_addval
(
self
,
val
):
f
=
_open
(
self
.
_datfile
,
'rb+'
)
with
_open
(
self
.
_datfile
,
'rb+'
)
as
f
:
f
.
seek
(
0
,
2
)
f
.
seek
(
0
,
2
)
pos
=
int
(
f
.
tell
())
pos
=
int
(
f
.
tell
())
npos
=
((
pos
+
_BLOCKSIZE
-
1
)
//
_BLOCKSIZE
)
*
_BLOCKSIZE
npos
=
((
pos
+
_BLOCKSIZE
-
1
)
//
_BLOCKSIZE
)
*
_BLOCKSIZE
f
.
write
(
'
\0
'
*
(
npos
-
pos
))
f
.
write
(
'
\0
'
*
(
npos
-
pos
))
pos
=
npos
pos
=
npos
f
.
write
(
val
)
f
.
write
(
val
)
f
.
close
()
return
(
pos
,
len
(
val
))
return
(
pos
,
len
(
val
))
# Write val to the data file, starting at offset pos. The caller
# Write val to the data file, starting at offset pos. The caller
...
@@ -143,10 +141,9 @@ class _Database(UserDict.DictMixin):
...
@@ -143,10 +141,9 @@ class _Database(UserDict.DictMixin):
# pos to hold val, without overwriting some other value. Return
# pos to hold val, without overwriting some other value. Return
# pair (pos, len(val)).
# pair (pos, len(val)).
def
_setval
(
self
,
pos
,
val
):
def
_setval
(
self
,
pos
,
val
):
f
=
_open
(
self
.
_datfile
,
'rb+'
)
with
_open
(
self
.
_datfile
,
'rb+'
)
as
f
:
f
.
seek
(
pos
)
f
.
seek
(
pos
)
f
.
write
(
val
)
f
.
write
(
val
)
f
.
close
()
return
(
pos
,
len
(
val
))
return
(
pos
,
len
(
val
))
# key is a new key whose associated value starts in the data file
# key is a new key whose associated value starts in the data file
...
@@ -154,10 +151,9 @@ class _Database(UserDict.DictMixin):
...
@@ -154,10 +151,9 @@ class _Database(UserDict.DictMixin):
# the in-memory index dict, and append one to the directory file.
# the in-memory index dict, and append one to the directory file.
def
_addkey
(
self
,
key
,
pos_and_siz_pair
):
def
_addkey
(
self
,
key
,
pos_and_siz_pair
):
self
.
_index
[
key
]
=
pos_and_siz_pair
self
.
_index
[
key
]
=
pos_and_siz_pair
f
=
_open
(
self
.
_dirfile
,
'a'
)
with
_open
(
self
.
_dirfile
,
'a'
)
as
f
:
self
.
_chmod
(
self
.
_dirfile
)
self
.
_chmod
(
self
.
_dirfile
)
f
.
write
(
"
%
r,
%
r
\n
"
%
(
key
,
pos_and_siz_pair
))
f
.
write
(
"
%
r,
%
r
\n
"
%
(
key
,
pos_and_siz_pair
))
f
.
close
()
def
__setitem__
(
self
,
key
,
val
):
def
__setitem__
(
self
,
key
,
val
):
if
not
type
(
key
)
==
type
(
''
)
==
type
(
val
):
if
not
type
(
key
)
==
type
(
''
)
==
type
(
val
):
...
...
Misc/NEWS
Dosyayı görüntüle @
33ad0968
...
@@ -32,6 +32,9 @@ Core and Builtins
...
@@ -32,6 +32,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #21729: Used the "with" statement in the dbm.dumb module to ensure
files closing.
- Issue #21672: Fix the behavior of ntpath.join on UNC-style paths.
- Issue #21672: Fix the behavior of ntpath.join on UNC-style paths.
- Issue #19145: The times argument for itertools.repeat now handles
- Issue #19145: The times argument for itertools.repeat now handles
...
...
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