Esempio n. 1
0
 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
Esempio n. 2
0
 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
Esempio n. 3
0
 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')
Esempio n. 4
0
 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')
Esempio n. 5
0
 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')
Esempio n. 6
0
    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)
Esempio n. 7
0
    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')
Esempio n. 8
0
    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)
Esempio n. 9
0
    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')
Esempio n. 10
0
 def test_assignment(self):
     l = local()
     l.x = 1
     ok_(l.x == 1)
Esempio n. 11
0
 def test_deletion(self):
     l = local()
     l.x = 1
     ok_(l.x == 1)
     del l.x
     l.x
Esempio n. 12
0
 def test_reassignment(self):
     l = local()
     l.x = 1
     ok_(l.x == 1)
     l.x = 2
     ok_(l.x == 2)
Esempio n. 13
0
    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
Esempio n. 14
0
 def local_env(self, value):
     if not hasattr(self, '_local_env'):
         self._local_env = plocal.local()
     self._local_env.env = value
Esempio n. 15
0
 def local_env(self, value):
     if not hasattr(self, '_local_env'):
         self._local_env = plocal.local()
     self._local_env.env = value