From 538f3752844989de2313706cc4954552b6b8e210 Mon Sep 17 00:00:00 2001 From: ilvalle Date: Sun, 24 May 2015 20:15:28 +0200 Subject: [PATCH] lazy request.uuid --- gluon/globals.py | 17 ++++++++++++----- gluon/main.py | 1 - 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gluon/globals.py b/gluon/globals.py index 1a3ebb6e..6c64ff20 100644 --- a/gluon/globals.py +++ b/gluon/globals.py @@ -193,6 +193,7 @@ class Request(Storage): self.is_https = False self.is_local = False self.global_settings = settings.global_settings + self._uuid = None def parse_get_vars(self): """Takes the QUERY_STRING and unpacks it to get_vars @@ -306,13 +307,21 @@ class Request(Storage): self.parse_all_vars() return self._vars + @property + def uuid(self): + """Lazily uuid + """ + if self._uuid is None: + self.compute_uuid() + return self._uuid + def compute_uuid(self): - self.uuid = '%s/%s.%s.%s' % ( + self._uuid = '%s/%s.%s.%s' % ( self.application, self.client.replace(':', '_'), self.now.strftime('%Y-%m-%d.%H-%M-%S'), web2py_uuid()) - return self.uuid + return self._uuid def user_agent(self): from gluon.contrib import user_agent_parser @@ -453,8 +462,6 @@ class Response(Storage): response.cache_includes = (cache_method, time_expire). Example: (cache.disk, 60) # caches to disk for 1 minute. """ - from gluon import URL - files = [] has_js = has_css = False for item in self.files: @@ -663,7 +670,7 @@ class Response(Storage): return handler(request, self, methods) def toolbar(self): - from html import DIV, SCRIPT, BEAUTIFY, TAG, URL, A + from gluon.html import DIV, SCRIPT, BEAUTIFY, TAG, A BUTTON = TAG.button admin = URL("admin", "default", "design", extension='html', args=current.request.application) diff --git a/gluon/main.py b/gluon/main.py index d4565dc4..ee3600a2 100644 --- a/gluon/main.py +++ b/gluon/main.py @@ -376,7 +376,6 @@ def wsgibase(environ, responder): request.env.http_x_forwarded_proto in HTTPS_SCHEMES \ or env.https == 'on' ) - request.compute_uuid() # requires client request.url = environ['PATH_INFO'] # ##################################################