File ibus-googlepinyin-python3.patch of Package ibus-googlepinyin
Index: ibus-googlepinyin/engine.py
===================================================================
--- ibus-googlepinyin.orig/engine.py
+++ ibus-googlepinyin/engine.py
@@ -45,9 +45,9 @@ import os, sys
import gettext
if os.path.isdir(os.path.dirname(sys.argv[0]) + '/../build/mo'):
- gettext.install(app, os.path.dirname(sys.argv[0]) + '/../build/mo', unicode=True)
+ gettext.install(app, os.path.dirname(sys.argv[0]) + '/../build/mo', str=True)
else:
- gettext.install(app, unicode=True)
+ gettext.install(app, str=True)
import time
import atexit
@@ -62,7 +62,7 @@ class Engine(ibus.EngineBase):
super(Engine, self).__init__(bus, object_path)
im_open_decoder()
self.__is_invalidate = False
- self.__prepinyin_string = u""
+ self.__prepinyin_string = ""
self.__lookup_table = ibus.LookupTable()
self.__lookup_table.set_page_size(5)
@@ -78,13 +78,13 @@ class Engine(ibus.EngineBase):
# init properties
self.__prop_list = ibus.PropList()
- self.__status_property = ibus.Property(u"status")
+ self.__status_property = ibus.Property("status")
self.__prop_list.append(self.__status_property)
- self.__letter_property = ibus.Property(u"full_letter")
+ self.__letter_property = ibus.Property("full_letter")
self.__prop_list.append(self.__letter_property)
- self.__punct_property = ibus.Property(u"full_punct")
+ self.__punct_property = ibus.Property("full_punct")
self.__prop_list.append(self.__punct_property)
- self.__trad_chinese_property = ibus.Property(u"_trad chinese")
+ self.__trad_chinese_property = ibus.Property("_trad chinese")
if globals().get('libopencc'):
self.__prop_list.append(self.__trad_chinese_property)
pass
@@ -93,44 +93,44 @@ class Engine(ibus.EngineBase):
try:
self.__refresh_properties2()
except e:
- print e
+ print(e)
def __refresh_properties2(self):
if self.__mode == 1: # refresh mode
self.__status_property.icon = path.join(IBUS_GOOGLEPINYIN_LOCATION, "icons", "chinese.svg")
- self.__status_property.label = _(u"CN")
- self.__status_property.tooltip = _(u"Switch to English mode")
+ self.__status_property.label = _("CN")
+ self.__status_property.tooltip = _("Switch to English mode")
else:
self.__status_property.icon = path.join(IBUS_GOOGLEPINYIN_LOCATION, "icons", "english.svg")
- self.__status_property.label = _(u"EN")
- self.__status_property.tooltip = _(u"Switch to Chinese mode")
+ self.__status_property.label = _("EN")
+ self.__status_property.tooltip = _("Switch to Chinese mode")
if self.__full_width_letter[self.__mode]:
self.__letter_property.icon = path.join(IBUS_GOOGLEPINYIN_LOCATION, "icons", "full-letter.svg")
- self.__letter_property.label = u"Aa"
- self.__letter_property.tooltip = _(u"Switch to half letter mode")
+ self.__letter_property.label = "Aa"
+ self.__letter_property.tooltip = _("Switch to half letter mode")
else:
self.__letter_property.icon = path.join(IBUS_GOOGLEPINYIN_LOCATION, "icons", "half-letter.svg")
- self.__letter_property.label = u"Aa"
- self.__letter_property.tooltip = _(u"Switch to full letter mode")
+ self.__letter_property.label = "Aa"
+ self.__letter_property.tooltip = _("Switch to full letter mode")
if self.__full_width_punct[self.__mode]:
self.__punct_property.icon = path.join(IBUS_GOOGLEPINYIN_LOCATION, "icons", "full-punct.svg")
- self.__punct_property.label = u",。"
- self.__punct_property.tooltip = _(u"Switch to half punctuation mode")
+ self.__punct_property.label = ",。"
+ self.__punct_property.tooltip = _("Switch to half punctuation mode")
else:
self.__punct_property.icon = path.join(IBUS_GOOGLEPINYIN_LOCATION, "icons", "half-punct.svg")
- self.__punct_property.label = u".,"
- self.__punct_property.tooltip = _(u"Switch to full punctuation mode")
+ self.__punct_property.label = ".,"
+ self.__punct_property.tooltip = _("Switch to full punctuation mode")
if self.__trad_chinese[self.__mode]:
self.__trad_chinese_property.icon = path.join(IBUS_GOOGLEPINYIN_LOCATION, "icons", "trad-chinese.svg")
- self.__trad_chinese_property.label = u",。"
- self.__trad_chinese_property.tooltip = _(u"Switch to Traditional Chinese mode")
+ self.__trad_chinese_property.label = ",。"
+ self.__trad_chinese_property.tooltip = _("Switch to Traditional Chinese mode")
else:
self.__trad_chinese_property.icon = path.join(IBUS_GOOGLEPINYIN_LOCATION, "icons", "simp-chinese.svg")
- self.__trad_chinese_property.label = u".,"
- self.__trad_chinese_property.tooltip = _(u"Switch to Simplified Chinese mode")
+ self.__trad_chinese_property.label = ".,"
+ self.__trad_chinese_property.tooltip = _("Switch to Simplified Chinese mode")
properties =(
self.__status_property,
@@ -157,7 +157,7 @@ class Engine(ibus.EngineBase):
__last_im_flush_cache_time = 0
__candidate_num = 0
__lookup_candidate_num = 0
- __prev_char = u''
+ __prev_char = ''
def process_key_event(self, keyval, keycode, state):
## for key release events
@@ -177,7 +177,7 @@ class Engine(ibus.EngineBase):
if self.__is_input_english():
if ascii.isprint(chr(keyval)) and self.__full_width_letter[self.__mode] :
- c = unichr(keyval)
+ c = chr(keyval)
c = ibus.unichar_half_to_full(c)
self.__commit_string(c)
return True
@@ -186,14 +186,14 @@ class Engine(ibus.EngineBase):
if self.__prepinyin_string:
if keyval == keysyms.Return:
if self.__full_width_letter[self.__mode]:
- self.__prepinyin_string = u''.join(
+ self.__prepinyin_string = ''.join(
(ibus.unichar_half_to_full(c) for c in self.__prepinyin_string)
)
pass
self.__commit_string(self.__prepinyin_string)
return True
elif keyval == keysyms.Escape:
- self.__prepinyin_string = u""
+ self.__prepinyin_string = ""
self.__update()
return True
elif keyval == keysyms.BackSpace:
@@ -244,21 +244,21 @@ class Engine(ibus.EngineBase):
return True
elif keyval == keysyms.Left or keyval == keysyms.Right:
return True
- if keyval in xrange(keysyms.a, keysyms.z + 1) or \
+ if keyval in range(keysyms.a, keysyms.z + 1) or \
(keyval == keysyms.quoteright and self.__prepinyin_string):
if self.__lookup_table.get_number_of_candidates() \
and len(self.__lookup_table.get_candidate(0).text.decode('utf8'))\
>= MAX_SPELLINGS:
return True
if state & (modifier.CONTROL_MASK | modifier.ALT_MASK) == 0:
- self.__prepinyin_string += unichr(keyval)
+ self.__prepinyin_string += chr(keyval)
self.__invalidate()
return True
else:
- c = unichr(keyval)
- if c == u"." and self.__prev_char and self.__prev_char.isdigit():
+ c = chr(keyval)
+ if c == "." and self.__prev_char and self.__prev_char.isdigit():
return False
- if self.__full_width_punct[self.__mode] and c in u'~!$^&*()_[{]}\\|;:\'",<.>/?':
+ if self.__full_width_punct[self.__mode] and c in '~!$^&*()_[{]}\\|;:\'",<.>/?':
c = self.__convert_to_full_width(c)
self.__commit_string(c)
return True
@@ -323,8 +323,8 @@ class Engine(ibus.EngineBase):
def __commit_string(self, text):
self.commit_text(ibus.Text(text))
- self.__prepinyin_string = u""
- self.__prev_char = text and text[-1] or u''
+ self.__prepinyin_string = ""
+ self.__prev_char = text and text[-1] or ''
self.__update()
def __update(self):
@@ -343,7 +343,7 @@ class Engine(ibus.EngineBase):
pass
preedit_string = self.__lookup_table \
and self.__lookup_table.get_number_of_candidates() \
- and self.__lookup_table.get_candidate(0).text.decode('utf8') or u""
+ and self.__lookup_table.get_candidate(0).text.decode('utf8') or ""
preedit_len = len(preedit_string)
preedit_pos = im_get_fixed_len()
@@ -363,33 +363,33 @@ class Engine(ibus.EngineBase):
__double_quotation_state = 0
__single_quotation_state = 0
def __convert_to_full_width(self, c):
- if c == u".":
- return u"\u3002"
- elif c == u"\\":
- return u"\u3001"
- elif c == u"^":
- return u"\u2026\u2026"
- elif c == u"_":
- return u"\u2014\u2014"
- elif c == u"$":
- return u"\uffe5"
- elif c == u"\"":
+ if c == ".":
+ return "\u3002"
+ elif c == "\\":
+ return "\u3001"
+ elif c == "^":
+ return "\u2026\u2026"
+ elif c == "_":
+ return "\u2014\u2014"
+ elif c == "$":
+ return "\uffe5"
+ elif c == "\"":
self.__double_quotation_state = not self.__double_quotation_state
if self.__double_quotation_state:
- return u"\u201c"
+ return "\u201c"
else:
- return u"\u201d"
- elif c == u"'":
+ return "\u201d"
+ elif c == "'":
self.__single_quotation_state = not self.__single_quotation_state
if self.__single_quotation_state:
- return u"\u2018"
+ return "\u2018"
else:
- return u"\u2019"
+ return "\u2019"
- elif c == u"<":
- return u"\u300a"
- elif c == u">":
- return u"\u300b"
+ elif c == "<":
+ return "\u300a"
+ elif c == ">":
+ return "\u300b"
return ibus.unichar_half_to_full(c)
@@ -407,7 +407,7 @@ class Engine(ibus.EngineBase):
im_reset_search()
self.__double_quotation_state = False
self.__single_quotation_state = False
- self.__prepinyin_string = u""
+ self.__prepinyin_string = ""
self.__candidate_num = 0
self.__lookup_candidate_num = 0
self.__invalidate()
Index: ibus-googlepinyin/factory.py
===================================================================
--- ibus-googlepinyin.orig/factory.py
+++ ibus-googlepinyin/factory.py
@@ -30,7 +30,7 @@ class EngineFactory(ibus.EngineFactoryBa
self.__id = 0
def create_engine(self, engine_name):
- print engine_name
+ print(engine_name)
if engine_name == "googlepinyin":
self.__id += 1
return engine.Engine(self.__bus, "%s/%d" % ("/org/freedesktop/IBus/GooglePinyin/Engine", self.__id))
Index: ibus-googlepinyin/googlepinyin.py
===================================================================
--- ibus-googlepinyin.orig/googlepinyin.py
+++ ibus-googlepinyin/googlepinyin.py
@@ -309,7 +309,7 @@ if __name__=="__main__":
pinyin = sys.argv[1]
im_open_decoder()
num = im_search(pinyin)
- print '\t'.join((('%3s %s') % (i, im_get_candidate(i)) for i in range(num)))
+ print('\t'.join((('%3s %s') % (i, im_get_candidate(i)) for i in range(num))))
pass
else:
try:
@@ -320,19 +320,19 @@ if __name__=="__main__":
num = 0
while True:
try:
- i = raw_input('> ')
+ i = input('> ')
except:
im_close_decoder()
break
if i and i[0].isalpha():
im_reset_search()
num = im_search(i)
- print '\t'.join((('%3s %s') % (i, im_get_candidate(i)) for i in range(num)))
+ print('\t'.join((('%3s %s') % (i, im_get_candidate(i)) for i in range(num))))
pass
elif i.isdigit() and int(i) < num:
num = im_choose(int(i))
- print '-', im_get_fixed_len()
- print '\t'.join((('%3s %s') % (i, im_get_candidate(i)) for i in range(num)))
+ print('-', im_get_fixed_len())
+ print('\t'.join((('%3s %s') % (i, im_get_candidate(i)) for i in range(num))))
pass
pass
pass
Index: ibus-googlepinyin/libopencc.py
===================================================================
--- ibus-googlepinyin.orig/libopencc.py
+++ ibus-googlepinyin/libopencc.py
@@ -34,4 +34,4 @@ if __name__=="__main__":
else:
text = sys.stdin.read()
pass
- print convert(text)
+ print(convert(text))
Index: ibus-googlepinyin/main.py
===================================================================
--- ibus-googlepinyin.orig/main.py
+++ ibus-googlepinyin/main.py
@@ -61,9 +61,9 @@ def launch_engine(exec_by_ibus):
IMApp(exec_by_ibus).run()
def print_help(out, v = 0):
- print >> out, "-i, --ibus execute by ibus."
- print >> out, "-h, --help show this message."
- print >> out, "-d, --daemonize daemonize ibus"
+ print("-i, --ibus execute by ibus.", file=out)
+ print("-h, --help show this message.", file=out)
+ print("-d, --daemonize daemonize ibus", file=out)
sys.exit(v)
def main():
@@ -73,7 +73,7 @@ def main():
longopt = ["help", "daemonize", "ibus"]
try:
opts, args = getopt.getopt(sys.argv[1:], shortopt, longopt)
- except getopt.GetoptError, err:
+ except getopt.GetoptError as err:
print_help(sys.stderr, 1)
for o, a in opts:
@@ -84,7 +84,7 @@ def main():
elif o in ("-i", "--ibus"):
exec_by_ibus = True
else:
- print >> sys.stderr, "Unknown argument: %s" % o
+ print("Unknown argument: %s" % o, file=sys.stderr)
print_help(sys.stderr, 1)
if daemonize: