From 5ab00b7d463500a1076c9e0f7c80bb7f901c5bd4 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Fri, 5 Apr 2013 18:34:39 +0900 Subject: [PATCH] Working with ST3 Fixes for python 3 syntax and string to bytes conversion. --- sublimeibus/async.py | 9 ++++++--- sublimeibus/sublime-ibus-agent.py | 4 ++-- sublimeibusplugin.py | 13 +++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sublimeibus/async.py b/sublimeibus/async.py index 8295852..ed02049 100644 --- a/sublimeibus/async.py +++ b/sublimeibus/async.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- import os -import thread import subprocess import logging +try: + import _thread as thread +except ImportError: + import thread if os.name == "nt" and not hasattr(subprocess, 'STARTF_USESHOWWINDOW'): @@ -127,7 +130,7 @@ def stop(self): def send(self, data): if self.async is not None: - return self.async.proc.stdin.write(data) + return self.async.proc.stdin.write(data.encode('utf-8')) else: raise @@ -135,7 +138,7 @@ def push(self, data): self.send(data) def handle_read(self, data): - buf = data + buf = data.decode('utf-8') terminator = self.get_terminator() while True: diff --git a/sublimeibus/sublime-ibus-agent.py b/sublimeibus/sublime-ibus-agent.py index 519f05c..93b7b0b 100644 --- a/sublimeibus/sublime-ibus-agent.py +++ b/sublimeibus/sublime-ibus-agent.py @@ -500,7 +500,7 @@ def focus_in(id_no): def focus_out(id_no): imcontexts[id_no].focus_out() - print '{}' # Dummy response + print('{}') # Dummy response def reset(id_no): imcontexts[id_no].reset() @@ -562,7 +562,7 @@ def __start_cb(self): def __stdin_cb(self, fd, condition): try: expr = sys.stdin.readline() - exec expr + exec(expr) except: import traceback print_command('error', 'error expr: ' + expr) diff --git a/sublimeibusplugin.py b/sublimeibusplugin.py index 72ff2ac..9257315 100644 --- a/sublimeibusplugin.py +++ b/sublimeibusplugin.py @@ -4,7 +4,12 @@ import os import json from os.path import join -from sublimeibus import host +import sys + +BASE_PATH = os.path.abspath(os.path.dirname(__file__)) +sys.path += [BASE_PATH] + [join(BASE_PATH, 'sublimeibus')] + +from sublimeibus.host import agent class Logger(object): @@ -190,9 +195,9 @@ def on_data(data): logger.debug(repr(data)) -host.agent.register_callback(on_data) -host.agent.restart(join(os.getcwd(), 'sublimeibus')) +agent.register_callback(on_data) +agent.restart(join(BASE_PATH, 'sublimeibus')) status = IBusStatus() -command = IBusCommand(host.agent) +command = IBusCommand(agent) command.setup()