[Python-checkins] cpython (3.2): Issue #14777: In an X11 windowing environment, tkinter may return
ned.deily
python-checkins at python.org
Wed May 16 03:14:06 CEST 2012
http://hg.python.org/cpython/rev/41382250e5e1
changeset: 76975:41382250e5e1
branch: 3.2
parent: 76972:48cb6b67d306
user: Ned Deily <nad at acm.org>
date: Tue May 15 18:08:11 2012 -0700
summary:
Issue #14777: In an X11 windowing environment, tkinter may return
undecoded UTF-8 bytes as a string when accessing the Tk clipboard.
Modify clipboad_get() to first request type UTF8_STRING when no
specific type is requested in an X11 windowing environment, falling
back to the current default type STRING if that fails.
Original patch by Thomas Kluyver.
files:
Lib/tkinter/__init__.py | 28 ++++++++++++++++++++++++++--
Misc/NEWS | 6 ++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -526,12 +526,19 @@
The type keyword specifies the form in which the data is
to be returned and should be an atom name such as STRING
- or FILE_NAME. Type defaults to STRING.
+ or FILE_NAME. Type defaults to STRING, except on X11, where the default
+ is to try UTF8_STRING and fall back to STRING.
This command is equivalent to:
selection_get(CLIPBOARD)
"""
+ if 'type' not in kw and self._windowingsystem == 'x11':
+ try:
+ kw['type'] = 'UTF8_STRING'
+ return self.tk.call(('clipboard', 'get') + self._options(kw))
+ except TclError:
+ del kw['type']
return self.tk.call(('clipboard', 'get') + self._options(kw))
def clipboard_clear(self, **kw):
@@ -613,8 +620,16 @@
A keyword parameter selection specifies the name of
the selection and defaults to PRIMARY. A keyword
parameter displayof specifies a widget on the display
- to use."""
+ to use. A keyword parameter type specifies the form of data to be
+ fetched, defaulting to STRING except on X11, where UTF8_STRING is tried
+ before STRING."""
if 'displayof' not in kw: kw['displayof'] = self._w
+ if 'type' not in kw and self._windowingsystem == 'x11':
+ try:
+ kw['type'] = 'UTF8_STRING'
+ return self.tk.call(('selection', 'get') + self._options(kw))
+ except TclError:
+ del kw['type']
return self.tk.call(('selection', 'get') + self._options(kw))
def selection_handle(self, command, **kw):
"""Specify a function COMMAND to call if the X
@@ -1029,6 +1044,15 @@
if displayof is None:
return ('-displayof', self._w)
return ()
+ @property
+ def _windowingsystem(self):
+ """Internal function."""
+ try:
+ return self._root()._windowingsystem_cached
+ except AttributeError:
+ ws = self._root()._windowingsystem_cached = \
+ self.tk.call('tk', 'windowingsystem')
+ return ws
def _options(self, cnf, kw = None):
"""Internal function."""
if kw:
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,12 @@
Library
-------
+- Issue #14777: tkinter may return undecoded UTF-8 bytes as a string when
+ accessing the Tk clipboard. Modify clipboad_get() to first request type
+ UTF8_STRING when no specific type is requested in an X11 windowing
+ environment, falling back to the current default type STRING if that fails.
+ Original patch by Thomas Kluyver.
+
- Issue #12541: Be lenient with quotes around Realm field of HTTP Basic
Authentation in urllib2.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list