Author: andar

Revision: 5894

Log:
        Fix displaying non-ascii strings in the console ui -- patch from Ian 
Martin

Diff:
Modified: branches/1.2_RC/ChangeLog
===================================================================
--- branches/1.2_RC/ChangeLog   2009-10-30 00:15:22 UTC (rev 5893)
+++ branches/1.2_RC/ChangeLog   2009-10-30 18:00:13 UTC (rev 5894)
@@ -17,6 +17,9 @@
        * Fix displaying the protocol upload speed
        * Fix #990, showing 0 as a limit when it means unlimited in the 
statusbar
 
+==== Console ====
+       * Fix displaying non-ascii strings
+       
 === Deluge 1.2.0_rc2 (25 October 2009) ===
 ==== GtkUI ====
        * Fix path errors when adding torrents externally in Windows

Modified: branches/1.2_RC/deluge/ui/console/commands/info.py
===================================================================
--- branches/1.2_RC/deluge/ui/console/commands/info.py  2009-10-30 00:15:22 UTC 
(rev 5893)
+++ branches/1.2_RC/deluge/ui/console/commands/info.py  2009-10-30 18:00:13 UTC 
(rev 5894)
@@ -201,7 +201,7 @@
                     s += peer["country"] + "\t"
                     s += peer["ip"]
 
-                    c = peer["client"].encode(sys.getdefaultencoding(), 
"replace")
+                    c = peer["client"]
                     s += "\t" + c
 
                     if len(c) < 16:

Modified: branches/1.2_RC/deluge/ui/console/main.py
===================================================================
--- branches/1.2_RC/deluge/ui/console/main.py   2009-10-30 00:15:22 UTC (rev 
5893)
+++ branches/1.2_RC/deluge/ui/console/main.py   2009-10-30 18:00:13 UTC (rev 
5894)
@@ -37,6 +37,7 @@
 import os, sys
 import optparse
 import shlex
+import locale
 
 from twisted.internet import defer, reactor
 
@@ -137,6 +138,14 @@
 class ConsoleUI(component.Component):
     def __init__(self, args=None):
         component.Component.__init__(self, "ConsoleUI", 2)
+        
+        try:
+            locale.setlocale(locale.LC_ALL, '')
+            self.encoding = locale.getpreferredencoding()
+        except:
+            self.encoding = sys.getdefaultencoding()
+        
+        log.debug("Using encoding: %s", self.encoding)
         # Load all the commands
         self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
 
@@ -191,7 +200,7 @@
         # We want to do an interactive session, so start up the curses screen 
and
         # pass it the function that handles commands
         colors.init_colors()
-        self.screen = screen.Screen(stdscr, self.do_command, 
self.tab_completer)
+        self.screen = screen.Screen(stdscr, self.do_command, 
self.tab_completer, self.encoding)
         self.statusbars = StatusBars()
         self.eventlog = EventLog()
 

Modified: branches/1.2_RC/deluge/ui/console/screen.py
===================================================================
--- branches/1.2_RC/deluge/ui/console/screen.py 2009-10-30 00:15:22 UTC (rev 
5893)
+++ branches/1.2_RC/deluge/ui/console/screen.py 2009-10-30 18:00:13 UTC (rev 
5894)
@@ -33,6 +33,7 @@
 #
 #
 
+import sys
 import curses
 import colors
 try:
@@ -63,7 +64,7 @@
 INPUT_HISTORY_SIZE = 500
 
 class Screen(CursesStdIO):
-    def __init__(self, stdscr, command_parser, tab_completer=None):
+    def __init__(self, stdscr, command_parser, tab_completer=None, 
encoding=None):
         """
         A curses screen designed to run as a reader in a twisted reactor.
 
@@ -110,6 +111,11 @@
         except Exception, e:
             log.debug("Unable to catch SIGWINCH signal!")
 
+        if not encoding:
+            self.encoding = sys.getdefaultencoding()
+        else:
+            self.encoding = encoding
+            
         # Do a refresh right away to draw the screen
         self.refresh()
 
@@ -233,6 +239,9 @@
             if index + 1 == len(parsed):
                 # This is the last string so lets append some " " to it
                 s += " " * (self.cols - (col + len(s)) - 1)
+            if isinstance(s, unicode):
+                #Have to use replace as character counting has already been 
done
+                s = s.encode(self.encoding, 'replace')
             self.stdscr.addstr(row, col, s, color)
             col += len(s)
 

Modified: trunk/deluge/ui/console/commands/info.py
===================================================================
--- trunk/deluge/ui/console/commands/info.py    2009-10-30 00:15:22 UTC (rev 
5893)
+++ trunk/deluge/ui/console/commands/info.py    2009-10-30 18:00:13 UTC (rev 
5894)
@@ -201,7 +201,7 @@
                     s += peer["country"] + "\t"
                     s += peer["ip"]
 
-                    c = peer["client"].encode(sys.getdefaultencoding(), 
"replace")
+                    c = peer["client"]
                     s += "\t" + c
 
                     if len(c) < 16:

Modified: trunk/deluge/ui/console/main.py
===================================================================
--- trunk/deluge/ui/console/main.py     2009-10-30 00:15:22 UTC (rev 5893)
+++ trunk/deluge/ui/console/main.py     2009-10-30 18:00:13 UTC (rev 5894)
@@ -37,6 +37,7 @@
 import os, sys
 import optparse
 import shlex
+import locale
 
 from twisted.internet import defer, reactor
 
@@ -137,6 +138,14 @@
 class ConsoleUI(component.Component):
     def __init__(self, args=None):
         component.Component.__init__(self, "ConsoleUI", 2)
+        
+        try:
+            locale.setlocale(locale.LC_ALL, '')
+            self.encoding = locale.getpreferredencoding()
+        except:
+            self.encoding = sys.getdefaultencoding()
+        
+        log.debug("Using encoding: %s", self.encoding)
         # Load all the commands
         self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
 
@@ -191,7 +200,7 @@
         # We want to do an interactive session, so start up the curses screen 
and
         # pass it the function that handles commands
         colors.init_colors()
-        self.screen = screen.Screen(stdscr, self.do_command, 
self.tab_completer)
+        self.screen = screen.Screen(stdscr, self.do_command, 
self.tab_completer, self.encoding)
         self.statusbars = StatusBars()
         self.eventlog = EventLog()
 

Modified: trunk/deluge/ui/console/screen.py
===================================================================
--- trunk/deluge/ui/console/screen.py   2009-10-30 00:15:22 UTC (rev 5893)
+++ trunk/deluge/ui/console/screen.py   2009-10-30 18:00:13 UTC (rev 5894)
@@ -33,6 +33,7 @@
 #
 #
 
+import sys
 import curses
 import colors
 try:
@@ -63,7 +64,7 @@
 INPUT_HISTORY_SIZE = 500
 
 class Screen(CursesStdIO):
-    def __init__(self, stdscr, command_parser, tab_completer=None):
+    def __init__(self, stdscr, command_parser, tab_completer=None, 
encoding=None):
         """
         A curses screen designed to run as a reader in a twisted reactor.
 
@@ -110,6 +111,11 @@
         except Exception, e:
             log.debug("Unable to catch SIGWINCH signal!")
 
+        if not encoding:
+            self.encoding = sys.getdefaultencoding()
+        else:
+            self.encoding = encoding
+            
         # Do a refresh right away to draw the screen
         self.refresh()
 
@@ -233,6 +239,9 @@
             if index + 1 == len(parsed):
                 # This is the last string so lets append some " " to it
                 s += " " * (self.cols - (col + len(s)) - 1)
+            if isinstance(s, unicode):
+                #Have to use replace as character counting has already been 
done
+                s = s.encode(self.encoding, 'replace')
             self.stdscr.addstr(row, col, s, color)
             col += len(s)
 



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to