diff --git a/connectpyse/config.py b/connectpyse/config.py index bb3a687..e86558d 100644 --- a/connectpyse/config.py +++ b/connectpyse/config.py @@ -14,6 +14,7 @@ cw_api_settings = json.load(fin) API_URL = cw_api_settings['API_URL'] + ENSURE_ASCII = cw_api_settings['ENSURE_ASCII'] if 'ENSURE_ASCII' in cw_api_settings else False _cid = cw_api_settings['COMPANYID'] _pubk = cw_api_settings['PUBLICKEY'] _privk = cw_api_settings['PRIVATEKEY'] @@ -31,4 +32,5 @@ basic_auth['clientId'] = _clientId except FileNotFoundError as e: API_URL = '' + ENSURE_ASCII = False basic_auth = {} \ No newline at end of file diff --git a/connectpyse/cw_controller.py b/connectpyse/cw_controller.py index c677df5..363904c 100644 --- a/connectpyse/cw_controller.py +++ b/connectpyse/cw_controller.py @@ -1,10 +1,10 @@ # Parent class for module controller classes -from .config import API_URL, basic_auth +from .config import API_URL, basic_auth, ENSURE_ASCII from .restapi import Client class CWController(Client): - def __init__(self, url=None, auth=None): + def __init__(self, url=None, auth=None, ensure_ascii=None): # self.module_url comes from child # self.module comes from child # self._class comes from child @@ -16,6 +16,7 @@ def __init__(self, url=None, auth=None): self.pageSize = '' self.API_URL = url if url is not None else API_URL self.basic_auth = auth if auth is not None else basic_auth + self.ensure_ascii = ensure_ascii if ensure_ascii is not None else ENSURE_ASCII super().__init__('{}/{}'.format(self.API_URL, self.module_url)) def _format_user_params(self): diff --git a/connectpyse/restapi.py b/connectpyse/restapi.py index 67c3c45..5d0e539 100644 --- a/connectpyse/restapi.py +++ b/connectpyse/restapi.py @@ -43,15 +43,17 @@ def __getattribute__(self, attr): except AttributeError: return Endpoint( self.root_path, - attr + attr, + ensure_ascii=self.ensure_ascii ) class Endpoint(object): - def __init__(self, root_path, endpoint): + def __init__(self, root_path, endpoint, ensure_ascii): self.endpoint = endpoint self.root_path = root_path + self.ensure_ascii = ensure_ascii def _url(self, path, *args): url = "{}/{}/".format(self.root_path, path) @@ -93,7 +95,7 @@ def post(self, user_data, the_id=None, user_params={}, user_headers={}, files=No url = self._url(self.endpoint) if user_data: - strjsondata = json.dumps(user_data, ensure_ascii=False) + strjsondata = json.dumps(user_data, ensure_ascii=self.ensure_ascii) resp = req.post( url, data=strjsondata, @@ -121,7 +123,7 @@ def post(self, user_data, the_id=None, user_params={}, user_headers={}, files=No def put(self, the_id, user_data, user_params={}, user_headers={}): - strjsondata = json.dumps(user_data, ensure_ascii=False) + strjsondata = json.dumps(user_data, ensure_ascii=self.ensure_ascii) resp = req.put( self._url(self.endpoint, the_id), @@ -141,7 +143,7 @@ def put(self, the_id, user_data, user_params={}, user_headers={}): def patch(self, the_id, user_data, user_params={}, user_headers={}): - strjsondata = json.dumps(user_data, ensure_ascii=False) + strjsondata = json.dumps(user_data, ensure_ascii=self.ensure_ascii) resp = req.patch( self._url(self.endpoint, the_id),