From 2700fc55e3848afb33bd919f684b9a65de784038 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 23 Sep 2013 19:58:23 +0000 Subject: use utf-8 encoding for unicode strings --- (limited to 'TurtleArt') diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 8d8ed4a..ff392e0 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -555,7 +555,7 @@ class Block: if self.spr is None: return if isinstance(self.name, unicode): - self.name = self.name.encode('ascii', 'replace') + self.name = self.name.encode('utf-8') if self.name in content_blocks: n = len(self.values) if n == 0: @@ -636,7 +636,7 @@ class Block: self.svg.set_stroke_width(STANDARD_STROKE_WIDTH) self.svg.clear_docks() if isinstance(self.name, unicode): - self.name = self.name.encode('ascii', 'replace') + self.name = self.name.encode('utf-8') for k in block_styles.keys(): if self.name in block_styles[k]: if isinstance(self.block_methods[k], list): diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index 07b72d9..b0aa368 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -186,7 +186,7 @@ def find_hat(data): def _to_str(text): ''' Convert whatever to a str type ''' if isinstance(text, unicode): - return text.encode('ascii', 'replace') + return text.encode('utf-8') elif isinstance(text, str): return text else: @@ -371,7 +371,7 @@ def data_from_string(text): if isinstance(text, str): return json_load(text.replace(']],\n', ']], ')) elif isinstance(text, unicode): - text = text.encode('ascii', 'replace') + text = text.encode('utf-8') return json_load(text.replace(']],\n', ']], ')) else: print 'type error (%s) in data_from_string' % (type(text)) @@ -415,7 +415,7 @@ def save_picture(canvas, file_name): cr.set_source_surface(x_surface) cr.paint() if isinstance(file_name, unicode): - img_surface.write_to_png(str(file_name.encode('ascii', 'replace'))) + img_surface.write_to_png(str(file_name.encode('utf-8'))) else: img_surface.write_to_png(str(file_name)) diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 4e55d5b..7209dd3 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -1591,13 +1591,13 @@ before making changes to your Turtle Blocks program')) found_the_action_block = False bname = _('action') if isinstance(bname, unicode): - bname = bname.encode('ascii', 'replace') + bname = bname.encode('utf-8') for sblk in similars: cblk = sblk.connections[1] if cblk is not None: blabel = cblk.spr.labels[0] if isinstance(blabel, unicode): - blabel = blabel.encode('ascii', 'replace') + blabel = blabel.encode('utf-8') if bname == blabel: found_the_action_block = True # If there is an action block in use, change the name @@ -1825,7 +1825,7 @@ before making changes to your Turtle Blocks program')) if isinstance(name, (float, int)): return if isinstance(name, unicode): - name = name.encode('ascii', 'replace') + name = name.encode('utf-8') for blk in self.just_blocks(): if self._action_name(blk, hat=False): if blk.spr.labels[0] == self._saved_action_name: @@ -1843,7 +1843,7 @@ before making changes to your Turtle Blocks program')) if isinstance(name, (float, int)): return if isinstance(name, unicode): - name = name.encode('ascii', 'replace') + name = name.encode('utf-8') for blk in self.just_blocks(): if self._box_name(blk, storein=False): if blk.spr.labels[0] == self._saved_box_name: @@ -1861,7 +1861,7 @@ before making changes to your Turtle Blocks program')) if isinstance(name, (float, int)): return if isinstance(name, unicode): - name = name.encode('ascii', 'replace') + name = name.encode('utf-8') for blk in self.just_blocks(): if self._box_name(blk, storein=True): if blk.spr.labels[0] == self._saved_box_name: @@ -1884,11 +1884,11 @@ before making changes to your Turtle Blocks program')) # (3) The list of proto blocks on the palette # (4) The list of block names if isinstance(name, unicode): - name = name.encode('ascii', 'replace') + name = name.encode('utf-8') if isinstance(old, unicode): - old = old.encode('ascii', 'replace') + old = old.encode('utf-8') if isinstance(new, unicode): - new = new.encode('ascii', 'replace') + new = new.encode('utf-8') if old == new: ''' @@ -4066,7 +4066,7 @@ before making changes to your Turtle Blocks program')) if btype == 'string' and blk.spr is not None: value = blk.values[0] if isinstance(value, unicode): - value = value.encode('ascii', 'replace') + value = value.encode('utf-8') blk.spr.set_label(value.replace('\n', RETURN)) elif btype == 'start': # block size is saved in start block if value is not None: @@ -4541,16 +4541,16 @@ before making changes to your Turtle Blocks program')) if not self.interactive_mode: return False if isinstance(name, unicode): - name = name.encode('ascii', 'replace') + name = name.encode('utf-8') if isinstance(label, unicode): - label = label.encode('ascii', 'replace') + label = label.encode('utf-8') i = palette_name_to_index(palette) for blk in self.palettes[i]: blk_label = blk.spr.labels[0] if isinstance(blk.name, unicode): - blk.name = blk.name.encode('ascii', 'replace') + blk.name = blk.name.encode('utf-8') if isinstance(blk_label, unicode): - blk_label = blk_label.encode('ascii', 'replace') + blk_label = blk_label.encode('utf-8') if blk.name == name and blk_label == label: return True # Check labels[1] too (e.g., store in block) @@ -4567,7 +4567,7 @@ before making changes to your Turtle Blocks program')) if isinstance(name, (float, int)): return if isinstance(name, unicode): - name = name.encode('ascii', 'replace') + name = name.encode('utf-8') if name == _('action'): return # Choose a palette for the new block. @@ -4596,7 +4596,7 @@ before making changes to your Turtle Blocks program')) if isinstance(name, (float, int)): return if isinstance(name, unicode): - name = name.encode('ascii', 'replace') + name = name.encode('utf-8') if name == _('my box'): return # Choose a palette for the new block. @@ -4626,7 +4626,7 @@ before making changes to your Turtle Blocks program')) if isinstance(name, (float, int)): return if isinstance(name, unicode): - name = name.encode('ascii', 'replace') + name = name.encode('utf-8') if name == _('my box'): return # Choose a palette for the new block. -- cgit v0.9.1