From 47d8e1a4704196219d10cfce6ac63f43c4fbda86 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 2 May 2013 12:42:49 +0200 Subject: [PATCH] [FIX] http.py Impossible to load the website when there is a unicode char in the url path. `openerp.modules.module.ad_paths` containing unicode strings, werkzeug fail to compare the path which is converted to ascii. force `openerp.modules.module.ad_paths` to only contain bytestrings bzr revid: chm@openerp.com-20130502104249-ttokukc2rpetxqkr --- addons/web/http.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/addons/web/http.py b/addons/web/http.py index 05069574da1..040022b3069 100644 --- a/addons/web/http.py +++ b/addons/web/http.py @@ -19,6 +19,7 @@ import time import traceback import urlparse import uuid +import errno import babel.core import simplejson @@ -200,7 +201,7 @@ class JsonRequest(WebRequest): _logger.debug("--> %s.%s\n%s", method.im_class.__name__, method.__name__, pprint.pformat(self.jsonrequest)) response['id'] = self.jsonrequest.get('id') response["result"] = method(self, **self.params) - except session.AuthenticationError: + except session.AuthenticationError, e: se = serialize_exception(e) error = { 'code': 100, @@ -354,17 +355,31 @@ def httprequest(f): addons_module = {} addons_manifest = {} controllers_class = [] +controllers_class_path = {} controllers_object = {} +controllers_object_path = {} controllers_path = {} class ControllerType(type): def __init__(cls, name, bases, attrs): super(ControllerType, cls).__init__(name, bases, attrs) - controllers_class.append(("%s.%s" % (cls.__module__, cls.__name__), cls)) + name_class = ("%s.%s" % (cls.__module__, cls.__name__), cls) + controllers_class.append(name_class) + path = attrs.get('_cp_path') + if path not in controllers_class_path: + controllers_class_path[path] = name_class class Controller(object): __metaclass__ = ControllerType + def __new__(cls, *args, **kwargs): + subclasses = [c for c in cls.__subclasses__() if c._cp_path == cls._cp_path] + if subclasses: + name = "%s (extended by %s)" % (cls.__name__, ', '.join(sub.__name__ for sub in subclasses)) + cls = type(name, tuple(reversed(subclasses)), {}) + + return object.__new__(cls) + #---------------------------------------------------------- # Session context manager #---------------------------------------------------------- @@ -476,8 +491,15 @@ def session_path(): except Exception: username = "unknown" path = os.path.join(tempfile.gettempdir(), "oe-sessions-" + username) - if not os.path.exists(path): + try: os.mkdir(path, 0700) + except OSError as exc: + if exc.errno == errno.EEXIST: + # directory exists: ensure it has the correct permissions + # this will fail if the directory is not owned by the current user + os.chmod(path, 0700) + else: + raise return path class Root(object): @@ -541,7 +563,7 @@ class Root(object): controllers and configure them. """ for addons_path in openerp.modules.module.ad_paths: - for module in sorted(os.listdir(addons_path)): + for module in sorted(os.listdir(str(addons_path))): if module not in addons_module: manifest_path = os.path.join(addons_path, module, '__openerp__.py') path_static = os.path.join(addons_path, module, 'static') @@ -557,10 +579,11 @@ class Root(object): addons_manifest[module] = manifest self.statics['/%s/static' % module] = path_static - for k, v in controllers_class: - if k not in controllers_object: - o = v() - controllers_object[k] = o + for k, v in controllers_class_path.items(): + if k not in controllers_object_path and hasattr(v[1], '_cp_path'): + o = v[1]() + controllers_object[v[0]] = o + controllers_object_path[k] = o if hasattr(o, '_cp_path'): controllers_path[o._cp_path] = o