Skip to content

Commit

Permalink
Merge branch 'main' into nogil_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoV authored Jan 23, 2024
2 parents c6aede1 + ce01ab5 commit 6614421
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 160 deletions.
103 changes: 43 additions & 60 deletions Doc/library/dbm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ the Oracle Berkeley DB.
.. versionchanged:: 3.11
Accepts :term:`path-like object` for filename.

.. Substitutions for the open() flag param docs;
all submodules use the same text.
.. |flag_r| replace::
Open existing database for reading only.

.. |flag_w| replace::
Open existing database for reading and writing.

.. |flag_c| replace::
Open database for reading and writing, creating it if it doesn't exist.

.. |flag_n| replace::
Always create a new, empty database, open for reading and writing.

.. function:: open(file, flag='r', mode=0o666)

Open the database file *file* and return a corresponding object.
Expand All @@ -46,21 +61,13 @@ the Oracle Berkeley DB.

The optional *flag* argument can be:

+---------+-------------------------------------------+
| Value | Meaning |
+=========+===========================================+
| ``'r'`` | Open existing database for reading only |
| | (default) |
+---------+-------------------------------------------+
| ``'w'`` | Open existing database for reading and |
| | writing |
+---------+-------------------------------------------+
| ``'c'`` | Open database for reading and writing, |
| | creating it if it doesn't exist |
+---------+-------------------------------------------+
| ``'n'`` | Always create a new, empty database, open |
| | for reading and writing |
+---------+-------------------------------------------+
.. csv-table::
:header: "Value", "Meaning"

``'r'`` (default), |flag_r|
``'w'``, |flag_w|
``'c'``, |flag_c|
``'n'``, |flag_n|

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
Expand Down Expand Up @@ -165,21 +172,13 @@ supported.

The optional *flag* argument can be:

+---------+-------------------------------------------+
| Value | Meaning |
+=========+===========================================+
| ``'r'`` | Open existing database for reading only |
| | (default) |
+---------+-------------------------------------------+
| ``'w'`` | Open existing database for reading and |
| | writing |
+---------+-------------------------------------------+
| ``'c'`` | Open database for reading and writing, |
| | creating it if it doesn't exist |
+---------+-------------------------------------------+
| ``'n'`` | Always create a new, empty database, open |
| | for reading and writing |
+---------+-------------------------------------------+
.. csv-table::
:header: "Value", "Meaning"

``'r'`` (default), |flag_r|
``'w'``, |flag_w|
``'c'``, |flag_c|
``'n'``, |flag_n|

The following additional characters may be appended to the flag to control
how the database is opened:
Expand Down Expand Up @@ -297,21 +296,13 @@ to locate the appropriate header file to simplify building this module.

The optional *flag* argument must be one of these values:

+---------+-------------------------------------------+
| Value | Meaning |
+=========+===========================================+
| ``'r'`` | Open existing database for reading only |
| | (default) |
+---------+-------------------------------------------+
| ``'w'`` | Open existing database for reading and |
| | writing |
+---------+-------------------------------------------+
| ``'c'`` | Open database for reading and writing, |
| | creating it if it doesn't exist |
+---------+-------------------------------------------+
| ``'n'`` | Always create a new, empty database, open |
| | for reading and writing |
+---------+-------------------------------------------+
.. csv-table::
:header: "Value", "Meaning"

``'r'`` (default), |flag_r|
``'w'``, |flag_w|
``'c'``, |flag_c|
``'n'``, |flag_n|

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
Expand Down Expand Up @@ -376,21 +367,13 @@ The module defines the following:

The optional *flag* argument can be:

+---------+-------------------------------------------+
| Value | Meaning |
+=========+===========================================+
| ``'r'`` | Open existing database for reading only |
| | (default) |
+---------+-------------------------------------------+
| ``'w'`` | Open existing database for reading and |
| | writing |
+---------+-------------------------------------------+
| ``'c'`` | Open database for reading and writing, |
| | creating it if it doesn't exist |
+---------+-------------------------------------------+
| ``'n'`` | Always create a new, empty database, open |
| | for reading and writing |
+---------+-------------------------------------------+
.. csv-table::
:header: "Value", "Meaning"

``'r'``, |flag_r|
``'w'``, |flag_w|
``'c'`` (default), |flag_c|
``'n'``, |flag_n|

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
Expand Down
27 changes: 17 additions & 10 deletions Lib/xml/etree/ElementTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import collections
import collections.abc
import contextlib
import weakref

from . import ElementPath

Expand Down Expand Up @@ -1223,13 +1224,14 @@ def iterparse(source, events=None, parser=None):
# parser argument of iterparse is removed, this can be killed.
pullparser = XMLPullParser(events=events, _parser=parser)

def iterator(source):
if not hasattr(source, "read"):
source = open(source, "rb")
close_source = True
else:
close_source = False

def iterator(source):
try:
if not hasattr(source, "read"):
source = open(source, "rb")
close_source = True
yield None
while True:
yield from pullparser.read_events()
# load event buffer
Expand All @@ -1239,18 +1241,23 @@ def iterator(source):
pullparser.feed(data)
root = pullparser._close_and_return_root()
yield from pullparser.read_events()
it.root = root
it = wr()
if it is not None:
it.root = root
finally:
if close_source:
source.close()

class IterParseIterator(collections.abc.Iterator):
__next__ = iterator(source).__next__
it = IterParseIterator()
it.root = None
del iterator, IterParseIterator

next(it)
def __del__(self):
if close_source:
source.close()

it = IterParseIterator()
wr = weakref.ref(it)
del IterParseIterator
return it


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make :class:`queue.SimpleQueue` thread safe when the GIL is disabled.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Avoid reference cycle in ElementTree.iterparse. The iterator returned by
``ElementTree.iterparse`` may hold on to a file descriptor. The reference
cycle prevented prompt clean-up of the file descriptor if the returned
iterator was not exhausted.
Loading

0 comments on commit 6614421

Please sign in to comment.