aboutsummaryrefslogtreecommitdiffstats
path: root/pycrctrl.py
diff options
context:
space:
mode:
Diffstat (limited to 'pycrctrl.py')
-rw-r--r--pycrctrl.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/pycrctrl.py b/pycrctrl.py
index 6204f5d..1d2248d 100644
--- a/pycrctrl.py
+++ b/pycrctrl.py
@@ -130,13 +130,13 @@ class PyCRCtrl(object):
# "shutdownExp" : r"^Internetspiel ausgewertet(.*)"
# }
- def __init__(self, irc=None, path=None):
+ def __init__(self, irc=None, path=None, config="pycrctrl.conf"):
if sys.platform == "win32":
raise NotImplementedError("{} wird nicht unterstützt!".format(sys.platform))
self.irc = irc
self.path = path
- self.loadConfigFile()
+ self.loadConfigFile(config)
self.loadScenarioList()
self.codec = codec = QTextCodec.codecForName(self.config.get("encoding"))
self.queue = queue.Queue(5)
@@ -166,11 +166,11 @@ class PyCRCtrl(object):
return True
- def loadConfigFile(self):
+ def loadConfigFile(self, config):
if self.path == None:
return False
- self.config = json.load(open(os.path.join(self.path, "pycrctrl.conf"),"r"))
+ self.config = json.load(open(os.path.join(self.path, config),"r"))
return True
def decodeRegExp(self, regexp):
@@ -192,7 +192,7 @@ class PyCRCtrl(object):
return (CmdResult.SyntaxFail, "Bitte gib einen Szenarionamen an!")
if type(scenario) in [bytes, QByteArray]:
try:
- scenario = self.codec.toUnicode(scenario)
+ scenario = scenario.decode("utf-8")
except:
return (CmdResult.SyntaxFail, "Unbekannter Datentyp!")
@@ -251,7 +251,7 @@ class PyCRCtrl(object):
try:
output = self.clonk.stdout.readline()
- if bool(re.match(self.decodeRegExp(self.config.get("RegExps")["shutdownExp"]), self.codec.toUnicode(output))):
+ if bool(re.match(self.decodeRegExp(self.config.get("RegExps")["shutdownExp"]), output.decode("utf-8"))):
self.clonk.stdin.close()
elif output == b"" and self.clonk.poll() is not None:
if self.clonk:
@@ -261,7 +261,8 @@ class PyCRCtrl(object):
return
elif output:
- output = self.codec.toUnicode(output).splitlines()[0]
+ #output = self.codec.toUnicode(output).splitlines()[0]
+ output = output.decode("utf-8").splitlines()[0]
output = output[(output.find("] ") if output.find("] ") != -1 else -2)+len("] "):]
if output[0] == ">":
@@ -342,7 +343,7 @@ class PyCRCtrl(object):
return (CmdResult.RuntimeError, "")
elif type(text) not in [bytes, QByteArray]:
try:
- text = self.codec.fromUnicode(text)
+ text = text.encode("utf-8")
except:
raise IOError("Cannot write anything else to the server except the following data types: QString, bytes, str, QByteArray")