summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-09-14 18:13:37 +0200
committerGravatar mkaay <mkaay@mkaay.de> 2010-09-14 18:13:37 +0200
commit46d16791cc4f3acd4424667146fcd85ae542f08d (patch)
tree2fd0d43a721d5853f6721560bcc278b7c2894267
parentresolved a python 2.5 issue (diff)
downloadpyload-46d16791cc4f3acd4424667146fcd85ae542f08d.tar.xz
missing file, again..
-rw-r--r--module/PluginManager.py6
-rw-r--r--module/SaveEval.py63
2 files changed, 68 insertions, 1 deletions
diff --git a/module/PluginManager.py b/module/PluginManager.py
index 19dd5886f..85504ed24 100644
--- a/module/PluginManager.py
+++ b/module/PluginManager.py
@@ -169,7 +169,11 @@ class PluginManager():
config = self.reConfig.findall(content)
if config:
- config = [ [y.strip() for y in x.replace("'","").replace('"',"").replace(")","").split(",")] for x in config[0].split("(") if x.strip()]
+ config = literal_eval(config[0].strip().replace("\n", "").replace("\r", ""))
+ if type(config[0]) == tuple:
+ config = [list(x) for x in config]
+ else:
+ config = [list(config)]
if folder == "hooks":
config.append( ["load", "bool", "Load on startup", True if name not in ("XMPPInterface", "MultiHome") else False] )
diff --git a/module/SaveEval.py b/module/SaveEval.py
new file mode 100644
index 000000000..863ff48cc
--- /dev/null
+++ b/module/SaveEval.py
@@ -0,0 +1,63 @@
+## {{{ http://code.activestate.com/recipes/364469/ (r2)
+import compiler
+
+class Unsafe_Source_Error(Exception):
+ def __init__(self,error,descr = None,node = None):
+ self.error = error
+ self.descr = descr
+ self.node = node
+ self.lineno = getattr(node,"lineno",None)
+
+ def __repr__(self):
+ return "Line %d. %s: %s" % (self.lineno, self.error, self.descr)
+ __str__ = __repr__
+
+class SafeEval(object):
+
+ def visit(self, node,**kw):
+ cls = node.__class__
+ meth = getattr(self,'visit'+cls.__name__,self.default)
+ return meth(node, **kw)
+
+ def default(self, node, **kw):
+ for child in node.getChildNodes():
+ return self.visit(child, **kw)
+
+ visitExpression = default
+
+ def visitConst(self, node, **kw):
+ return node.value
+
+ def visitDict(self,node,**kw):
+ return dict([(self.visit(k),self.visit(v)) for k,v in node.items])
+
+ def visitTuple(self,node, **kw):
+ return tuple(self.visit(i) for i in node.nodes)
+
+ def visitList(self,node, **kw):
+ return [self.visit(i) for i in node.nodes]
+
+class SafeEvalWithErrors(SafeEval):
+
+ def default(self, node, **kw):
+ raise Unsafe_Source_Error("Unsupported source construct",
+ node.__class__,node)
+
+ def visitName(self,node, **kw):
+ raise Unsafe_Source_Error("Strings must be quoted",
+ node.name, node)
+
+ # Add more specific errors if desired
+
+
+def safe_eval(source, fail_on_error = True):
+ walker = fail_on_error and SafeEvalWithErrors() or SafeEval()
+ try:
+ ast = compiler.parse(source,"eval")
+ except SyntaxError, err:
+ raise
+ try:
+ return walker.visit(ast)
+ except Unsafe_Source_Error, err:
+ raise
+## end of http://code.activestate.com/recipes/364469/ }}}