comparison libervia/server/pages.py @ 1193:aee3d8fa679f

pages: fixed cached data when `url_cache` is used: `request.template_data` and `request.data` where cached using a shallow copy, causing trouble when a mutable object was used. This has been fixed by using a deepcopy, which should not be a resource issue as `request.data` and `request.template_data` should contain a few data in most cases.
author Goffi <goffi@goffi.org>
date Wed, 12 Jun 2019 20:05:45 +0200
parents 263fed3ce354
children 1211dbc3cca7
comparison
equal deleted inserted replaced
1192:7b05ebc46141 1193:aee3d8fa679f
37 import uuid 37 import uuid
38 import os.path 38 import os.path
39 import urllib 39 import urllib
40 import time 40 import time
41 import hashlib 41 import hashlib
42 import copy
42 43
43 log = getLogger(__name__) 44 log = getLogger(__name__)
44 45
45 46
46 class CacheBase(object): 47 class CacheBase(object):
80 81
81 class CacheURL(CacheBase): 82 class CacheURL(CacheBase):
82 def __init__(self, request): 83 def __init__(self, request):
83 super(CacheURL, self).__init__() 84 super(CacheURL, self).__init__()
84 try: 85 try:
85 self._data = request.data.copy() 86 self._data = copy.deepcopy(request.data)
86 except AttributeError: 87 except AttributeError:
87 self._data = {} 88 self._data = {}
88 self._template_data = request.template_data.copy() 89 self._template_data = copy.deepcopy(request.template_data)
89 self._prepath = request.prepath[:] 90 self._prepath = request.prepath[:]
90 self._postpath = request.postpath[:] 91 self._postpath = request.postpath[:]
91 del self._template_data["csrf_token"] 92 del self._template_data["csrf_token"]
92 93
93 def use(self, request): 94 def use(self, request):
94 self.last_access = time.time() 95 self.last_access = time.time()
95 request.data = self._data.copy() 96 request.data = copy.deepcopy(self._data)
96 request.template_data.update(self._template_data) 97 request.template_data.update(copy.deepcopy(self._template_data))
97 request.prepath = self._prepath[:] 98 request.prepath = self._prepath[:]
98 request.postpath = self._postpath[:] 99 request.postpath = self._postpath[:]
99 100
100 101
101 class LiberviaPage(web_resource.Resource): 102 class LiberviaPage(web_resource.Resource):