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
b398d33c
Kaydet (Commit)
b398d33c
authored
Haz 10, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18039: dbm.dump.open() now always creates a new database when the
flag has the value 'n'. Patch by Claudiu Popa.
üst
4c4cde78
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
11 deletions
+36
-11
dbm.rst
Doc/library/dbm.rst
+7
-2
dumb.py
Lib/dbm/dumb.py
+18
-9
test_dbm_dumb.py
Lib/test/test_dbm_dumb.py
+8
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/dbm.rst
Dosyayı görüntüle @
b398d33c
...
...
@@ -316,13 +316,18 @@ The module defines the following:
dumbdbm database is created, files with :file:`.dat` and :file:`.dir` extensions
are created.
The optional *flag* argument is currently ignored; the database is always opened
for update, and will be created if it does not exist.
The optional *flag* argument supports only the semantics of ``'c'``
and ``'n'`` values. Other values will default to database being always
opened for update, and will be created if it does not exist.
The optional *mode* argument is the Unix mode of the file, used only when the
database has to be created. It defaults to octal ``0o666`` (and will be modified
by the prevailing umask).
.. versionchanged:: 3.5
:func:`.open` always creates a new database when the flag has the value
``'n'``.
In addition to the methods provided by the
:class:`collections.abc.MutableMapping` class, :class:`dumbdbm` objects
provide the following method:
...
...
Lib/dbm/dumb.py
Dosyayı görüntüle @
b398d33c
...
...
@@ -44,7 +44,7 @@ class _Database(collections.MutableMapping):
_os
=
_os
# for _commit()
_io
=
_io
# for _commit()
def
__init__
(
self
,
filebasename
,
mode
):
def
__init__
(
self
,
filebasename
,
mode
,
flag
=
'c'
):
self
.
_mode
=
mode
# The directory file is a text file. Each line looks like
...
...
@@ -64,6 +64,17 @@ class _Database(collections.MutableMapping):
# The index is an in-memory dict, mirroring the directory file.
self
.
_index
=
None
# maps keys to (pos, siz) pairs
# Handle the creation
self
.
_create
(
flag
)
self
.
_update
()
def
_create
(
self
,
flag
):
if
flag
==
'n'
:
for
filename
in
(
self
.
_datfile
,
self
.
_bakfile
,
self
.
_dirfile
):
try
:
_os
.
remove
(
filename
)
except
OSError
:
pass
# Mod by Jack: create data file if needed
try
:
f
=
_io
.
open
(
self
.
_datfile
,
'r'
,
encoding
=
"Latin-1"
)
...
...
@@ -71,7 +82,6 @@ class _Database(collections.MutableMapping):
f
=
_io
.
open
(
self
.
_datfile
,
'w'
,
encoding
=
"Latin-1"
)
self
.
_chmod
(
self
.
_datfile
)
f
.
close
()
self
.
_update
()
# Read directory file into the in-memory index dict.
def
_update
(
self
):
...
...
@@ -266,20 +276,20 @@ class _Database(collections.MutableMapping):
self
.
close
()
def
open
(
file
,
flag
=
None
,
mode
=
0
o666
):
def
open
(
file
,
flag
=
'c'
,
mode
=
0
o666
):
"""Open the database file, filename, and return corresponding object.
The flag argument, used to control how the database is opened in the
other DBM implementations, is ignored in the dbm.dumb module; the
database is always opened for update, and will be created if it does
not exist.
other DBM implementations, supports only the semantics of 'c' and 'n'
values. Other values will default to the semantics of 'c' value:
the database will always opened for update and will be created if it
does not exist.
The optional mode argument is the UNIX mode of the file, used only when
the database has to be created. It defaults to octal code 0o666 (and
will be modified by the prevailing umask).
"""
# flag argument is currently ignored
# Modify mode depending on the umask
try
:
...
...
@@ -290,5 +300,4 @@ def open(file, flag=None, mode=0o666):
else
:
# Turn off any bits that are set in the umask
mode
=
mode
&
(
~
um
)
return
_Database
(
file
,
mode
)
return
_Database
(
file
,
mode
,
flag
=
flag
)
Lib/test/test_dbm_dumb.py
Dosyayı görüntüle @
b398d33c
...
...
@@ -217,6 +217,14 @@ class DumbDBMTestCase(unittest.TestCase):
self
.
assertEqual
(
str
(
cm
.
exception
),
"DBM object has already been closed"
)
def
test_create_new
(
self
):
with
dumbdbm
.
open
(
_fname
,
'n'
)
as
f
:
for
k
in
self
.
_dict
:
f
[
k
]
=
self
.
_dict
[
k
]
with
dumbdbm
.
open
(
_fname
,
'n'
)
as
f
:
self
.
assertEqual
(
f
.
keys
(),
[])
def
tearDown
(
self
):
_delete_files
()
...
...
Misc/NEWS
Dosyayı görüntüle @
b398d33c
...
...
@@ -92,6 +92,9 @@ Core and Builtins
Library
-------
- Issue #18039: dbm.dump.open() now always creates a new database when the
flag has the value '
n
'. Patch by Claudiu Popa.
- Issue #21326: Add a new is_closed() method to asyncio.BaseEventLoop.
run_forever() and run_until_complete() methods of asyncio.BaseEventLoop now
raise an exception if the event loop was closed.
...
...
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