def test_is_ascii_and_is_sjis(self): ascii = self.read(UnicodeSupportTest.PATHMAP['ascii']) sjis = self.read(UnicodeSupportTest.PATHMAP['sjis']) utf8 = self.read(UnicodeSupportTest.PATHMAP['utf8']) self.assertTrue(unicodesupport.is_ascii(ascii)) self.assertFalse(unicodesupport.is_ascii(sjis)) self.assertFalse(unicodesupport.is_ascii(utf8)) self.assertFalse(unicodesupport.is_sjis_and_not_ascii(ascii)) self.assertTrue(unicodesupport.is_sjis_and_not_ascii(sjis)) self.assertFalse(unicodesupport.is_sjis_and_not_ascii(utf8))
def test_sjis_file_to_utf8_file(self): testee_filename = UnicodeSupportTest.PATHMAP['sjis2utf8'] sjis_str = unicodesupport._a_to_b(rawstring='012345あいうえお阿修羅', src_encoding_name='utf8', dst_encoding_name='sjis') print 'creating "%s" ...' % testee_filename, if os.path.exists(testee_filename): os.remove(testee_filename) with open(testee_filename, "w") as f: f.write(sjis_str) f.close() print 'fin.' # sjis で書いたので sjis として読み込めるはず actual = self.read(testee_filename) self.assertTrue(unicodesupport.is_sjis_and_not_ascii(actual)) # utf8 に変換したので, utf8 として読み込めるはず unicodesupport.sjis_file_to_utf8_file(testee_filename) actual = self.read(testee_filename) self.assertFalse(unicodesupport.is_sjis_and_not_ascii(actual)) self.assertTrue(unicodesupport._is_hoge_encoding(actual, 'utf8'))
def _copy(self, rawstring): """ 指定文字列をクリップボードにコピーする. @retval True コピーした @retval False コピーできなかった """ if unicodesupport.is_ascii(rawstring): log.debug('COPY as ascii') return clipboard.Clipboard.set_ansi(rawstring) if unicodesupport.is_utf8_and_not_ascii(rawstring): log.debug('COPY as utf8') return clipboard.Clipboard.set_unicode( unicodesupport.to_unicodestr(rawstring) ) if unicodesupport.is_sjis_and_not_ascii(rawstring): log.debug('COPY as sjis') return clipboard.Clipboard.set_ansi(rawstring) log.debug('COPY as unknown-type') return clipboard.Clipboard.set_ansi(rawstring)