def local_env(self): " A thread save dictionary to store data for a particular tag. " if not hasattr(self, '_local_env'): self._local_env = plocal.local() if not hasattr(self._local_env, 'env'): self._local_env.env = {} return self._local_env.env
def test_assignment(self): l = local(thread_local=False) l.x = 'a' ok_(l.x == 'a') pid = os.fork() if pid: os.wait() ok_(l.x == 'a') else: l.x = 'b' ok_(l.x == 'b')
def test_namespace(self): l = local(thread_local=False) l.x = 'a' pid = os.fork() if pid: os.wait() assert_raises(AttributeError, lambda: l.y) else: assert_raises(AttributeError, lambda: l.x) l.y = 'b' ok_(l.y == 'b')
def test_assignment(self): l = local() def f(): l.x = 'b' ok_(l.x == 'b') l.x = 'a' ok_(l.x == 'a') th = threading.Thread(target=f) th.start() th.join() ok_(l.x == 'a')
def test_namespace(self): l = local() def f(): assert_raises(AttributeError, lambda: l.x) l.y = 'b' ok_(l.y == 'b') l.x = 'a' th = threading.Thread(target=f) th.start() th.join() assert_raises(AttributeError, lambda: l.y)
def test_threading_namespace(self): l = local(thread_local=False) def f(): ok_(l.x == 'a') l.y = 'b' ok_(l.y == 'b') l.x = 'a' th = threading.Thread(target=f) th.start() th.join() ok_(l.y == 'b')
def test_deletion(self): l = local(thread_local=False) l.x = 'a' ok_(l.x == 'a') pid = os.fork() if pid: os.wait() ok_(l.x == 'a') else: l.x = 'b' ok_(l.x == 'b') del l.x assert_raises(AttributeError, lambda: l.x)
def test_deletion(self): l = local() def f(): l.x = 'b' ok_(l.x == 'b') del l.x assert_raises(AttributeError, lambda: l.x) l.x = 'a' ok_(l.x == 'a') th = threading.Thread(target=f) th.start() th.join() ok_(l.x == 'a')
def test_assignment(self): l = local() l.x = 1 ok_(l.x == 1)
def test_deletion(self): l = local() l.x = 1 ok_(l.x == 1) del l.x l.x
def test_reassignment(self): l = local() l.x = 1 ok_(l.x == 1) l.x = 2 ok_(l.x == 2)
def parse(self, parser): INSIDE_BLOCK, OUTSIDE_BLOCK = 0, 1 tag = parser.stream.next() end_tags_in_block = [ 'name:{}_endblock'.format(tag.value), 'name:{}_end_block'.format(tag.value), ] end_tags_outside_block = [ 'name:end' + tag.value, 'name:end_' + tag.value, 'name:{}_block'.format(tag.value), ] end_tags = (end_tags_in_block, end_tags_outside_block) state = OUTSIDE_BLOCK attrs_ = self.parse_attrs(parser) body = parser.parse_statements(end_tags[state], drop_needle=False) node_list = [] blocks = [ ('body', body, tag.lineno), ] while True: sub_tag = parser.stream.next() sub_tag_name = sub_tag.value tag_index = end_tags[state].index('name:' + sub_tag_name) if state == OUTSIDE_BLOCK and tag_index < 2: break elif state == OUTSIDE_BLOCK: # entering new block sub_block_name = parser.stream.next().value state = INSIDE_BLOCK body = parser.parse_statements(end_tags[state], drop_needle=False) blocks.append((sub_block_name, body, sub_tag.lineno)) else: state = OUTSIDE_BLOCK parser.parse_statements(end_tags[state], drop_needle=False) self.block_results = plocal.local() self.block_results.data = {} node_list = [ nodes.CallBlock(self.call_method('_subblock', args=[nodes.Const(block_name)]), [], [], block).set_lineno(lineno) for block_name, block, lineno in blocks ] attrs = self.to_node_dict(attrs_) node_list.append(nodes.Output([self.call_method('_call_multiblock_tag', args=[attrs])])) return node_list
def local_env(self, value): if not hasattr(self, '_local_env'): self._local_env = plocal.local() self._local_env.env = value