]> jfr.im git - z_archive/twitter.git/commitdiff
Merge branch 'select_num_statuses'
authorMike Verdone <redacted>
Thu, 2 Apr 2009 02:13:49 +0000 (20:13 -0600)
committerMike Verdone <redacted>
Thu, 2 Apr 2009 02:13:49 +0000 (20:13 -0600)
Conflicts:
AUTHORS

AUTHORS
twitter/ansi.py
twitter/cmdline.py

diff --git a/AUTHORS b/AUTHORS
index 89d3b6cd65d9f3a452af22b051d24168d6265301..a9732bfbb5cb463a9a72b9c10eae0235ddc2cede 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -5,4 +5,5 @@ Wes Devauld <wes@devauld.ca>
 
 Contributors:
 Horacio Duran <horacio.duran@gmail.com> (utf-8 patch for IRC bot)
+Rainer Michael Schmid (bugfix: crash when redirecting output to a file in 1.1)
 Anders Sandvig (cmdline -l, -d, and -t flags)
index 870dec2b5720fe3e98dd20a3adacb328eec7fc54..7b8f6dbd465c4762e5526c845aec68a44752049e 100644 (file)
@@ -4,6 +4,7 @@ Support for ANSI colours in command-line client.
 """
 
 import itertools
+import sys
 
 ESC = chr(0x1B)
 RESET = "0"
@@ -21,7 +22,13 @@ class ColourMap(object):
         return self._cmap[string]
 
 def cmdReset():
-    return ESC + "[0m"
+    if sys.stdout.isatty():
+        return ESC + "[0m"
+    else:
+        return ""
 
 def cmdColour(colour):
-    return ESC + "[" + colour + "m"
+    if sys.stdout.isatty():
+        return ESC + "[" + colour + "m"
+    else:
+        return ""
index 0db8feb58eb3255b6d2d7b930adbc5d2b2effc55..c70e7054cf69b88bfedac4cb19d138ffe65c5a4c 100644 (file)
@@ -202,6 +202,12 @@ class NoSuchAction(Action):
         print >> sys.stderr, "No such action: ", options['action']
         sys.exit(1)
 
+def printNicely(string):        
+    if sys.stdout.encoding:
+        print string.encode(sys.stdout.encoding, 'replace')
+    else:
+        print string.encode('utf-8')
+        
 class StatusAction(Action):
     def __call__(self, twitter, options):
         statuses = self.getStatuses(twitter, options)
@@ -209,7 +215,7 @@ class StatusAction(Action):
         for status in statuses:
             statusStr = sf(status, options)
             if statusStr.strip():
-                print statusStr.encode(sys.stdout.encoding, 'replace')
+                printNicely(statusStr)
 
 class AdminAction(Action):
     def __call__(self, twitter, options):
@@ -227,7 +233,7 @@ class AdminAction(Action):
             print
             print e
         else:
-            print af(options['action'], user).encode(sys.stdout.encoding, 'replace')
+            printNicely(af(options['action'], user))
 
 class FriendsAction(StatusAction):
     def getStatuses(self, twitter, options):