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()
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()
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))
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')
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()
async def taskfunc(): self.none(s_task.varget('test')) self.eq([1, 2, 3], s_task.varget('test2')) s_task.varset('test', 42)
def dupstack(newtask): ''' Duplicate the current provenance stack onto another task ''' stack = s_task.varget('provstack') s_task.varset('provstack', stack.copy(), newtask)
def setiden(iden): ''' Sets the cached stack iden for the current provenance stack ''' stack = s_task.varget('provstack') stack.setiden(iden)