
* add a wrapper around `sqlite3` to enable connection pooling across multiple threads. Most tests now use a in-memory database which speeds things (slightly) up. The database wrapper is now uncoupled from the actual database connection. * split cache framework from core.Mixin into a separate package `isso.cache`. The dependency on `werkzeug.contrib` has been removed to ease a possible transition to a different web framework later. The default cache uses SQLite3 now (unless Isso is run from uWSGI). While it may sound like a Bad Idea (tm), it's much more efficient than per-process python datastructures. The SQLite3 cache is SMP-capable and fast for read-heavy sites. SQLite3 may fail due to a corrupt database for concurrent read access from multiple processes. The database is actually not corrupted, but the connection is stale. As a workaround, limit process number to your CPU count or wait until a "real" backend such as PostgreSQL is available.
25 lines
702 B
Python
25 lines
702 B
Python
# -*- encoding: utf-8 -*-
|
|
|
|
|
|
def _TypeError(expected, val):
|
|
if isinstance(expected, (list, tuple)):
|
|
expected = ", ".join(ex.__name__ for ex in expected)
|
|
else:
|
|
expected = expected.__name__
|
|
return TypeError("Expected {0}, not {1}".format(
|
|
expected, val.__class__.__name__))
|
|
|
|
|
|
def require(val, expected):
|
|
"""Assure that :param val: is an instance of :param expected: or raise a
|
|
:exception TypeError: indicating what's expected.
|
|
|
|
>>> require(23, int)
|
|
>>> require(None, bool)
|
|
Traceback (most recent call last):
|
|
...
|
|
TypeError: Expected bool, not NoneType
|
|
"""
|
|
if not isinstance(val, expected):
|
|
raise _TypeError(expected, val)
|