Abstracts classes keyed on external variables (e.g. current Flask request).
Moves thread-locals to LocalProxy; adds changes from @sloria's review.