The tkinter.Variable methods trace_variable(), trace(), trace_vdelete()
and trace_vinfo(), deprecated since Python 3.14, are now scheduled for
removal in Python 3.17.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Move the compile-time optimizations (_optimize_charset, _compile_charset,
_simple, _compile_info and the literal/charset prefix helpers) out of
_compiler.py into a new Lib/re/_optimizer.py. _compiler.py keeps only the
bytecode emitter and imports them. This is groundwork for a follow-up
optimization; there is no behavior change.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Implement set difference [A--B], intersection [A&&B] and union [A||B] in
regular expression character classes (Unicode Technical Standard #18),
including nested, complemented and compound set operands. Symmetric
difference [A~~B] remains reserved.
Also use the new syntax in the standard library (_strptime, textwrap,
doctest, pkgutil).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
macOS records the caret only for the key window, so the query reads back
zeros instead of the values set in the test.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Add window methods and module functions that report curses state which could
previously only be set: the window getters is_cleared(), is_idcok(),
is_idlok(), is_immedok(), is_keypad(), is_leaveok(), is_nodelay(),
is_notimeout(), is_pad(), is_scrollok(), is_subwin(), is_syncok(),
getdelay(), getparent() and getscrreg(), and the functions is_cbreak(),
is_echo(), is_nl() and is_raw(). They are available when built against an
ncurses with NCURSES_EXT_FUNCS.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add alloc_pair(), find_pair(), free_pair() and reset_color_pairs(),
wrapping the ncurses extended-color dynamic pair management. They are
available only when built against a wide-character ncurses with
extended-color support.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CalledProcessError previously formatted cmd as `"... '%s' ..."`. This lead to
unbalanced quoting when cmd contains single-quotes or, more commonly, when cmd
is a list. This change updates the relevant format strings to use %r instead.
Co-authored-by: Benjy Wiener <benjywiener@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Run the generic DTrace/SystemTap commands in a new process group and
terminate the whole group on timeout.
This prevents a forked tracer child from keeping stdout/stderr pipes
open after the direct tracer process is killed.
Add the X/Open Curses SCREEN API for driving more than one terminal:
newterm() and set_term(), plus the ncurses extension new_prescr().
A new screen object wraps the C SCREEN. It exposes the terminal's
standard window as screen.stdscr. Each window keeps a reference to its
screen (like a subwindow does to its parent window), so the screen is
deleted automatically once it and all of its windows are unreferenced.
The ncurses use_screen()/use_window() locking helpers are exposed as
the screen.use() and window.use() methods.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
wcwidth() only classifies combining characters in a locale that can
encode them, so guard the wide-character test operations on encodability.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A character set containing exactly one category, e.g. [\d] or [^\s], now
compiles to a single CATEGORY opcode (like \d or \S) instead of an IN
block. The negated form maps to the complementary category. This speeds
up matching and reduces the size of the compiled byte code.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tcl 8.x crashes when title-casing a non-BMP character during Tk
initialization, so such a className is now rejected with a ValueError.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
The character-cell window methods now accept a full character cell -- a
spacing character optionally followed by combining characters (up to
CCHARW_MAX wide characters) -- in addition to a single int or byte
character. This affects addch(), bkgd(), bkgdset(), border(), box(),
echochar(), hline(), insch() and vline(); they dispatch to the ncursesw
wide-character functions (wadd_wch(), wbkgrnd(), wborder_set(),
wecho_wchar(), whline_set(), wins_wch(), wvline_set(), ...) when given a
string. border() and box() cannot mix integer or byte characters with
wide string characters in a single call. A cell is one spacing character
optionally followed by combining characters, so an extra spacing or
control character (such as "ab") is rejected with ValueError rather than
being silently truncated by setcchar().
Also add the wide-character read methods get_wstr() and in_wstr(), the
counterparts of getstr() and instr() that return a str rather than a
bytes object, and the module functions erasewchar(), killwchar() and
wunctrl(), the wide-character counterparts of erasechar(), killchar()
and unctrl().
All of this is available only when built against the wide-character
ncursesw library.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Character class escapes (``\d``, ``\D``, ``\s``, ``\S``, ``\w`` and
``\W``) that occur outside a character set are now compiled directly to a
single CATEGORY opcode instead of being wrapped in an IN block. This
removes the IN wrapper (three code words) and an indirect charset() call,
and makes such an escape a simple repeatable unit so that, for example,
``\d+`` uses the REPEAT_ONE fast path; a CATEGORY case is added to
SRE(count).
The transformation preserves behaviour exactly. For category-heavy
patterns the compiled byte code is about 20% smaller and matching is up
to ~2x faster, with no effect on patterns that do not use bare category
escapes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tarfile reads a member's extended header (a GNU long name/link or a pax
header) with a single read sized by the header's size field:
buf = tarfile.fileobj.read(self._block(self.size))
The size is taken from the archive and is not validated, so a ~512-byte
crafted file can claim several gigabytes (or, via base-256 encoding, far
more) and make read() pre-allocate that much memory -- on open/iterate,
before any extraction filter runs.
Read the extended-header data in bounded chunks instead, so an oversized
or truncated header can no longer force a huge allocation. The bytes
returned for valid archives are unchanged.
Rework SimpleDialog and Dialog to match the look and feel of the native Tk
dialogs ::tk_dialog and ::tk::MessageBox.
* SimpleDialog is a Python port of ::tk_dialog and Dialog a base class
modelled on ::tk::MessageBox. Both adopt the message-box keyboard
conventions: button accelerators, a default ring that follows the keyboard
focus, and a <Return> binding that invokes the focused button.
* Both classes gain a use_ttk parameter that selects the classic Tk or the
themed ttk widgets. It controls the widget set and the appearance that the
two procedures style differently, but not the keyboard behaviour.
* Update _place_window with the Tk 9.1 placement refinements.
* The new helpers _temp_grab_focus (a modal grab/focus context manager),
_underline_ampersand and _find_alt_key_target (ports of the Tk
accelerator-key procedures) can be reused by other tkinter dialogs, as
_setup_dialog already is.
* Fix several defects uncovered while comparing with the Tcl sources.
* Improve the simpledialog demo.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Arbitrary keyword arguments are now forwarded to the underlying
Menubutton and can override OptionMenu's default appearance options.
The positional API is unchanged.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Wrap the Tk 9.0 ``ttk::style theme styles ?themeName?`` subcommand as
ttk.Style.theme_styles(themename=None), returning the list of styles
defined in a theme (the current theme if themename is omitted).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Wrap three long-standing Tk commands that had no tkinter wrapper:
* Misc.tk_appname() queries or sets the name used to communicate with the
application through the send command (Tk 8.5).
* Misc.tk_useinputmethods() queries or sets whether Tk uses the X Input
Methods (XIM) for filtering events (Tk 8.5).
* Misc.tk_caret() sets or queries the per-display caret location used for
accessibility and for placing the input method window (Tk 8.5).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Add parameters mapping to Tk photo image options that previously had no
tkinter equivalent:
* the format parameter of PhotoImage.put() (Tk 8.6),
* the metadata parameter of PhotoImage.put(), read(), write() and data()
(Tk 9.0),
* the withalpha parameter of PhotoImage.get() (Tk 9.0).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Fixes issue #150162 by improving the code introduced by 70154855cf
(GH-127729) while retaining the original documented intent. The
aforementioned code has a side effect when used in a virtual environment
context, on posix platforms, with the cross-compiling environment
variable _PYTHON_PROJECT_BASE present. In this case, every single
sysconfig.get_config_vars() and sysconfig.get_config_var() call, forces
the _CONFIG_VARS dictionary to be reinitialised from scratch. This is
inefficient, but also means no changes to the dictionary returned by
sysconfig.get_config_vars() persist, which can be useful in certain
situations.
This commit tracks changes to sys.prefix and sys.exec_prefix more
directly rather than relying on a misalignment with the corresponding
sysconfig variables.
A user function that shadows the `.`/`source` builtin hijacks the
activate.fish prompt. fish resolves functions ahead of builtins, so the
`echo "exit $status" | .` line that restores the exit status pipes into
the user function instead of sourcing. Dot-style directory navigators
redefine `.`, which made the prompt list the directory on every command
and dropped the exit status handed to the original prompt.
Route every builtin the prompt path uses (`source`, `echo`, `printf`,
`set_color`, `functions`) through `builtin` so no user function can
intercept them. These have all been fish builtins with a stable
interface since fish 2.0.0, the version the script already required
through `functions --copy`, so the minimum supported fish version does
not change.
Wrap the photo image "redither" Tk command (since Tk 8.5) as the method
PhotoImage.redither(), which recalculates the dithered image in each
window where it is displayed (useful when the image data was supplied in
pieces), completing the wrapping of the photo image subcommands.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
PS1 is a parameter special to the current interactive shell. It does not
need to be exported to the environment. Exporting PS1 is not useful, and
will break different shells spawned by the current interactive shell.
Wrap three long-standing Tk commands that had no tkinter wrapper:
* Menu.postcascade() posts the submenu of a cascade entry (Tk 8.5),
complementing the existing post() and unpost() methods.
* Misc.tk_scaling() queries or sets the scaling factor in pixels per
point used to convert between physical units and pixels (Tk 8.4).
* Misc.tk_inactive() returns the user idle time in milliseconds, and can
reset that timer (Tk 8.5).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Wrap the Tk canvas commands "rchars" (replace the text or coordinates of
items, since Tk 8.6) and "rotate" (rotate the coordinates of items about
an origin, new in Tk 9.0) as the methods Canvas.rchars() and
Canvas.rotate(), complementing the existing dchars/insert and move/scale
methods.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Wrap the enhanced ttk::treeview widget commands added in Tk 9.1 (TIP 740),
and the detached query added in Tk 9.0, as tkinter.ttk.Treeview methods:
item navigation and queries (after_item, before_item, depth, haschildren,
visible, size, range, identifier, current), opening, hiding, sorting and
searching (expand, collapse, hide, unhide, sort, search, search_all,
search_cell, search_all_cells), cell focus, selection and tagging
(cellfocus, cellselection and its set/add/remove cell-list and *_range
rectangle forms, anchor/includes/present, tag_cell_add/remove/has), and the
detached query (detached, detached_all).
The expand() and collapse() methods, without recurse, also work on Tk older
than 9.1, where they are emulated via the item -open option.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>