Changeset 1456
- Timestamp:
- 07/05/08 09:42:59 (5 months ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
peppy/stcbase.py (modified) (3 diffs)
-
tests/test_unicode.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/peppy/stcbase.py
r1454 r1456 1 1 # peppy Copyright (c) 2006-2008 Rob McMullen 2 2 # Licenced under the GPLv2; see http://peppy.flipturn.org for more info 3 import os, re, time 3 import os, re, time, codecs 4 4 5 5 import wx … … 219 219 220 220 if encoding: 221 self.refstc.encoding = encoding 221 # Normalize the encoding name by running it through the codecs list 222 self.refstc.encoding = codecs.lookup(encoding).name 222 223 if not self.refstc.encoding: 223 224 self.refstc.encoding = detectEncoding(header) … … 305 306 self.refstc.encoding = encoding 306 307 self.decodeText(txt) 308 elif self.refstc.encoding: 309 if self.refstc.encoding != 'utf-8': 310 txt = txt.encode(self.refstc.encoding) 307 311 else: 308 312 # Have to use GetStyledText because GetText will truncate the -
trunk/tests/test_unicode.py
r1039 r1456 18 18 self.utf8 = '# -*- coding: UTF-8 -*-\naacute:\xc3\xa1 ntilde:\xc3\xb1' 19 19 self.latin1= '# -*- coding: latin-1 -*-\n' + ''.join([chr(i) for i in range(160, 255)]) 20 self.latin1_unmarked= ''.join([chr(i) for i in range(160, 255)]) 20 21 21 22 def testUTF8(self): … … 27 28 28 29 def testChangeLatin(self): 29 self.stc. encoding = detectEncoding(self.utf8)30 print self.stc. encoding30 self.stc.refstc.encoding = detectEncoding(self.utf8) 31 print self.stc.refstc.encoding 31 32 self.stc.decodeText(self.utf8) 32 33 unicode1 = self.stc.GetLine(1) … … 43 44 44 45 def testLatin1(self): 45 self.stc. encoding = detectEncoding(self.latin1)46 self.stc.refstc.encoding = detectEncoding(self.latin1) 46 47 print repr(self.latin1) 47 48 utf8 = unicode(self.latin1, "iso-8859-1").encode('utf-8') … … 51 52 self.stc.decodeText(self.latin1) 52 53 print repr(self.stc.GetText()) 54 print self.stc.refstc.encoding 53 55 self.stc.prepareEncoding() 54 56 print "encoded: " + repr(self.stc.refstc.encoded) 55 57 assert self.latin1 == self.stc.refstc.encoded 58 59 def testLatin1Unmarked(self): 60 self.stc.refstc.encoding = detectEncoding(self.latin1_unmarked) 61 print repr(self.latin1_unmarked) 62 utf8 = self.latin1_unmarked.decode('latin-1') 63 print repr(utf8) 64 print repr(utf8.encode('latin-1')) 65 assert utf8.encode('latin-1') == self.latin1_unmarked 66 self.stc.decodeText(self.latin1_unmarked) 67 print repr(self.stc.GetText()) 68 # There's no encoding marker in the text, so there shouldn't be an 69 # encoding listed 70 assert self.stc.refstc.encoding == None 71 self.stc.prepareEncoding() 72 print "encoded: " + repr(self.stc.refstc.encoded) 73 assert self.latin1_unmarked == self.stc.refstc.encoded
