-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-113093: add parameter 'mode' in shelve.open #148662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1013,6 +1013,8 @@ shelve | |||||||
| * Add support for custom serialization and deserialization functions | ||||||||
| in the :mod:`shelve` module. | ||||||||
| (Contributed by Furkan Onder in :gh:`99631`.) | ||||||||
| * Add suport for custom mode in :func:`shelve.open`. | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| (Contributed by Guilherme Crocetti in :gh:`113093`.) | ||||||||
|
|
||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kesp the new line |
||||||||
|
|
||||||||
| socket | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,10 +235,10 @@ class DbfilenameShelf(Shelf): | |
| See the module's __doc__ string for an overview of the interface. | ||
| """ | ||
|
|
||
| def __init__(self, filename, flag='c', protocol=None, writeback=False, *, | ||
| serializer=None, deserializer=None): | ||
| def __init__(self, filename, flag='c', protocol=None, writeback=False, | ||
| *, serializer=None, deserializer=None, mode=0o666): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the |
||
| import dbm | ||
| Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback, | ||
| Shelf.__init__(self, dbm.open(filename, flag, mode), protocol, writeback, | ||
| serializer=serializer, deserializer=deserializer) | ||
|
|
||
| def clear(self): | ||
|
|
@@ -248,19 +248,21 @@ def clear(self): | |
| self.cache.clear() | ||
| self.dict.clear() | ||
|
|
||
| def open(filename, flag='c', protocol=None, writeback=False, *, | ||
| serializer=None, deserializer=None): | ||
| def open(filename, flag='c', protocol=None, writeback=False, | ||
| *, serializer=None, deserializer=None, mode=0o666): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| """Open a persistent dictionary for reading and writing. | ||
|
|
||
| The filename parameter is the base filename for the underlying | ||
| database. As a side-effect, an extension may be added to the | ||
| filename and more than one file may be created. The optional flag | ||
| parameter has the same interpretation as the flag parameter of | ||
| dbm.open(). The optional protocol parameter specifies the | ||
| version of the pickle protocol. | ||
| version of the pickle protocol. The optional mode parameter is | ||
| passed to dbm.open() and controls the file mode when creating a | ||
| new shelf, set to 0666 by default. | ||
|
|
||
| See the module's __doc__ string for an overview of the interface. | ||
| """ | ||
|
|
||
| return DbfilenameShelf(filename, flag, protocol, writeback, | ||
| return DbfilenameShelf(filename, flag, protocol, writeback, mode=mode, | ||
| serializer=serializer, deserializer=deserializer) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import array | ||
| import unittest | ||
| from unittest import mock | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put zhis import after the list |
||
| import dbm | ||
| import shelve | ||
| import pickle | ||
|
|
@@ -47,6 +48,12 @@ class TestCase(unittest.TestCase): | |
| dirname = os_helper.TESTFN | ||
| fn = os.path.join(os_helper.TESTFN, "shelftemp.db") | ||
|
|
||
| @mock.patch("dbm.open", autospec=True) | ||
| def test_open_calls_dbm_as_expected(self, dbm_open): | ||
| shelf_open_mode = 0o433 | ||
| shelve.open(filename=self.fn, mode=shelf_open_mode) | ||
| dbm_open.assert_called_once_with(self.fn, 'c', shelf_open_mode) | ||
|
|
||
| def test_close(self): | ||
| d1 = {} | ||
| s = shelve.Shelf(d1, protocol=2, writeback=False) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add parameter *mode* in :func:`shelve.open`. | ||
| Contributed by Guilherme Crocetti. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the signature of the function and only refers to the default of dbm.open()