Commit 09f4f253 authored by Terry Jan Reedy's avatar Terry Jan Reedy

Issue #15618: Make turtle.py itself work when run from a module with

from __future__ import unicode_literals.  Initial patch by Juancarlo Añez.

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.
parent fd48a56b
...@@ -835,7 +835,7 @@ class Shape(object): ...@@ -835,7 +835,7 @@ class Shape(object):
if isinstance(data, list): if isinstance(data, list):
data = tuple(data) data = tuple(data)
elif type_ == "image": elif type_ == "image":
if isinstance(data, str): if isinstance(data, basestring):
if data.lower().endswith(".gif") and isfile(data): if data.lower().endswith(".gif") and isfile(data):
data = TurtleScreen._image(data) data = TurtleScreen._image(data)
# else data assumed to be Photoimage # else data assumed to be Photoimage
...@@ -1098,7 +1098,7 @@ class TurtleScreen(TurtleScreenBase): ...@@ -1098,7 +1098,7 @@ class TurtleScreen(TurtleScreenBase):
""" """
if len(color) == 1: if len(color) == 1:
color = color[0] color = color[0]
if isinstance(color, str): if isinstance(color, basestring):
if self._iscolorstring(color) or color == "": if self._iscolorstring(color) or color == "":
return color return color
else: else:
...@@ -2602,7 +2602,7 @@ class RawTurtle(TPen, TNavigator): ...@@ -2602,7 +2602,7 @@ class RawTurtle(TPen, TNavigator):
def _cc(self, args): def _cc(self, args):
"""Convert colortriples to hexstrings. """Convert colortriples to hexstrings.
""" """
if isinstance(args, str): if isinstance(args, basestring):
return args return args
try: try:
r, g, b = args r, g, b = args
...@@ -3228,7 +3228,7 @@ class RawTurtle(TPen, TNavigator): ...@@ -3228,7 +3228,7 @@ class RawTurtle(TPen, TNavigator):
""" """
#print "dot-1:", size, color #print "dot-1:", size, color
if not color: if not color:
if isinstance(size, (str, tuple)): if isinstance(size, (basestring, tuple)):
color = self._colorstr(size) color = self._colorstr(size)
size = self._pensize + max(self._pensize, 4) size = self._pensize + max(self._pensize, 4)
else: else:
...@@ -3913,7 +3913,7 @@ if __name__ == "__main__": ...@@ -3913,7 +3913,7 @@ if __name__ == "__main__":
down() down()
# some text # some text
write("startstart", 1) write("startstart", 1)
write("start", 1) write(u"start", 1)
color("red") color("red")
# staircase # staircase
for i in range(5): for i in range(5):
...@@ -3988,7 +3988,7 @@ if __name__ == "__main__": ...@@ -3988,7 +3988,7 @@ if __name__ == "__main__":
tri = getturtle() tri = getturtle()
tri.resizemode("auto") tri.resizemode("auto")
turtle = Turtle() turtle = Turtle()
turtle.resizemode("auto") turtle.resizemode(u"auto")
turtle.shape("turtle") turtle.shape("turtle")
turtle.reset() turtle.reset()
turtle.left(90) turtle.left(90)
...@@ -3998,7 +3998,7 @@ if __name__ == "__main__": ...@@ -3998,7 +3998,7 @@ if __name__ == "__main__":
turtle.lt(30) turtle.lt(30)
turtle.down() turtle.down()
turtle.speed(6) turtle.speed(6)
turtle.color("blue","orange") turtle.color("blue",u"orange")
turtle.pensize(2) turtle.pensize(2)
tri.speed(6) tri.speed(6)
setheading(towards(turtle)) setheading(towards(turtle))
...@@ -4013,9 +4013,9 @@ if __name__ == "__main__": ...@@ -4013,9 +4013,9 @@ if __name__ == "__main__":
tri.stamp() tri.stamp()
switchpen() switchpen()
count += 1 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("black")
tri.pencolor("red") tri.pencolor(u"red")
def baba(xdummy, ydummy): def baba(xdummy, ydummy):
clearscreen() clearscreen()
......
...@@ -33,6 +33,7 @@ Pehr Anderson ...@@ -33,6 +33,7 @@ Pehr Anderson
Erik Andersén Erik Andersén
Oliver Andrich Oliver Andrich
Ross Andrus Ross Andrus
Juancarlo Añez
Chris Angelico Chris Angelico
Ankur Ankan Ankur Ankan
Heidi Annexstad Heidi Annexstad
......
...@@ -40,6 +40,9 @@ Core and Builtins ...@@ -40,6 +40,9 @@ Core and Builtins
Library 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 - Issue #20501: fileinput module no longer reads whole file into memory when using
fileinput.hook_encoded. fileinput.hook_encoded.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment