mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #21580: Now Tkinter correctly handles bytes arguments passed to Tk.
In particular this allows to initialize images from binary data.
This commit is contained in:
commit
f44611cadf
4 changed files with 20 additions and 16 deletions
|
@ -389,8 +389,12 @@ class TclTest(unittest.TestCase):
|
||||||
self.assertEqual(passValue('str\x00ing'), 'str\x00ing')
|
self.assertEqual(passValue('str\x00ing'), 'str\x00ing')
|
||||||
self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd')
|
self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd')
|
||||||
self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac')
|
self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac')
|
||||||
self.assertEqual(passValue(b'str\x00ing'), 'str\x00ing')
|
self.assertEqual(passValue(b'str\x00ing'),
|
||||||
self.assertEqual(passValue(b'str\xc0\x80ing'), 'str\x00ing')
|
b'str\x00ing' if self.wantobjects else 'str\x00ing')
|
||||||
|
self.assertEqual(passValue(b'str\xc0\x80ing'),
|
||||||
|
b'str\xc0\x80ing' if self.wantobjects else 'str\xc0\x80ing')
|
||||||
|
self.assertEqual(passValue(b'str\xbding'),
|
||||||
|
b'str\xbding' if self.wantobjects else 'str\xbding')
|
||||||
for i in (0, 1, -1, 2**31-1, -2**31):
|
for i in (0, 1, -1, 2**31-1, -2**31):
|
||||||
self.assertEqual(passValue(i), i if self.wantobjects else str(i))
|
self.assertEqual(passValue(i), i if self.wantobjects else str(i))
|
||||||
for f in (0.0, 1.0, -1.0, 1/3,
|
for f in (0.0, 1.0, -1.0, 1/3,
|
||||||
|
@ -440,12 +444,14 @@ class TclTest(unittest.TestCase):
|
||||||
check('string\xbd', 'string\xbd')
|
check('string\xbd', 'string\xbd')
|
||||||
check('string\u20ac', 'string\u20ac')
|
check('string\u20ac', 'string\u20ac')
|
||||||
check(b'string', 'string')
|
check(b'string', 'string')
|
||||||
check(b'string\xe2\x82\xac', 'string\u20ac')
|
check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
|
||||||
|
check(b'string\xbd', 'string\xbd')
|
||||||
check('str\x00ing', 'str\x00ing')
|
check('str\x00ing', 'str\x00ing')
|
||||||
check('str\x00ing\xbd', 'str\x00ing\xbd')
|
check('str\x00ing\xbd', 'str\x00ing\xbd')
|
||||||
check('str\x00ing\u20ac', 'str\x00ing\u20ac')
|
check('str\x00ing\u20ac', 'str\x00ing\u20ac')
|
||||||
check(b'str\xc0\x80ing', 'str\x00ing')
|
check(b'str\x00ing', 'str\x00ing')
|
||||||
check(b'str\xc0\x80ing\xe2\x82\xac', 'str\x00ing\u20ac')
|
check(b'str\xc0\x80ing', 'str\xc0\x80ing')
|
||||||
|
check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac')
|
||||||
for i in (0, 1, -1, 2**31-1, -2**31):
|
for i in (0, 1, -1, 2**31-1, -2**31):
|
||||||
check(i, str(i))
|
check(i, str(i))
|
||||||
for f in (0.0, 1.0, -1.0):
|
for f in (0.0, 1.0, -1.0):
|
||||||
|
@ -493,9 +499,9 @@ class TclTest(unittest.TestCase):
|
||||||
if tcl_version >= (8, 5):
|
if tcl_version >= (8, 5):
|
||||||
if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
|
if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
|
||||||
# Before 8.5.5 dicts were converted to lists through string
|
# Before 8.5.5 dicts were converted to lists through string
|
||||||
expected = ('12', '\u20ac', '\u20ac', '3.4')
|
expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4')
|
||||||
else:
|
else:
|
||||||
expected = (12, '\u20ac', '\u20ac', (3.4,))
|
expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,))
|
||||||
testcases += [
|
testcases += [
|
||||||
(call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
|
(call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
|
||||||
expected),
|
expected),
|
||||||
|
@ -543,9 +549,9 @@ class TclTest(unittest.TestCase):
|
||||||
if tcl_version >= (8, 5):
|
if tcl_version >= (8, 5):
|
||||||
if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
|
if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
|
||||||
# Before 8.5.5 dicts were converted to lists through string
|
# Before 8.5.5 dicts were converted to lists through string
|
||||||
expected = ('12', '\u20ac', '\u20ac', '3.4')
|
expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4')
|
||||||
else:
|
else:
|
||||||
expected = (12, '\u20ac', '\u20ac', (3.4,))
|
expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,))
|
||||||
testcases += [
|
testcases += [
|
||||||
(call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
|
(call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
|
||||||
expected),
|
expected),
|
||||||
|
|
|
@ -161,21 +161,18 @@ class PhotoImageTest(unittest.TestCase):
|
||||||
def test_create_from_ppm_file(self):
|
def test_create_from_ppm_file(self):
|
||||||
self.check_create_from_file('ppm')
|
self.check_create_from_file('ppm')
|
||||||
|
|
||||||
@unittest.skip('issue #21580')
|
|
||||||
def test_create_from_ppm_data(self):
|
def test_create_from_ppm_data(self):
|
||||||
self.check_create_from_data('ppm')
|
self.check_create_from_data('ppm')
|
||||||
|
|
||||||
def test_create_from_pgm_file(self):
|
def test_create_from_pgm_file(self):
|
||||||
self.check_create_from_file('pgm')
|
self.check_create_from_file('pgm')
|
||||||
|
|
||||||
@unittest.skip('issue #21580')
|
|
||||||
def test_create_from_pgm_data(self):
|
def test_create_from_pgm_data(self):
|
||||||
self.check_create_from_data('pgm')
|
self.check_create_from_data('pgm')
|
||||||
|
|
||||||
def test_create_from_gif_file(self):
|
def test_create_from_gif_file(self):
|
||||||
self.check_create_from_file('gif')
|
self.check_create_from_file('gif')
|
||||||
|
|
||||||
@unittest.skip('issue #21580')
|
|
||||||
def test_create_from_gif_data(self):
|
def test_create_from_gif_data(self):
|
||||||
self.check_create_from_data('gif')
|
self.check_create_from_data('gif')
|
||||||
|
|
||||||
|
@ -183,12 +180,10 @@ class PhotoImageTest(unittest.TestCase):
|
||||||
def test_create_from_png_file(self):
|
def test_create_from_png_file(self):
|
||||||
self.check_create_from_file('png')
|
self.check_create_from_file('png')
|
||||||
|
|
||||||
@unittest.skip('issue #21580')
|
|
||||||
@requires_tcl(8, 6)
|
@requires_tcl(8, 6)
|
||||||
def test_create_from_png_data(self):
|
def test_create_from_png_data(self):
|
||||||
self.check_create_from_data('png')
|
self.check_create_from_data('png')
|
||||||
|
|
||||||
@unittest.skip('issue #21580')
|
|
||||||
def test_configure_data(self):
|
def test_configure_data(self):
|
||||||
image = tkinter.PhotoImage('::img::test', master=self.root)
|
image = tkinter.PhotoImage('::img::test', master=self.root)
|
||||||
self.assertEqual(image['data'], '')
|
self.assertEqual(image['data'], '')
|
||||||
|
|
|
@ -113,6 +113,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #21580: Now Tkinter correctly handles bytes arguments passed to Tk.
|
||||||
|
In particular this allows to initialize images from binary data.
|
||||||
|
|
||||||
- Issue #22003: When initialized from a bytes object, io.BytesIO() now
|
- Issue #22003: When initialized from a bytes object, io.BytesIO() now
|
||||||
defers making a copy until it is mutated, improving performance and
|
defers making a copy until it is mutated, improving performance and
|
||||||
memory use on some use cases. Patch by David Wilson.
|
memory use on some use cases. Patch by David Wilson.
|
||||||
|
|
|
@ -901,8 +901,8 @@ AsObj(PyObject *value)
|
||||||
int overflow;
|
int overflow;
|
||||||
|
|
||||||
if (PyBytes_Check(value))
|
if (PyBytes_Check(value))
|
||||||
return Tcl_NewStringObj(PyBytes_AS_STRING(value),
|
return Tcl_NewByteArrayObj((unsigned char *)PyBytes_AS_STRING(value),
|
||||||
PyBytes_GET_SIZE(value));
|
PyBytes_GET_SIZE(value));
|
||||||
else if (PyBool_Check(value))
|
else if (PyBool_Check(value))
|
||||||
return Tcl_NewBooleanObj(PyObject_IsTrue(value));
|
return Tcl_NewBooleanObj(PyObject_IsTrue(value));
|
||||||
else if (PyLong_CheckExact(value) &&
|
else if (PyLong_CheckExact(value) &&
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue