def test_local_release(): """Locals work without manager""" loc = Local() loc.foo = 42 release_local(loc) assert not hasattr(loc, "foo") ls = LocalStack() ls.push(42) release_local(ls) assert ls.top is None
def test_local_release(): """Locals work without manager""" loc = Local() loc.foo = 42 release_local(loc) assert not hasattr(loc, 'foo') ls = LocalStack() ls.push(42) release_local(ls) assert ls.top is None
def test_local_stack(): """Test the LocalStack""" ident = get_ident() ls = LocalStack() assert ident not in ls._local.__storage__ assert ls.top is None ls.push(42) assert ident in ls._local.__storage__ assert ls.top == 42 ls.push(23) assert ls.top == 23 ls.pop() assert ls.top == 42 ls.pop() assert ls.top is None assert ls.pop() is None assert ls.pop() is None proxy = ls() ls.push([1, 2]) assert proxy == [1, 2] ls.push((1, 2)) assert proxy == (1, 2) ls.pop() ls.pop() assert repr(proxy) == "<LocalProxy unbound>" assert ident not in ls._local.__storage__
def test_local_stack(): """Test the LocalStack""" ident = get_ident() ls = LocalStack() assert ident not in ls._local.__storage__ assert ls.top is None ls.push(42) assert ident in ls._local.__storage__ assert ls.top == 42 ls.push(23) assert ls.top == 23 ls.pop() assert ls.top == 42 ls.pop() assert ls.top is None assert ls.pop() is None assert ls.pop() is None proxy = ls() ls.push([1, 2]) assert proxy == [1, 2] ls.push((1, 2)) assert proxy == (1, 2) ls.pop() ls.pop() assert repr(proxy) == '<LocalProxy unbound>' assert ident not in ls._local.__storage__
def test_custom_idents(): """Local manager supports custom ident functions""" ident = 0 local = Local() stack = LocalStack() mgr = LocalManager([local, stack], ident_func=lambda: ident) local.foo = 42 stack.push({"foo": 42}) ident = 1 local.foo = 23 stack.push({"foo": 23}) ident = 0 assert local.foo == 42 assert stack.top["foo"] == 42 stack.pop() assert stack.top is None ident = 1 assert local.foo == 23 assert stack.top["foo"] == 23 stack.pop() assert stack.top is None
from datetime import datetime as _datetime, tzinfo as _tzinfo, timedelta from tzlocal import get_localzone import time as _time import pytz as _pytz import math as _math import datetime as _datetime_mod import re as _re from pytz import ZERO from werkzeug import LocalStack from sqlalchemy import processors _utc = _pytz.utc _default_tz_stack = LocalStack() _default_tz_stack.push(get_localzone()) _default_tz = _default_tz_stack() def patch(): _datetime_mod.datetime = datetime DATETIME_RE = re.compile( "(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)(?:\.(\d+))?") # (only) sqlite uses str_to_datetime to process its datetime result processors.str_to_datetime = processors. \ str_to_datetime_processor_factory(DATETIME_RE, datetime) def push_default_timezone(new_tz): """Sets the default time zone used by the objects contained in this module. new_tz may be either a pytz-compatible tzinfo (requires normalize