Revision: 6444
Author: russblau
Date: 2009-02-26 16:03:34 +0000 (Thu, 26 Feb 2009)
Log Message:
-----------
Trying again to fix output issues
Modified Paths:
--------------
branches/rewrite/pywikibot/bot.py
branches/rewrite/pywikibot/pagegenerators.py
branches/rewrite/pywikibot/userinterfaces/terminal_interface.py
Modified: branches/rewrite/pywikibot/bot.py
===================================================================
--- branches/rewrite/pywikibot/bot.py 2009-02-26 00:01:56 UTC (rev 6443)
+++ branches/rewrite/pywikibot/bot.py 2009-02-26 16:03:34 UTC (rev 6444)
@@ -60,8 +60,12 @@
class RotatingFileHandler(logging.handlers.RotatingFileHandler):
"""Strip trailing newlines before outputting text to file"""
def emit(self, record):
- record.msg = record.msg.rstrip("\r\n")
- logging.handlers.RotatingFileHandler.emit(self, record)
+ newrecord = logging.LogRecord(record.name, record.levelno,
+ record.pathname, record.lineno,
+ record.msg, record.args,
+ record.exc_info, record.funcName)
+ newrecord.msg = newrecord.msg.rstrip("\r\n")
+ logging.handlers.RotatingFileHandler.emit(self, newrecord)
def output(text, decoder=None, newline=True, toStdout=False, level=INFO):
Modified: branches/rewrite/pywikibot/pagegenerators.py
===================================================================
--- branches/rewrite/pywikibot/pagegenerators.py 2009-02-26 00:01:56 UTC (rev 6443)
+++ branches/rewrite/pywikibot/pagegenerators.py 2009-02-26 16:03:34 UTC (rev 6444)
@@ -955,7 +955,7 @@
gen = genFactory.getCombinedGenerator()
if gen:
for page in gen:
- pywikibot.output(page.title(), toStdout = True)
+ pywikibot.output(page.title(), level=pywikibot.STDOUT)
else:
pywikibot.showHelp()
except Exception:
Modified: branches/rewrite/pywikibot/userinterfaces/terminal_interface.py
===================================================================
--- branches/rewrite/pywikibot/userinterfaces/terminal_interface.py 2009-02-26 00:01:56 UTC (rev 6443)
+++ branches/rewrite/pywikibot/userinterfaces/terminal_interface.py 2009-02-26 16:03:34 UTC (rev 6444)
@@ -125,48 +125,6 @@
terminal, it will be replaced with a question mark or by a
transliteration.
"""
- if config.transliterate:
- # Encode unicode string in the encoding used by the user's console,
- # and decode it back to unicode. Then we can see which characters
- # can't be represented in the console encoding.
- codecedText = text.encode(config.console_encoding, 'replace'
- ).decode(config.console_encoding)
- transliteratedText = list(codecedText)
- # Note: A transliteration replacement might be longer than the
- # original character; e.g., ч is transliterated to ch.
- # the resulting list will have as many elements as there are
- # characters in the original text, but some list elements may
- # contain multiple characters
- prev = "-"
- prevchar = -1
- cursor = 0
- while cursor < len(codecedText):
- char = codecedText.find(u"?", cursor)
- if char == -1:
- break
- cursor = char + 1
- # work on characters that couldn't be encoded, but not on
- # original question marks.
- if text[char] != u"?":
- if char > 0 and prevchar != char - 1:
- prev = transliteratedText[char-1]
- try:
- transliterated = transliteration.trans(
- text[char], default='?',
- prev=prev, next=text[char+1])
- except IndexError:
- transliterated = transliteration.trans(
- text[char], default='?',
- prev=prev, next=' ')
- # transliteration was successful. The replacement
- # could consist of multiple letters.
- # mark the transliterated letters in yellow.
- transliteratedText[char] = u'\03{lightyellow}%s\03{default}' \
- % transliterated
- # save the last transliterated character
- prev = transliterated[-1:]
- prevchar = char
- text = u"".join(transliteratedText)
self.writelock.acquire()
try:
logging.log(level, text)
@@ -377,11 +335,53 @@
self.emit_raw(record, line)
def emit(self, record):
- msg = self.format(record)
+ text = self.format(record)
+ if config.transliterate:
+ # Encode unicode string in the encoding used by the user's console,
+ # and decode it back to unicode. Then we can see which characters
+ # can't be represented in the console encoding.
+ codecedText = text.encode(config.console_encoding, 'replace'
+ ).decode(config.console_encoding)
+ transliteratedText = list(codecedText)
+ # Note: A transliteration replacement might be longer than the
+ # original character; e.g., ч is transliterated to ch.
+ # the resulting list will have as many elements as there are
+ # characters in the original text, but some list elements may
+ # contain multiple characters
+ prev = "-"
+ prevchar = -1
+ cursor = 0
+ while cursor < len(codecedText):
+ char = codecedText.find(u"?", cursor)
+ if char == -1:
+ break
+ cursor = char + 1
+ # work on characters that couldn't be encoded, but not on
+ # original question marks.
+ if text[char] != u"?":
+ if char > 0 and prevchar != char - 1:
+ prev = transliteratedText[char-1]
+ try:
+ transliterated = transliteration.trans(
+ text[char], default='?',
+ prev=prev, next=text[char+1])
+ except IndexError:
+ transliterated = transliteration.trans(
+ text[char], default='?',
+ prev=prev, next=' ')
+ # transliteration was successful. The replacement
+ # could consist of multiple letters.
+ # mark the transliterated letters in yellow.
+ transliteratedText[char] = u'\03{lightyellow}%s\03{default}' \
+ % transliterated
+ # save the last transliterated character
+ prev = transliterated[-1:]
+ prevchar = char
+ text = u"".join(transliteratedText)
if config.colorized_output:
if sys.platform == 'win32':
- self.emitColorizedInWindows(record, msg)
+ self.emitColorizedInWindows(record, text)
else:
- self.emitColorizedInUnix(record, msg)
+ self.emitColorizedInUnix(record, text)
else:
- self.emit_raw(record, msg)
+ self.emit_raw(record, text)