Esempio n. 1
0
def get():
    '''
    Returns:
       A tuple of (stack iden (or None if not set), the current provenance stack)
    '''
    stack = s_task.varget('provstack')
    return stack.get()
Esempio n. 2
0
def get():
    '''
    Returns:
       A tuple of (stack iden (or None if not set), the current provenance stack)
    '''
    stack = s_task.varget('provstack')
    return stack.get()
Esempio n. 3
0
def claim(typ, **info):
    '''
    Add an entry to the provenance stack for the duration of the context
    '''
    stack = s_task.varget('provstack')

    if len(stack) > 256:
        baseframe = stack.provs[1]
        recent_frames = stack.provs[-6:]
        raise s_exc.RecursionLimitHit(
            mesg='Hit provenance claim recursion limit',
            type=typ,
            info=info,
            baseframe=baseframe,
            recent_frames=recent_frames)

    if not ProvenanceEnabled:
        info = {}

    stack.push(typ, **info)

    try:
        yield
    finally:
        stack.pop()
Esempio n. 4
0
def setiden(iden, waswritten):
    '''
    Sets the cached stack iden, waswritten for the current provenance stack.  We use waswritten to cache whether we've
    written the stack and so we can tell the snap whether to fire a prov:new event
    '''
    stack = s_task.varget('provstack')
    stack.setiden((iden, waswritten))
Esempio n. 5
0
    async def test_taskvars(self):
        s_task.varset('test', 'foo')
        self.eq(s_task.varget('test'), 'foo')

        self.none(s_task.varget('nope'))

        s_task.vardefault('test2', lambda: [1, 2, 3])
        test2 = s_task.varget('test2')
        self.eq(test2, [1, 2, 3])
        test2.append(4)
        self.eq([1, 2, 3, 4], s_task.varget('test2'))

        async def taskfunc():
            self.none(s_task.varget('test'))
            self.eq([1, 2, 3], s_task.varget('test2'))
            s_task.varset('test', 42)

        await asyncio.create_task(taskfunc())

        self.eq(s_task.varget('test'), 'foo')
Esempio n. 6
0
    async def test_taskvars(self):
        s_task.varset('test', 'foo')
        self.eq(s_task.varget('test'), 'foo')

        self.none(s_task.varget('nope'))

        s_task.vardefault('test2', lambda: [1, 2, 3])
        test2 = s_task.varget('test2')
        self.eq(test2, [1, 2, 3])
        test2.append(4)
        self.eq([1, 2, 3, 4], s_task.varget('test2'))

        async def taskfunc():
            self.none(s_task.varget('test'))
            self.eq([1, 2, 3], s_task.varget('test2'))
            s_task.varset('test', 42)

        await asyncio.create_task(taskfunc())

        self.eq(s_task.varget('test'), 'foo')
Esempio n. 7
0
def claim(typ, **info):
    '''
    Add an entry to the provenance stack for the duration of the context
    '''
    stack = s_task.varget('provstack')

    if len(stack) > 256:  # pragma: no cover
        raise s_exc.RecursionLimitHit(mesg='Hit global recursion limit')

    stack.push(typ, **info)

    try:
        yield
    finally:
        stack.pop()
Esempio n. 8
0
def claim(typ, **info):
    '''
    Add an entry to the provenance stack for the duration of the context
    '''
    stack = s_task.varget('provstack')

    if len(stack) > 256:  # pragma: no cover
        raise s_exc.RecursionLimitHit(mesg='Hit global recursion limit')

    stack.push(typ, **info)

    try:
        yield
    finally:
        stack.pop()
Esempio n. 9
0
 async def taskfunc():
     self.none(s_task.varget('test'))
     self.eq([1, 2, 3], s_task.varget('test2'))
     s_task.varset('test', 42)
Esempio n. 10
0
 async def taskfunc():
     self.none(s_task.varget('test'))
     self.eq([1, 2, 3], s_task.varget('test2'))
     s_task.varset('test', 42)
Esempio n. 11
0
def dupstack(newtask):
    '''
    Duplicate the current provenance stack onto another task
    '''
    stack = s_task.varget('provstack')
    s_task.varset('provstack', stack.copy(), newtask)
Esempio n. 12
0
def setiden(iden):
    '''
    Sets the cached stack iden for the current provenance stack
    '''
    stack = s_task.varget('provstack')
    stack.setiden(iden)
Esempio n. 13
0
def dupstack(newtask):
    '''
    Duplicate the current provenance stack onto another task
    '''
    stack = s_task.varget('provstack')
    s_task.varset('provstack', stack.copy(), newtask)
Esempio n. 14
0
def setiden(iden):
    '''
    Sets the cached stack iden for the current provenance stack
    '''
    stack = s_task.varget('provstack')
    stack.setiden(iden)