From 09f4f253b54019fd78b8a943eaa72d7f51441f0c Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 5 Mar 2014 23:15:57 -0500 Subject: [PATCH] =?utf8?q?Issue=20#15618:=20Make=20turtle.py=20itself=20wo?= =?utf8?q?rk=20when=20run=20from=20a=20module=20with=20from=20=5F=5Ffuture?= =?utf8?q?=5F=5F=20import=20unicode=5Fliterals.=20=20Initial=20patch=20by?= =?utf8?q?=20Juancarlo=20A=C3=B1ez.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The demos at the end of turtle.py appear to be the only test, so I changed some of the strings to unicode with a u prefix. If os.path.isfile or the Tk image function have problems with Unicode input, that would be different issue. --- Lib/lib-tk/turtle.py | 18 +++++++++--------- Misc/ACKS | 1 + Misc/NEWS | 5 ++++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Lib/lib-tk/turtle.py b/Lib/lib-tk/turtle.py index f8188e1b70..8d7cdc07be 100644 --- a/Lib/lib-tk/turtle.py +++ b/Lib/lib-tk/turtle.py @@ -835,7 +835,7 @@ class Shape(object): if isinstance(data, list): data = tuple(data) elif type_ == "image": - if isinstance(data, str): + if isinstance(data, basestring): if data.lower().endswith(".gif") and isfile(data): data = TurtleScreen._image(data) # else data assumed to be Photoimage @@ -1098,7 +1098,7 @@ class TurtleScreen(TurtleScreenBase): """ if len(color) == 1: color = color[0] - if isinstance(color, str): + if isinstance(color, basestring): if self._iscolorstring(color) or color == "": return color else: @@ -2602,7 +2602,7 @@ class RawTurtle(TPen, TNavigator): def _cc(self, args): """Convert colortriples to hexstrings. """ - if isinstance(args, str): + if isinstance(args, basestring): return args try: r, g, b = args @@ -3228,7 +3228,7 @@ class RawTurtle(TPen, TNavigator): """ #print "dot-1:", size, color if not color: - if isinstance(size, (str, tuple)): + if isinstance(size, (basestring, tuple)): color = self._colorstr(size) size = self._pensize + max(self._pensize, 4) else: @@ -3913,7 +3913,7 @@ if __name__ == "__main__": down() # some text write("startstart", 1) - write("start", 1) + write(u"start", 1) color("red") # staircase for i in range(5): @@ -3988,7 +3988,7 @@ if __name__ == "__main__": tri = getturtle() tri.resizemode("auto") turtle = Turtle() - turtle.resizemode("auto") + turtle.resizemode(u"auto") turtle.shape("turtle") turtle.reset() turtle.left(90) @@ -3998,7 +3998,7 @@ if __name__ == "__main__": turtle.lt(30) turtle.down() turtle.speed(6) - turtle.color("blue","orange") + turtle.color("blue",u"orange") turtle.pensize(2) tri.speed(6) setheading(towards(turtle)) @@ -4013,9 +4013,9 @@ if __name__ == "__main__": tri.stamp() switchpen() count += 1 - tri.write("CAUGHT! ", font=("Arial", 16, "bold"), align="right") + tri.write("CAUGHT! ", font=("Arial", 16, "bold"), align=u"right") tri.pencolor("black") - tri.pencolor("red") + tri.pencolor(u"red") def baba(xdummy, ydummy): clearscreen() diff --git a/Misc/ACKS b/Misc/ACKS index 3aca0d9d08..ad47f9c984 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -33,6 +33,7 @@ Pehr Anderson Erik Andersén Oliver Andrich Ross Andrus +Juancarlo Añez Chris Angelico Ankur Ankan Heidi Annexstad diff --git a/Misc/NEWS b/Misc/NEWS index 02175d053c..f5439fcc00 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,6 +40,9 @@ Core and Builtins Library ------- +- Issue #15618: Make turtle.py compatible with 'from __future__ import + unicode_literals'. Initial patch by Juancarlo Añez. + - Issue #20501: fileinput module no longer reads whole file into memory when using fileinput.hook_encoded. @@ -53,7 +56,7 @@ Library Based on patch by Stephen Tu. - Issue #8478: Untokenizer.compat processes first token from iterator input. - Patch based on lines from Georg Brandl, Eric Snow, and Gareth Rees. + Patch based on lines from Georg Brandl, Eric Snow, and Gareth Rees. - Issue #20594: Avoid name clash with the libc function posix_close. -- 2.50.1