[Pywikipedia-l] SVN: [6121] branches/rewrite/pywikibot/__init__.py

nicdumz at svn.wikimedia.org nicdumz at svn.wikimedia.org
Sun Nov 30 02:31:19 UTC 2008


Revision: 6121
Author:   nicdumz
Date:     2008-11-30 02:31:19 +0000 (Sun, 30 Nov 2008)

Log Message:
-----------
sys.stdout.encoding might be None in some contexts

Modified Paths:
--------------
    branches/rewrite/pywikibot/__init__.py

Modified: branches/rewrite/pywikibot/__init__.py
===================================================================
--- branches/rewrite/pywikibot/__init__.py	2008-11-26 20:02:30 UTC (rev 6120)
+++ branches/rewrite/pywikibot/__init__.py	2008-11-30 02:31:19 UTC (rev 6121)
@@ -106,7 +106,11 @@
 
 def input(prompt, password=False):
     if isinstance(prompt, unicode):
-        prompt = prompt.encode(sys.stdout.encoding, "xmlcharrefreplace")
+        encoding = sys.stdout.encoding
+        # Fallback to _some_ encoding for virtual consoles (cron, screen !)
+        if not encoding:
+            encoding = "UTF-8"
+        prompt = prompt.encode(encoding, "xmlcharrefreplace")
     if password:
         import getpass
         return getpass.getpass(prompt)





More information about the Pywikipedia-l mailing list