mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-05 17:04:10 +02:00
Implemented --convert for different things, renamed --all to --text
This commit is contained in:
parent
e66299c6ed
commit
2e4847e493
4 changed files with 104 additions and 25 deletions
|
|
@ -281,14 +281,14 @@ def progressbar(*args, **kwargs):
|
|||
yield bar
|
||||
|
||||
|
||||
def _compile_code(code, imports):
|
||||
def _compile_code(code, imports, variable="value"):
|
||||
locals = {}
|
||||
globals = {"r": recipes, "recipes": recipes}
|
||||
# If user defined a convert() function, return that
|
||||
try:
|
||||
exec(code, globals, locals)
|
||||
return locals["convert"]
|
||||
except (SyntaxError, NameError, KeyError, TypeError):
|
||||
except (AttributeError, SyntaxError, NameError, KeyError, TypeError):
|
||||
pass
|
||||
|
||||
# Try compiling their code as a function instead
|
||||
|
|
@ -297,7 +297,7 @@ def _compile_code(code, imports):
|
|||
if "\n" not in code and not code.strip().startswith("return "):
|
||||
code = "return {}".format(code)
|
||||
|
||||
new_code = ["def fn(value):"]
|
||||
new_code = ["def fn({}):".format(variable)]
|
||||
for line in code.split("\n"):
|
||||
new_code.append(" {}".format(line))
|
||||
code_o = compile("\n".join(new_code), "<string>", "exec")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue