>>> request.vars.y = ['abc', 'def'] >>> request.vars.getlast('x') 'abc' >>> request.vars.getlast('y') 'def' >>> request.vars.getlast('z') """ values = self.getlist(key) return values[-1] if values else default def pickle_storage(s): return Storage, (dict(s),) copyreg.pickle(Storage, pickle_storage) if PY2: PICKABLE = (str, int, long, float, bool, list, dict, tuple, set) else: PICKABLE = (str, int, float, bool, list, dict, tuple, set) class StorageList(Storage): """ Behaves like Storage but missing elements defaults to [] instead of None """ def __getitem__(self, key): return self.__getattr__(key) def __getattr__(self, key): if key in self: return self.get(key)
return str(self).decode(*a, **b) def read(self): return str(self) def __mod__(self, symbols): if self.is_copy: return lazyT(self) return lazyT(self.m, symbols, self.T, self.f, self.t, self.M) def pickle_lazyT(c): return str, (c.xml(), ) copyreg.pickle(lazyT, pickle_lazyT) class translator(object): """ This class is instantiated by gluon.compileapp.build_environment as the T object Example: T.force(None) # turns off translation T.force('fr, it') # forces web2py to translate using fr.py or it.py T("Hello World") # translates "Hello World" using the selected file Note:
response.session_file.write(session_pickled) response.session_file.truncate() return True finally: self._close(response) self.save_session_id_cookie() def _unlock(self, response): if response and response.session_file and response.session_locked: try: portalocker.unlock(response.session_file) response.session_locked = False except: # this should never happen but happens in Windows pass def _close(self, response): if response and response.session_file: self._unlock(response) try: response.session_file.close() del response.session_file except: pass def pickle_session(s): return Session, (dict(s), ) copyreg.pickle(Session, pickle_session)
def decode(self, *a, **b): return str(self).decode(*a, **b) def read(self): return str(self) def __mod__(self, symbols): if self.is_copy: return lazyT(self) return lazyT(self.m, symbols, self.T, self.f, self.t, self.M) def pickle_lazyT(c): return str, (c.xml(),) copyreg.pickle(lazyT, pickle_lazyT) class translator(object): """ This class is instantiated by gluon.compileapp.build_environment as the T object Example: T.force(None) # turns off translation T.force('fr, it') # forces web2py to translate using fr.py or it.py T("Hello World") # translates "Hello World" using the selected file Note:
session_pickled = response.session_pickled or pickle.dumps(self, pickle.HIGHEST_PROTOCOL) response.session_file.write(session_pickled) response.session_file.truncate() return True finally: self._close(response) self.save_session_id_cookie() def _unlock(self, response): if response and response.session_file and response.session_locked: try: portalocker.unlock(response.session_file) response.session_locked = False except: # this should never happen but happens in Windows pass def _close(self, response): if response and response.session_file: self._unlock(response) try: response.session_file.close() del response.session_file except: pass def pickle_session(s): return Session, (dict(s),) copyreg.pickle(Session, pickle_session)
>>> request.vars.getlast('x') 'abc' >>> request.vars.getlast('y') 'def' >>> request.vars.getlast('z') """ values = self.getlist(key) return values[-1] if values else default def pickle_storage(s): return Storage, (dict(s), ) copyreg.pickle(Storage, pickle_storage) if PY2: PICKABLE = (str, int, long, float, bool, list, dict, tuple, set) else: PICKABLE = (str, int, float, bool, list, dict, tuple, set) class StorageList(Storage): """ Behaves like Storage but missing elements defaults to [] instead of None """ def __getitem__(self, key): return self.__getattr__(key) def __getattr__(self, key): if key in self:
try: import psutil HAVE_PSUTIL = True except ImportError: HAVE_PSUTIL = False # TODO: REMOVE ME ONCE THIS IS FIXED IN DAL https://github.com/web2py/pydal/issues/668 from pydal.objects import Row from pydal._compat import copyreg def pickle_row(s): return Row, (dict(s), ) copyreg.pickle(Row, pickle_row) # END TODO def remove_oldest_entries(storage, percentage=90): # compute current memory usage (%) old_mem = psutil.virtual_memory().percent # if we have data in storage and utilization exceeds 90% while storage and old_mem > percentage: # removed oldest entry storage.popitem(last=False) # garbage collect gc.collect(1) # comute used memory again new_mem = psutil.virtual_memory().percent # if the used memory did not decrease stop