Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def context(self, content):
html = LazyHTML(content)
xml = LazyXML(content)
return {
'conf': self.conf,
'stash': LazyStash(),
'content': content,
'lines': content.splitlines(),
'json': LazyJSON(content),
'css': html.css,
'xpath': xml.xpath,
'env': os.environ,
}
def fetch_by_python(code, conf):
logger.info("Fetch using Python script")
logger.debug(code)
assert 'content' in code, PYTHON_ERROR
try:
# ok, content = False, None
namespace = {'ok': True}
context = {
'conf': conf,
'stash': LazyStash(),
'creds': settings().creds,
}
exec(code, context, namespace)
return namespace['ok'], namespace['content']
except:
logger.exception("Python fetcher raised an Exception")
return False, traceback.format_exc()
def __call__(self, report):
context = dict(
self.context,
text=report, # legacy
content=report,
stash=LazyStash(),
)
logger.info("Executing Python notifier")
logger.debug(self.code)
exec(self.code, context)
def python_transform(code, content, conf):
logger.info("Python transform")
logger.debug(code)
assert 'content' in code, PYTHON_ERROR
try:
namespace = {'ok': True, 'content': content}
context = {
'conf': conf,
'stash': LazyStash(),
'creds': settings().creds,
}
exec(code, context, namespace)
return namespace['ok'], six.text_type(namespace['content'])
except:
logger.exception("Python transform raised an Exception")
return False, traceback.format_exc()