Skip to content

Commit 1a4c5e5

Browse files
Merge branch 'main' into clear_NameError_suggestion
2 parents e8b47e4 + c22e9c9 commit 1a4c5e5

38 files changed

Lines changed: 1389 additions & 779 deletions

Doc/library/imaplib.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,13 @@ An :class:`IMAP4` instance has the following methods:
610610
If *uid* is true, the message numbers in the response are UIDs
611611
(``UID SEARCH``).
612612

613+
A criterion passed as :class:`str` is encoded to *charset*
614+
(which must name a codec known to Python);
615+
pass :class:`bytes` to send a criterion that is already encoded,
616+
for example when *charset* is one that Python does not support.
617+
When *charset* is ``None`` (as it must be under ``UTF8=ACCEPT``),
618+
the criterion is sent using the connection's encoding instead.
619+
613620
Example::
614621

615622
# M is a connected IMAP4 instance...
@@ -621,6 +628,9 @@ An :class:`IMAP4` instance has the following methods:
621628
.. versionchanged:: next
622629
Added the *uid* parameter.
623630

631+
.. versionchanged:: next
632+
``str`` search criteria are encoded to *charset*.
633+
624634

625635
.. method:: IMAP4.select(mailbox='INBOX', readonly=False)
626636

@@ -682,11 +692,18 @@ An :class:`IMAP4` instance has the following methods:
682692

683693
If *uid* is true, the message numbers in the response are UIDs (``UID SORT``).
684694

695+
As with :meth:`search`,
696+
a *search_criterion* passed as :class:`str` is encoded to *charset*;
697+
pass :class:`bytes` to send one already encoded.
698+
685699
This is an ``IMAP4rev1`` extension command.
686700

687701
.. versionchanged:: next
688702
Added the *uid* parameter.
689703

704+
.. versionchanged:: next
705+
``str`` search criteria are encoded to *charset*.
706+
690707

691708
.. method:: IMAP4.starttls(ssl_context=None)
692709

@@ -772,11 +789,18 @@ An :class:`IMAP4` instance has the following methods:
772789
If *uid* is true, the message numbers in the response are UIDs
773790
(``UID THREAD``).
774791

792+
As with :meth:`search`,
793+
a *search_criterion* passed as :class:`str` is encoded to *charset*;
794+
pass :class:`bytes` to send one already encoded.
795+
775796
This is an ``IMAP4rev1`` extension command.
776797

777798
.. versionchanged:: next
778799
Added the *uid* parameter.
779800

801+
.. versionchanged:: next
802+
``str`` search criteria are encoded to *charset*.
803+
780804

781805
.. method:: IMAP4.uid(command, arg[, ...])
782806

Doc/library/tkinter.scrolledtext.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ most normal geometry management behavior.
2323
Should more specific control be necessary, the following attributes are
2424
available:
2525

26-
.. class:: ScrolledText(master=None, **kw)
26+
.. class:: ScrolledText(master=None, *, use_ttk=False, **kw)
27+
28+
The keyword arguments are passed to the :class:`~tkinter.Text` widget.
29+
30+
When *use_ttk* is true, the surrounding frame and the scroll bar are the
31+
themed :mod:`tkinter.ttk` widgets;
32+
the default is the classic :mod:`tkinter` widgets.
33+
34+
.. versionchanged:: next
35+
Added the *use_ttk* parameter.
2736

2837

2938
.. attribute:: frame

Doc/whatsnew/3.16.rst

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ codecs
9999
curses
100100
------
101101

102-
* Add support for multiple terminals to the :mod:`curses` module:
103-
the new functions :func:`curses.newterm`, :func:`curses.set_term`
104-
and :func:`curses.new_prescr`,
105-
the corresponding :ref:`screen <curses-screen-objects>` object,
106-
and the :meth:`window.use() <curses.window.use>` method.
107-
(Contributed by Serhiy Storchaka in :gh:`90092`.)
108-
109102
* The :mod:`curses` character-cell window methods now accept a full character
110103
cell --- a spacing character optionally followed by combining characters ---
111104
in addition to a single integer or byte character. This affects
@@ -126,40 +119,6 @@ curses
126119
and :meth:`~curses.window.in_wstr` returns its decoded text.
127120
(Contributed by Serhiy Storchaka in :gh:`151757`.)
128121

129-
* The wide-character :mod:`curses` functions and methods
130-
:meth:`~curses.window.get_wch`, :meth:`~curses.window.get_wstr`,
131-
:func:`curses.unget_wch`, :func:`curses.erasewchar`,
132-
:func:`curses.killwchar` and :func:`curses.wunctrl` now also work when Python
133-
is not built against a wide-character-aware curses library, on an 8-bit
134-
locale, where each character is a single byte in the relevant encoding.
135-
:func:`curses.ungetch` now also accepts a one-character string, like
136-
:func:`curses.unget_wch`; on a wide-character build it can be any character
137-
(previously a multibyte character raised :exc:`OverflowError`).
138-
(Contributed by Serhiy Storchaka in :gh:`152470`.)
139-
140-
* Add :func:`curses.nofilter`, which undoes the effect of :func:`curses.filter`.
141-
(Contributed by Serhiy Storchaka in :gh:`151744`.)
142-
143-
* Add the :mod:`curses` functions :func:`curses.alloc_pair`,
144-
:func:`curses.find_pair`, :func:`curses.free_pair` and
145-
:func:`curses.reset_color_pairs` for dynamic color-pair management,
146-
available when built against a wide-character ncurses with extended-color
147-
support.
148-
(Contributed by Serhiy Storchaka in :gh:`151774`.)
149-
150-
* Add :mod:`curses` functions and window methods that report state which could
151-
previously only be set, such as :meth:`curses.window.is_keypad`,
152-
:meth:`curses.window.getparent` and :func:`curses.is_cbreak`,
153-
available when built against an ncurses with ``NCURSES_EXT_FUNCS``.
154-
(Contributed by Serhiy Storchaka in :gh:`151776`.)
155-
156-
* Add the :mod:`curses` window methods :meth:`~curses.window.attr_get`,
157-
:meth:`~curses.window.attr_set`, :meth:`~curses.window.attr_on`,
158-
:meth:`~curses.window.attr_off` and :meth:`~curses.window.color_set`, which
159-
pass the color pair as a separate argument instead of packing it into the
160-
attribute value, and the corresponding ``WA_*`` attribute constants.
161-
(Contributed by Serhiy Storchaka in :gh:`152219`.)
162-
163122
* Add the :class:`curses.complexchar` type, representing a styled
164123
character cell (its text, attributes and color pair), and the window
165124
methods :meth:`~curses.window.in_wch` and :meth:`~curses.window.getbkgrnd`
@@ -183,15 +142,52 @@ curses
183142
library.
184143
(Contributed by Serhiy Storchaka in :gh:`152233`.)
185144

186-
* Add the :mod:`curses` window method :meth:`~curses.window.dupwin`, which
187-
returns a new window that is an independent duplicate of an existing one.
188-
(Contributed by Serhiy Storchaka in :gh:`152258`.)
145+
* The wide-character :mod:`curses` functions and methods
146+
:meth:`~curses.window.get_wch`, :meth:`~curses.window.get_wstr`,
147+
:func:`curses.unget_wch`, :func:`curses.erasewchar`,
148+
:func:`curses.killwchar` and :func:`curses.wunctrl` now also work when Python
149+
is not built against a wide-character-aware curses library, on an 8-bit
150+
locale, where each character is a single byte in the relevant encoding.
151+
:func:`curses.ungetch` now also accepts a one-character string, like
152+
:func:`curses.unget_wch`; on a wide-character build it can be any character
153+
(previously a multibyte character raised :exc:`OverflowError`).
154+
(Contributed by Serhiy Storchaka in :gh:`152470`.)
155+
156+
* Add support for multiple terminals to the :mod:`curses` module:
157+
the new functions :func:`curses.newterm`, :func:`curses.set_term`
158+
and :func:`curses.new_prescr`,
159+
the corresponding :ref:`screen <curses-screen-objects>` object,
160+
and the :meth:`window.use() <curses.window.use>` method.
161+
(Contributed by Serhiy Storchaka in :gh:`90092`.)
162+
163+
* Add the :mod:`curses` window methods :meth:`~curses.window.attr_get`,
164+
:meth:`~curses.window.attr_set`, :meth:`~curses.window.attr_on`,
165+
:meth:`~curses.window.attr_off` and :meth:`~curses.window.color_set`, which
166+
pass the color pair as a separate argument instead of packing it into the
167+
attribute value, and the corresponding ``WA_*`` attribute constants.
168+
(Contributed by Serhiy Storchaka in :gh:`152219`.)
169+
170+
* Add the :func:`curses.term_attrs` function, which returns the supported
171+
video attributes as :ref:`WA_* <curses-wa-constants>` values, the
172+
counterpart of :func:`curses.termattrs`.
173+
(Contributed by Serhiy Storchaka in :gh:`152332`.)
174+
175+
* Add the :mod:`curses` functions :func:`curses.alloc_pair`,
176+
:func:`curses.find_pair`, :func:`curses.free_pair` and
177+
:func:`curses.reset_color_pairs` for dynamic color-pair management,
178+
available when built against a wide-character ncurses with extended-color
179+
support.
180+
(Contributed by Serhiy Storchaka in :gh:`151774`.)
189181

190182
* Add the :mod:`curses` functions :func:`~curses.scr_dump`,
191183
:func:`~curses.scr_restore`, :func:`~curses.scr_init` and
192184
:func:`~curses.scr_set`, which dump the whole screen to a file and restore it.
193185
(Contributed by Serhiy Storchaka in :gh:`152260`.)
194186

187+
* Add the :mod:`curses` window method :meth:`~curses.window.dupwin`, which
188+
returns a new window that is an independent duplicate of an existing one.
189+
(Contributed by Serhiy Storchaka in :gh:`152258`.)
190+
195191
* Add the soft-label-key functions to the :mod:`curses` module, which manage a
196192
row of labels along the bottom line of the screen:
197193
:func:`~curses.slk_init`, :func:`~curses.slk_set`, :func:`~curses.slk_label`,
@@ -204,11 +200,6 @@ curses
204200
:func:`~curses.slk_attr_set`, and :func:`~curses.slk_color`.
205201
(Contributed by Serhiy Storchaka in :gh:`152263`.)
206202

207-
* Add the :func:`curses.term_attrs` function, which returns the supported
208-
video attributes as :ref:`WA_* <curses-wa-constants>` values, the
209-
counterpart of :func:`curses.termattrs`.
210-
(Contributed by Serhiy Storchaka in :gh:`152332`.)
211-
212203
* Add the :mod:`curses` key-management functions :func:`~curses.define_key`,
213204
:func:`~curses.key_defined` and :func:`~curses.keyok`, available when built
214205
against an ncurses with ``NCURSES_EXT_FUNCS``.
@@ -219,6 +210,15 @@ curses
219210
mouse interface.
220211
(Contributed by Serhiy Storchaka in :gh:`152325`.)
221212

213+
* Add :mod:`curses` functions and window methods that report state which could
214+
previously only be set, such as :meth:`curses.window.is_keypad`,
215+
:meth:`curses.window.getparent` and :func:`curses.is_cbreak`,
216+
available when built against an ncurses with ``NCURSES_EXT_FUNCS``.
217+
(Contributed by Serhiy Storchaka in :gh:`151776`.)
218+
219+
* Add :func:`curses.nofilter`, which undoes the effect of :func:`curses.filter`.
220+
(Contributed by Serhiy Storchaka in :gh:`151744`.)
221+
222222
* :class:`curses.textpad.Textbox` now supports entering and reading back the
223223
full Unicode range, including combining characters, when curses is built with
224224
wide-character support.
@@ -276,6 +276,14 @@ imaplib
276276
:meth:`~imaplib.IMAP4.uid`.
277277
(Contributed by Serhiy Storchaka in :gh:`153502`.)
278278

279+
* :meth:`~imaplib.IMAP4.search`, :meth:`~imaplib.IMAP4.sort`
280+
and :meth:`~imaplib.IMAP4.thread` (and the corresponding ``uid`` commands)
281+
now encode :class:`str` search criteria to the declared *charset*,
282+
so international search text can be passed as an ordinary :class:`str`.
283+
When *charset* is ``None`` (as it must be under ``UTF8=ACCEPT``),
284+
the criteria are sent using the connection encoding instead.
285+
(Contributed by Serhiy Storchaka in :gh:`153494`.)
286+
279287

280288
ipaddress
281289
---------
@@ -448,6 +456,11 @@ tkinter
448456
them.
449457
(Contributed by Serhiy Storchaka in :gh:`59396`.)
450458

459+
* :class:`tkinter.scrolledtext.ScrolledText` gained a *use_ttk* parameter to use
460+
the themed :mod:`tkinter.ttk` frame and scroll bar instead of the classic
461+
:mod:`tkinter` widgets.
462+
(Contributed by Serhiy Storchaka in :gh:`59396`.)
463+
451464
* :class:`tkinter.font.Font` can now wrap a font description without creating a
452465
new named font, by passing it as *font* with ``exists=True`` and no *name*.
453466
This avoids a loss of precision in :meth:`~tkinter.font.Font.actual`,

Lib/imaplib.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,11 +950,15 @@ def search(self, charset, *criteria, uid=False):
950950
If UTF8 is enabled, charset MUST be None.
951951
If 'uid' is true, the message numbers in the response are UIDs
952952
(UID SEARCH).
953+
954+
A 'criteria' passed as str is encoded to 'charset'; pass bytes to
955+
send criteria that are already encoded.
953956
"""
954957
name = 'SEARCH'
955958
if charset is not None:
956959
if self.utf8_enabled:
957960
raise IMAP4.error("Non-None charset not valid in UTF8 mode")
961+
criteria = self._encode_criteria(charset, criteria)
958962
args = ('CHARSET', self._astring(charset), *criteria)
959963
else:
960964
args = criteria
@@ -1036,6 +1040,7 @@ def sort(self, sort_criteria, charset, *search_criteria, uid=False):
10361040
#if not name in self.capabilities: # Let the server decide!
10371041
# raise self.error('unimplemented extension command: %s' % name)
10381042
sort_criteria = self._set_quote(sort_criteria)
1043+
search_criteria = self._encode_criteria(charset, search_criteria)
10391044
if charset is not None:
10401045
charset = self._astring(charset)
10411046
args = (sort_criteria, charset, *search_criteria)
@@ -1117,6 +1122,7 @@ def thread(self, threading_algorithm, charset, *search_criteria, uid=False):
11171122
(UID THREAD).
11181123
"""
11191124
name = 'THREAD'
1125+
search_criteria = self._encode_criteria(charset, search_criteria)
11201126
if charset is not None:
11211127
charset = self._astring(charset)
11221128
args = (self._atom(threading_algorithm), charset, *search_criteria)
@@ -1158,12 +1164,14 @@ def uid(self, command, *args):
11581164
self._set_quote(flags))
11591165
elif command == 'SORT':
11601166
sort_criteria, charset, *search_criteria = args
1167+
search_criteria = self._encode_criteria(charset, search_criteria)
11611168
if charset is not None:
11621169
charset = self._astring(charset)
11631170
args = (self._set_quote(sort_criteria), charset,
11641171
*search_criteria)
11651172
elif command == 'THREAD':
11661173
threading_algorithm, charset, *search_criteria = args
1174+
search_criteria = self._encode_criteria(charset, search_criteria)
11671175
if charset is not None:
11681176
charset = self._astring(charset)
11691177
args = (self._atom(threading_algorithm), charset,
@@ -1576,6 +1584,17 @@ def _fetch_parts(self, arg):
15761584
return arg
15771585
return self._set_quote(arg)
15781586

1587+
def _encode_criteria(self, charset, criteria):
1588+
# Encode str search criteria to the declared CHARSET so the bytes on
1589+
# the wire match it. bytes criteria are already encoded and pass
1590+
# through unchanged. charset is None when no CHARSET is sent.
1591+
if charset is None:
1592+
return criteria
1593+
if isinstance(charset, (bytes, bytearray)):
1594+
charset = str(charset, 'ascii')
1595+
return tuple(c.encode(charset) if isinstance(c, str) else c
1596+
for c in criteria)
1597+
15791598
def _quote(self, arg):
15801599
if isinstance(arg, str):
15811600
arg = bytes(arg, self._encoding)

0 commit comments

Comments
 (0)