From 9d2615c221b647f7d554123fa4aaecb11f8b2bb7 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 18 Dec 2018 11:48:53 -0600 Subject: [PATCH] Added a patched version of jconfig to support non-ascii paths --- src/sessionmanager/jconfig_patched.py | 27 +++++++++++++++++++++++++++ src/sessionmanager/vk_api_patched.py | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/sessionmanager/jconfig_patched.py diff --git a/src/sessionmanager/jconfig_patched.py b/src/sessionmanager/jconfig_patched.py new file mode 100644 index 0000000..1d80693 --- /dev/null +++ b/src/sessionmanager/jconfig_patched.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +""" Modified Jconfig base class """ +import logging +import json +from codecs import open +from jconfig import jconfig + +log = logging.getLogger('jconfig_patched') + +class Config(jconfig.Config): + + log.info("Instantiated patched jconfig instance") + + def load(self, filename, **kwargs): + try: + with open(filename, 'r', encoding="utf-8") as f: + settings = json.load(f) + except (IOError, ValueError): + settings = {} + + settings.setdefault(self.section_name, {}) + + return settings + + def save(self): + with open(self._filename, 'w', encoding="utf-8") as f: + json.dump(self._settings, f, indent=2, sort_keys=True) diff --git a/src/sessionmanager/vk_api_patched.py b/src/sessionmanager/vk_api_patched.py index f5da838..b6ae4a0 100644 --- a/src/sessionmanager/vk_api_patched.py +++ b/src/sessionmanager/vk_api_patched.py @@ -5,7 +5,7 @@ import logging import vk_api import threading import requests -import jconfig +import jconfig_patched as jconfig from vk_api.enums import VkUserPermissions from vk_api.exceptions import *