diff options
| author | Fulgen301 <tokmajigeorge@gmailc.om> | 2017-01-26 20:33:32 +0100 |
|---|---|---|
| committer | Fulgen301 <tokmajigeorge@gmailc.om> | 2017-01-26 20:33:32 +0100 |
| commit | 783b5ac2c47a3eef815dcd862c8152f2fe03d680 (patch) | |
| tree | bf40fcffcb77746925a7df1f1c6426c039ea9ba0 | |
| parent | 73c9cbdce4ac7aa1b6d4656ed082775c3c3ed276 (diff) | |
| download | pycrctrl-783b5ac2c47a3eef815dcd862c8152f2fe03d680.tar.gz pycrctrl-783b5ac2c47a3eef815dcd862c8152f2fe03d680.zip | |
Config implementation adjusted
| -rw-r--r-- | pycrctrl.py | 17 |
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") |
