From a4c1f6af8fda27b0f1d748fabe89b3490b2053a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez?= Date: Tue, 30 Oct 2012 15:00:45 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20a=20bug=20with=20encodings=20when=20usi?= =?UTF-8?q?ng=20extended=20chars=20(such=20as=20=C3=A1,=20...).=20Set=20de?= =?UTF-8?q?fault=20encoding=20at=20"wsgi.py"=20to=20UTF-8=20and=20added=20?= =?UTF-8?q?a=20custom=20"sitecustomize.py"=20so,=20in=20case=20we=20run=20?= =?UTF-8?q?server=20from=20command=20line=20(with=20PYTHONPATH=20at=20leas?= =?UTF-8?q?t=20pointing=20to=20"."),=20correctly=20sets=20the=20encoding?= =?UTF-8?q?=20to=20UTF-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/server/wsgi.py | 4 ++++ server/src/sitecustomize.py | 3 +++ server/src/uds/core/util/Cache.py | 2 ++ server/src/uds/core/util/Config.py | 25 +++++++++++++++++-------- 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 server/src/sitecustomize.py diff --git a/server/src/server/wsgi.py b/server/src/server/wsgi.py index 8906f5eee..116bd6ab7 100644 --- a/server/src/server/wsgi.py +++ b/server/src/server/wsgi.py @@ -13,6 +13,10 @@ middleware here, or combine a Django application with an application of another framework. """ +import sys +reload(sys) +sys.setdefaultencoding('UTF-8') + import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings") diff --git a/server/src/sitecustomize.py b/server/src/sitecustomize.py new file mode 100644 index 000000000..0ada98614 --- /dev/null +++ b/server/src/sitecustomize.py @@ -0,0 +1,3 @@ +import sys + +sys.setdefaultencoding('UTF-8') diff --git a/server/src/uds/core/util/Cache.py b/server/src/uds/core/util/Cache.py index 0b5d5a3a6..a4e1e5e4c 100644 --- a/server/src/uds/core/util/Cache.py +++ b/server/src/uds/core/util/Cache.py @@ -49,6 +49,8 @@ class Cache(object): def __getKey(self, key): + import os + logger.debug(os.environ) h = hashlib.md5() h.update(self._owner + key) return h.hexdigest() diff --git a/server/src/uds/core/util/Config.py b/server/src/uds/core/util/Config.py index d89720c90..2e92edb3e 100644 --- a/server/src/uds/core/util/Config.py +++ b/server/src/uds/core/util/Config.py @@ -47,10 +47,11 @@ class Config: ''' class _Value: - def __init__(self, section, key, default = '', crypt = False): + def __init__(self, section, key, default = '', crypt = False, longText = False): self._section = section self._key = key self._crypt = crypt + self._longText = longText if crypt is False: self._default = default else: @@ -66,12 +67,11 @@ class Config: self._crypt = [self._crypt, True][readed.crypt] # True has "higher" precedende than False except Exception: # Not found - if self._default != '': - if self._crypt: - self.set( CryptoManager.manager().decrypt(self._default) ) - else: - self.set(self._default) - self._data = self._default + if self._default != '' and self._crypt: + self.set( CryptoManager.manager().decrypt(self._default) ) + elif not self._crypt: + self.set(self._default) + self._data = self._default if self._crypt is True: return CryptoManager.manager().decrypt(self._data) else: @@ -96,6 +96,9 @@ class Config: def isCrypted(self): return self._crypt + + def isLongText(self): + return self._longText def set(self, value): if self._crypt is True: @@ -124,6 +127,9 @@ class Config: def valueCrypt(self, key, default = ''): return Config._Value(self, key, default, True) + def valueLong(self, key, default = ''): + return Config._Value(self, key, default, False, True) + def name(self): return self._sectionName @@ -208,6 +214,8 @@ class GlobalConfig: # Max time needed to get a service "fully functional" before it's considered "failed" and removed # The time is in seconds MAX_INITIALIZING_TIME = Config.section(GLOBAL_SECTION).value('maxInitTime', '3600') + # Custom HTML for login page + CUSTOM_HTML_LOGIN = Config.section(GLOBAL_SECTION).valueLong('customHtmlLogin', '') initDone = False @@ -238,7 +246,8 @@ class GlobalConfig: GlobalConfig.AUTORUN_SERVICE.get() GlobalConfig.REDIRECT_TO_HTTPS.get() GlobalConfig.MAX_INITIALIZING_TIME.get() - except Exception, e: + GlobalConfig.CUSTOM_HTML_LOGIN.get() + except: logger.debug('Config table do not exists!!!, maybe we are installing? :-)') # Context processor