You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nuvem-commits@incubator.apache.org by js...@apache.org on 2011/03/13 19:20:57 UTC
svn commit: r1081202 - in /incubator/nuvem/trunk/nuvem-parallel:
nuvem/eval_.py nuvem/exec_.py test.py
Author: jsdelfino
Date: Sun Mar 13 19:20:57 2011
New Revision: 1081202
URL: http://svn.apache.org/viewvc?rev=1081202&view=rev
Log:
Add components that eval a python expression and execute a python statement.
Added:
incubator/nuvem/trunk/nuvem-parallel/nuvem/eval_.py
incubator/nuvem/trunk/nuvem-parallel/nuvem/exec_.py
Modified:
incubator/nuvem/trunk/nuvem-parallel/test.py
Added: incubator/nuvem/trunk/nuvem-parallel/nuvem/eval_.py
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/nuvem/eval_.py?rev=1081202&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-parallel/nuvem/eval_.py (added)
+++ incubator/nuvem/trunk/nuvem-parallel/nuvem/eval_.py Sun Mar 13 19:20:57 2011
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+def get(r, py, ref):
+ pye = py.get(r)
+ return eval(pye if isinstance(pye, basestring) else pye[1][0])
Added: incubator/nuvem/trunk/nuvem-parallel/nuvem/exec_.py
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/nuvem/exec_.py?rev=1081202&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-parallel/nuvem/exec_.py (added)
+++ incubator/nuvem/trunk/nuvem-parallel/nuvem/exec_.py Sun Mar 13 19:20:57 2011
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+def get(r, py, ref):
+ val = None
+ pys = py.get(r)
+ exec(pys if isinstance(pys, basestring) else pys[1][0])
+ return val
Modified: incubator/nuvem/trunk/nuvem-parallel/test.py
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/test.py?rev=1081202&r1=1081201&r2=1081202&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-parallel/test.py (original)
+++ incubator/nuvem/trunk/nuvem-parallel/test.py Sun Mar 13 19:20:57 2011
@@ -67,6 +67,8 @@ from nuvem import join
from nuvem import replace
from nuvem import lowercase
from nuvem import uppercase
+from nuvem import eval_
+from nuvem import exec_
def testValues():
assert true_.get(()) == True
@@ -143,6 +145,15 @@ def testText():
assert uppercase.get((), mkref('s', lambda r: 'abc')) == 'ABC'
return True
+def testEval():
+ assert eval_.get((), mkref('py', lambda r: '1 + 2'), mkref('ref', lambda r: 4)) == 3
+ assert eval_.get((), mkref('py', lambda r: 'ref.get(r) + 2'), mkref('ref', lambda r: 4)) == 6
+ assert eval_.get((5,), mkref('py', lambda r: 'ref.get(r) + r[0] + 2'), mkref('ref', lambda r: 4)) == 11
+ assert exec_.get((), mkref('py', lambda r: 'val = 1 + 2'), mkref('ref', lambda r: 4)) == 3
+ assert exec_.get((), mkref('py', lambda r: 'val = ref.get(r) + 2'), mkref('ref', lambda r: 4)) == 6
+ assert exec_.get((5,), mkref('py', lambda r: 'val = ref.get(r) + r[0] + 2'), mkref('ref', lambda r: 4)) == 11
+ return True
+
if __name__ == '__main__':
print 'Testing...'
testValues()
@@ -151,5 +162,6 @@ if __name__ == '__main__':
testMath()
testURL()
testText()
+ testEval()
print 'OK'