diff options
author | Jesse van den Kieboom <jessevdk@gnome.org> | 2012-01-21 01:46:48 +0100 |
---|---|---|
committer | Jesse van den Kieboom <jessevdk@gnome.org> | 2012-01-21 01:46:48 +0100 |
commit | 5befd18c202fccfd8ca38689c586439b681c46e8 (patch) | |
tree | df03ce4a57c82b63b458433617a813c342c2e3d1 | |
parent | 579d445e3c3e8f593ebf902c59ba00895ce5abfc (diff) | |
download | gedit-5befd18c202fccfd8ca38689c586439b681c46e8.tar.gz |
Use unicode everywhere where necessary in snippets
-rw-r--r-- | plugins/snippets/snippets/completion.py | 2 | ||||
-rw-r--r-- | plugins/snippets/snippets/document.py | 14 | ||||
-rw-r--r-- | plugins/snippets/snippets/helper.py | 24 | ||||
-rw-r--r-- | plugins/snippets/snippets/importer.py | 2 | ||||
-rw-r--r-- | plugins/snippets/snippets/library.py | 4 | ||||
-rw-r--r-- | plugins/snippets/snippets/manager.py | 20 | ||||
-rw-r--r-- | plugins/snippets/snippets/placeholder.py | 6 | ||||
-rw-r--r-- | plugins/snippets/snippets/snippet.py | 6 |
8 files changed, 40 insertions, 38 deletions
diff --git a/plugins/snippets/snippets/completion.py b/plugins/snippets/snippets/completion.py index 4e7378cfe..bf9a4bdb4 100644 --- a/plugins/snippets/snippets/completion.py +++ b/plugins/snippets/snippets/completion.py @@ -83,7 +83,7 @@ class Provider(GObject.Object, GtkSource.CompletionProvider): if start.backward_word_start(): self.mark_position(start) - return start.get_text(it) + return unicode(start.get_text(it), 'utf-8') else: return None diff --git a/plugins/snippets/snippets/document.py b/plugins/snippets/snippets/document.py index 289f11760..86ddc239a 100644 --- a/plugins/snippets/snippets/document.py +++ b/plugins/snippets/snippets/document.py @@ -312,24 +312,24 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals): bounds = buf.get_selection_bounds() if bounds: - return buf.get_text(bounds[0], bounds[1], False) + return unicode(buf.get_text(bounds[0], bounds[1], False), 'utf-8') else: return '' def env_get_current_word(self, buf): start, end = buffer_word_boundary(buf) - return buf.get_text(start, end, False) + return unicode(buf.get_text(start, end, False), 'utf-8') def env_get_current_line(self, buf): start, end = buffer_line_boundary(buf) - return buf.get_text(start, end, False) + return unicode(buf.get_text(start, end, False), 'utf-8') def env_get_current_line_number(self, buf): start, end = buffer_line_boundary(buf) - return str(start.get_line() + 1) + return unicode(start.get_line() + 1) def env_get_document_uri(self, buf): location = buf.get_location() @@ -389,7 +389,7 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals): else: documents_uri = [] - return ' '.join(documents_uri) + return u' '.join(documents_uri) def env_get_documents_path(self, buf): toplevel = self.view.get_toplevel() @@ -405,7 +405,7 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals): else: documents_path = [] - return ' '.join(documents_path) + return u' '.join(documents_path) def update_environment(self): buf = self.view.get_buffer() @@ -534,7 +534,7 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals): tmp.forward_word_end() if tmp.equal(end): - word = buf.get_text(start, end, False) + word = unicode(buf.get_text(start, end, False), 'utf-8') else: start = end.copy() else: diff --git a/plugins/snippets/snippets/helper.py b/plugins/snippets/snippets/helper.py index ca8c40dc4..58cdb2fb6 100644 --- a/plugins/snippets/snippets/helper.py +++ b/plugins/snippets/snippets/helper.py @@ -19,6 +19,7 @@ import string from xml.sax import saxutils from xml.etree.ElementTree import * import re +import codecs from gi.repository import Gtk, Gdk @@ -90,7 +91,7 @@ def write_xml(node, f, cdata_nodes=()): assert node is not None if not hasattr(f, "write"): - f = open(f, "wb") + f = codecs.open(f, "wb", encoding="utf-8") # Encoding f.write("<?xml version='1.0' encoding='utf-8'?>\n") @@ -105,26 +106,26 @@ def _write_node(node, file, cdata_nodes=(), indent=0): tag = node.tag if node is Comment: - _write_indent(file, "<!-- %s -->\n" % saxutils.escape(node.text.encode('utf-8')), indent) + _write_indent(file, "<!-- %s -->\n" % saxutils.escape(node.text), indent) elif node is ProcessingInstruction: - _write_indent(file, "<?%s?>\n" % saxutils.escape(node.text.encode('utf-8')), indent) + _write_indent(file, "<?%s?>\n" % saxutils.escape(node.text), indent) else: items = node.items() if items or node.text or len(node): - _write_indent(file, "<" + tag.encode('utf-8'), indent) + _write_indent(file, "<" + tag, indent) if items: items.sort() # lexical order for k, v in items: - file.write(" %s=%s" % (k.encode('utf-8'), saxutils.quoteattr(v.encode('utf-8')))) + file.write(" %s=%s" % (k, saxutils.quoteattr(v))) if node.text or len(node): file.write(">") if node.text and node.text.strip() != "": if tag in cdata_nodes: file.write(_cdata(node.text)) else: - file.write(saxutils.escape(node.text.encode('utf-8'))) + file.write(saxutils.escape(node.text)) else: file.write("\n") @@ -132,19 +133,18 @@ def _write_node(node, file, cdata_nodes=(), indent=0): _write_node(n, file, cdata_nodes, indent + 1) if not len(node): - file.write("</" + tag.encode('utf-8') + ">\n") + file.write("</" + tag + ">\n") else: - _write_indent(file, "</" + tag.encode('utf-8') + ">\n", \ + _write_indent(file, "</" + tag + ">\n", \ indent) else: file.write(" />\n") if node.tail and node.tail.strip() != "": - file.write(saxutils.escape(node.tail.encode('utf-8'))) + file.write(saxutils.escape(node.tail)) -def _cdata(text, replace=string.replace): - text = text.encode('utf-8') - return '<![CDATA[' + replace(text, ']]>', ']]]]><![CDATA[>') + ']]>' +def _cdata(text): + return '<![CDATA[' + text.replace(']]>', ']]]]><![CDATA[>') + ']]>' def buffer_word_boundary(buf): iter = buf.get_iter_at_mark(buf.get_insert()) diff --git a/plugins/snippets/snippets/importer.py b/plugins/snippets/snippets/importer.py index 8b63e482c..2cf606356 100644 --- a/plugins/snippets/snippets/importer.py +++ b/plugins/snippets/snippets/importer.py @@ -92,7 +92,7 @@ class Importer: shutil.rmtree(dirname) if len(errors) > 0: - return _('The following files could not be imported: %s') % ', '.join(errors) + return _('The following files could not be imported: %s') % u', '.join(errors) def import_targz(self): self.import_archive('tar -x --gzip -f') diff --git a/plugins/snippets/snippets/library.py b/plugins/snippets/snippets/library.py index 41f4b7ee0..7cb797e99 100644 --- a/plugins/snippets/snippets/library.py +++ b/plugins/snippets/snippets/library.py @@ -138,7 +138,7 @@ class SnippetData: return if isinstance(value, list): - value = ','.join(value) + value = u','.join(value) if not self.can_modify() and self.properties[prop] != value: # ohoh, this is not can_modify, but it needs to be changed... @@ -951,7 +951,7 @@ class Library(Singleton): self.check_buffer.set_text(trigger) start, end = self.check_buffer.get_bounds() - text = self.check_buffer.get_text(start, end, False) + text = unicode(self.check_buffer.get_text(start, end, False), 'utf-8') s = start.copy() e = end.copy() diff --git a/plugins/snippets/snippets/manager.py b/plugins/snippets/snippets/manager.py index 95900f219..15d80d5c3 100644 --- a/plugins/snippets/snippets/manager.py +++ b/plugins/snippets/snippets/manager.py @@ -515,7 +515,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable): self['entry_tab_trigger'].set_text(self.snippet['tag']) self['entry_accelerator'].set_text( \ self.snippet.accelerator_display()) - self['combo_drop_targets'].get_child().set_text(', '.join(self.snippet['drop-targets'])) + self['combo_drop_targets'].get_child().set_text(u', '.join(self.snippet['drop-targets'])) buf = self['source_view_snippet'].get_buffer() buf.begin_not_undoable_action() @@ -652,7 +652,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable): def entry_tab_trigger_update_valid(self): entry = self['entry_tab_trigger'] - text = entry.get_text() + text = unicode(entry.get_text(), 'utf-8') if text and not Library().valid_tab_trigger(text): img = self['image_tab_trigger'] @@ -675,7 +675,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable): if not self.snippet: return - text = entry.get_text() + text = unicode(entry.get_text(), 'utf-8') # save tag self.snippet['tag'] = text @@ -685,7 +685,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable): if not self.snippet: return - text = entry.get_text() + text = unicode(entry.get_text(), 'utf-8') # save drop targets self.snippet['drop-targets'] = text @@ -699,8 +699,8 @@ class Manager(Gtk.Dialog, Gtk.Buildable): return buf = source_view.get_buffer() - text = buf.get_text(buf.get_start_iter(), \ - buf.get_end_iter(), False) + text = unicode(buf.get_text(buf.get_start_iter(), \ + buf.get_end_iter(), False), 'utf-8') self.snippet['text'] = text self.snippet_changed() @@ -1113,8 +1113,10 @@ class Manager(Gtk.Dialog, Gtk.Buildable): if not uris: return - if entry.get_text(): - mimes = [entry.get_text()] + text = unicode(entry.get_text(), 'utf-8') + + if text: + mimes = [text] else: mimes = [] @@ -1127,7 +1129,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable): if mime: mimes.append(mime) - entry.set_text(', '.join(mimes)) + entry.set_text(u', '.join(mimes)) self.on_entry_drop_targets_focus_out(entry, None) context.finish(True, False, timestamp) diff --git a/plugins/snippets/snippets/placeholder.py b/plugins/snippets/snippets/placeholder.py index 61727bd25..2628419cf 100644 --- a/plugins/snippets/snippets/placeholder.py +++ b/plugins/snippets/snippets/placeholder.py @@ -138,7 +138,7 @@ class Placeholder: eiter = self.end_iter() if biter and eiter: - return self.buf.get_text(self.begin_iter(), self.end_iter(), False) + return unicode(self.buf.get_text(self.begin_iter(), self.end_iter(), False), 'utf-8') else: return '' else: @@ -414,7 +414,7 @@ class PlaceholderShell(PlaceholderExpand): self.close_shell() self.remove_timeout() - self.set_text(str.join('', self.shell_output).rstrip('\n')) + self.set_text(unicode.join(u'', self.shell_output).rstrip('\n')) if self.default == None: self.default = self.get_text() @@ -564,7 +564,7 @@ class PlaceholderEval(PlaceholderExpand): self.set_text('') return - text = "def process_snippet():\n\t" + "\n\t".join(text.split("\n")) + text = "def process_snippet():\n\t" + u"\n\t".join(text.split("\n")) if 'process_snippet' in self.namespace: del self.namespace['process_snippet'] diff --git a/plugins/snippets/snippets/snippet.py b/plugins/snippets/snippets/snippet.py index b32450386..1269efdbb 100644 --- a/plugins/snippets/snippets/snippet.py +++ b/plugins/snippets/snippets/snippet.py @@ -132,7 +132,7 @@ class Snippet: if not detail: return nm else: - return nm + ' (<b>' + markup_escape(str.join(', ', detail)) + \ + return nm + ' (<b>' + markup_escape(unicode.join(u', ', detail)) + \ '</b>)' def _add_placeholder(self, placeholder): @@ -149,7 +149,7 @@ class Snippet: def _insert_text(self, text): # Insert text keeping indentation in mind - indented = unicode.join('\n' + unicode(self._indent), spaces_instead_of_tabs(self._view, text).split('\n')) + indented = unicode.join(u'\n' + self._indent, spaces_instead_of_tabs(self._view, text).split('\n')) self._view.get_buffer().insert(self._insert_iter(), indented) def _insert_iter(self): @@ -165,7 +165,7 @@ class Snippet: indent = all_indent[len(self._indent):] # Keep indentation - return unicode.join('\n' + unicode(indent), val.split('\n')) + return unicode.join(u'\n' + indent, val.split('\n')) def _create_placeholder(self, data): tabstop = data['tabstop'] |