[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
This commit is contained in:
Christophe Matthieu 2013-05-02 12:42:49 +02:00
parent 511efd43a9
commit 47d8e1a470
1 changed files with 31 additions and 8 deletions

View File

@ -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