[pywin32-checkins] pywin32/Pythonwin/pywin/framework interact.py, 1.20, 1.21
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Mark H. <mha...@us...> - 2009-01-31 03:52:45
|
Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/framework In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22805/pywin/framework Modified Files: interact.py Log Message: do syntax coloring on the raw utf8 stream Index: interact.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/framework/interact.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** interact.py 3 Jan 2009 05:52:28 -0000 1.20 --- interact.py 31 Jan 2009 03:52:39 -0000 1.21 *************** *** 116,120 **** if lengthDoc == 0: return state = styleStart ! chNext = cdoc[0] startSeg = 0 i = 0 --- 116,124 ---- if lengthDoc == 0: return state = styleStart ! # As per comments in Colorize(), we work with the raw utf8 ! # bytes. To avoid too muych py3k pain, we treat each utf8 byte ! # as a latin-1 unicode character - we only use it to compare ! # against ascii chars anyway... ! chNext = cdoc[0:1].decode('latin-1') startSeg = 0 i = 0 *************** *** 122,126 **** while i < lengthDoc: ch = chNext ! chNext = cdoc[i+1:i+2] # trace("ch=%r, i=%d, next=%r, state=%s" % (ch, i, chNext, state)) --- 126,130 ---- while i < lengthDoc: ch = chNext ! chNext = cdoc[i+1:i+2].decode('latin-1') # trace("ch=%r, i=%d, next=%r, state=%s" % (ch, i, chNext, state)) *************** *** 176,180 **** # and ask the Python colorizer to color that. end = startSeg ! while end < lengthDoc and cdoc[end] not in '\r\n': end = end + 1 self.ColorizePythonCode( cdoc[:end], startSeg, state) --- 180,184 ---- # and ask the Python colorizer to color that. end = startSeg ! while end < lengthDoc and cdoc[end] not in '\r\n'.encode('ascii'): end = end + 1 self.ColorizePythonCode( cdoc[:end], startSeg, state) *************** *** 186,190 **** startSeg =end i = end - 1 # ready for increment. ! chNext = cdoc[end:end+1] state = STYLE_INTERACTIVE_EOL if lastState != state: --- 190,194 ---- startSeg =end i = end - 1 # ready for increment. ! chNext = cdoc[end:end+1].decode('latin-1') state = STYLE_INTERACTIVE_EOL if lastState != state: *************** *** 196,200 **** def Colorize(self, start=0, end=-1): ! stringVal = self.scintilla.GetTextRange(start, end) styleStart = None stylePyStart = None --- 200,208 ---- def Colorize(self, start=0, end=-1): ! # scintilla's formatting is all done in terms of utf, so ! # we work with utf8 bytes instead of unicode. This magically ! # works as any extended chars found in the utf8 don't change ! # the semantics. ! stringVal = self.scintilla.GetTextRange(start, end, decode=False) styleStart = None stylePyStart = None *************** *** 303,315 **** if line==-1: line = self.LineFromChar() line = self.GetLine(line) - if pywin.is_platform_unicode: - try: - line = unicode(line, pywin.default_scintilla_encoding).encode(pywin.default_platform_encoding) - except: - # We should fix the underlying problem rather than always masking errors - # so make it complain. - print "Unicode error converting", repr(line) - line = unicode(line, pywin.default_scintilla_encoding, "ignore").encode(pywin.default_platform_encoding) - while line and line[-1] in ['\r', '\n']: line = line[:-1] --- 311,314 ---- |