Changeset 8a56ab916e0a…
Parent 275dac79437c…
by
Changes to 9 files · Browse files at 8a56ab916e0a Showing diff from parent 275dac79437c Diff from another changeset...
@@ -13,7 +13,7 @@ import os
import threading
import Queue
-from hglib import HgThread, hgcmd_toq
+from hglib import HgThread, hgcmd_toq, toutf
from shlib import set_tortoise_icon, get_system_times
class CmdDialog(gtk.Dialog):
@@ -104,7 +104,7 @@ gobject.timeout_add(10, self.process_queue)
def write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = toutf(msg, 'iso-8859-1')
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
@@ -120,8 +120,7 @@ while self.hgthread.getqueue().qsize():
try:
msg = self.hgthread.getqueue().get(0)
- msg = unicode(msg, 'iso-8859-1')
- self.textbuffer.insert(enditer, msg)
+ self.textbuffer.insert(enditer, toutf(msg))
self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)
except Queue.Empty:
pass
|
@@ -33,6 +33,32 @@ finally:
demandimport.enable()
+def toutf(s):
+ """
+ Convert a string to UTF-8 encoding
+
+ Based on mercurial.util.tolocal()
+ """
+ for e in ('utf-8', util._encoding):
+ try:
+ return s.decode(e, 'strict').encode('utf-8')
+ except UnicodeDecodeError:
+ pass
+ return s.decode(util._fallbackencoding, 'replace').encode('utf-8')
+
+def fromutf(s):
+ """
+ Convert UTF-8 encoded string to local.
+
+ It's primarily used on strings converted to UTF-8 by toutf().
+ """
+ try:
+ return s.decode('utf-8').encode(util._encoding)
+ except UnicodeDecodeError:
+ pass
+ except UnicodeEncodeError:
+ pass
+ return s.decode('utf-8').encode(util._fallbackencoding)
def rootpath(path=None):
""" find Mercurial's repo root of path """
|
@@ -22,6 +22,7 @@ from merge import MergeDialog
from vis import treemodel
from vis.treeview import TreeView
+from hglib import toutf
import gtklib
|
@@ -21,7 +21,7 @@ from mercurial.repo import RepoError
from mercurial.node import *
from dialog import error_dialog, question_dialog
-from hglib import HgThread
+from hglib import HgThread, toutf
from shlib import set_tortoise_icon, shell_notify
import gtklib
@@ -173,7 +173,7 @@ self.stbar.set_status_text('hg ' + ' '.join(cmdline))
def write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = toutf(msg)
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
|
@@ -250,7 +250,7 @@ self._queue.put(msg)
def _write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = hglib.toutf(msg)
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
|
@@ -20,7 +20,7 @@ from mercurial import hg, ui, util, extensions
from mercurial.repo import RepoError
from dialog import error_dialog, question_dialog, info_dialog
-from hglib import HgThread
+from hglib import HgThread, toutf
import shlib
import gtklib
@@ -470,7 +470,7 @@ self.pathlist.append([p])
def write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = toutf(msg)
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
|
@@ -13,6 +13,8 @@ import Queue
import win32trace
+from hglib import toutf
+
class TraceLog():
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
@@ -111,7 +113,7 @@ self.queue.put(msg)
def write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = toutf(msg)
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
|
@@ -29,6 +29,24 @@ MARKED = 12
FGCOLOR = 13
+# FIXME:
+# this function is a copy of hglib.touft(), but I've
+# trouble importing hglib (resides one dir level above )
+# into this module.
+#
+# Note: Python 2.5's new import syntax causes problem
+# when importing this module from command line.
+def toutf(s):
+ """
+ Convert a string to UTF-8 encoding
+ """
+ for e in ('utf-8', util._encoding):
+ try:
+ return s.decode(e, 'strict').encode('utf-8')
+ except UnicodeDecodeError:
+ pass
+ return s.decode(util._fallbackencoding, 'replace').encode('utf-8')
+
class TreeModel(gtk.GenericTreeModel):
def __init__ (self, repo, graphdata, color_func):
@@ -86,19 +104,14 @@
summary = ctx.description().replace('\0', '')
summary = summary.split('\n')[0]
- try:
- summary = unicode(summary)
- except UnicodeDecodeError:
- summary = unicode(summary, util._fallbackencoding, 'replace')
- summary = gobject.markup_escape_text(summary)
+ summary = gobject.markup_escape_text(toutf(summary))
node = self.repo.lookup(revid)
tags = ', '.join(self.repo.nodetags(node))
if '<' in ctx.user():
- author = util.fromlocal((self.author_re.sub('',
- ctx.user()).strip(' ')))
+ author = toutf(self.author_re.sub('', ctx.user()).strip(' '))
else:
- author = util.fromlocal(util.shortuser(ctx.user()))
+ author = toutf(util.shortuser(ctx.user()))
date = strftime("%Y-%m-%d %H:%M:%S", gmtime(ctx.date()[0]))
|
Loading...