def save(self, key, **fields): """Slow write using separate blocking connection.""" keys, values = zip(*sorted(fields.items())) if keys != self.fields[1:]: say.error("dbase %s: declared keys = %s", self.filename, self.keys) say.error("dbase %s: saved keys = %s", self.filename, keys) raise SatoryError("bad save: inconsistent fields") values = (t(v) for t, v in zip(self.types, (key,) + values)) questions = ", ".join("?" for v in self.types) query = u"INSERT OR REPLACE INTO %s %s VALUES (%s);" % (self.table, self.fields, questions) with apsw.Connection(self.filename) as dbase: dbase.setbusytimeout(self.timeout_millisecs) cur = dbase.cursor() cur.execute(query, values)
def PLUG(ID, method="html", *args, **kw): """Returns content of the element 'ID' in given form.""" TODO("missing security checks here...") ID_components = re.match("^(\w[\w\d_]+):([\d\w_]+)$", str(ID)) if not ID_components: say.error("[PLUG] bad ID: %s", repr(ID)) return HtmlStub("[PLUG] bad ID") block, block_id = ID_components.groups() if block not in MAPPER: say.error("[PLUG] unregistered class: %s" % block) return HtmlStub("[PLUG] unknown block") tile = MAPPER[block](block_id) func = getattr(tile, method, None) if func and getattr(func, "isportlet", False): return func(*args, **kw) else: return HtmlStub("[PLUG] call to forbidden/missing method %s.%s" % (block, method))