Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def history(style=None):
storage_dir = tempfile.mkdtemp()
page_history = PageHistory(
conf={'name': 'test', 'url': 'web'},
storage_dir=storage_dir,
style=style,
)
try:
yield page_history
finally:
shutil.rmtree(storage_dir, ignore_errors=True)
def report_changes(conf, content):
return PageHistory(conf).report_changes(content)
def changes_transform_factory(value, conf):
style = value.lower() if value else None
return PageHistory(conf, style=style).report_changes
def clean():
"""Remove storage dir (delete all git repos)"""
shutil.rmtree(PageHistory.STORAGE_DIR)
name, value = next(iter(rule.items()))
except AttributeError:
name, value = rule, None
if name == 'css':
return functools.partial(css_selector, value)
if name == 'css-all':
return functools.partial(css_selector, value, select_all=True)
elif name == 'xpath':
return functools.partial(xpath_selector, value)
elif name == 'tag':
return functools.partial(tag_selector, value)
elif name == 'text':
return extract_text
elif name == 'changes':
style = value.lower() if value else None
return PageHistory(conf, style=style).report_changes
elif name == 'json':
return pretty_json
elif name == 'jq':
return functools.partial(run_jq, value)
elif name == 'sort':
return sort_lines
elif name == 'cut':
return functools.partial(cut_lines, value)
elif name == 'python':
return functools.partial(python_transform, conf=conf, code=value)
elif name == 'bash':
return functools.partial(bash_transform, code=value)
else:
raise RuntimeError(
"Unknown transformer: %r" % (name,)
)
def clean():
"""Clean change history"""
from kibitzr.storage import PageHistory
PageHistory.clean()