incubator-nuvem-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r1126266 - in /incubator/nuvem/trunk/nuvem-parallel: nuvem/assoc.py nuvem/call.py nuvem/comment.py nuvem/item.py nuvem/keychain.py nuvem/search.py nuvem/select.py test.py
Date Sun, 22 May 2011 22:47:16 GMT
Author: jsdelfino
Date: Sun May 22 22:47:15 2011
New Revision: 1126266

URL: http://svn.apache.org/viewvc?rev=1126266&view=rev
Log:
Refactor and minor fixes to assoc and search components. Add a keychain component.

Added:
    incubator/nuvem/trunk/nuvem-parallel/nuvem/comment.py
      - copied, changed from r1104607, incubator/nuvem/trunk/nuvem-parallel/nuvem/assoc.py
    incubator/nuvem/trunk/nuvem-parallel/nuvem/item.py
      - copied, changed from r1104607, incubator/nuvem/trunk/nuvem-parallel/nuvem/assoc.py
    incubator/nuvem/trunk/nuvem-parallel/nuvem/keychain.py
    incubator/nuvem/trunk/nuvem-parallel/nuvem/select.py
      - copied, changed from r1104607, incubator/nuvem/trunk/nuvem-parallel/nuvem/search.py
Removed:
    incubator/nuvem/trunk/nuvem-parallel/nuvem/assoc.py
    incubator/nuvem/trunk/nuvem-parallel/nuvem/search.py
Modified:
    incubator/nuvem/trunk/nuvem-parallel/nuvem/call.py
    incubator/nuvem/trunk/nuvem-parallel/test.py

Modified: incubator/nuvem/trunk/nuvem-parallel/nuvem/call.py
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/nuvem/call.py?rev=1126266&r1=1126265&r2=1126266&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-parallel/nuvem/call.py (original)
+++ incubator/nuvem/trunk/nuvem-parallel/nuvem/call.py Sun May 22 22:47:15 2011
@@ -16,5 +16,6 @@
 #  under the License.
 
 def get(r, name, proxy):
-    return proxy.get(name.get(r), r)
+    nv = name.get(r)
+    return proxy.get(nv if nv[0:1] == "'" else "'" + nv, r)
 

Copied: incubator/nuvem/trunk/nuvem-parallel/nuvem/comment.py (from r1104607, incubator/nuvem/trunk/nuvem-parallel/nuvem/assoc.py)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/nuvem/comment.py?p2=incubator/nuvem/trunk/nuvem-parallel/nuvem/comment.py&p1=incubator/nuvem/trunk/nuvem-parallel/nuvem/assoc.py&r1=1104607&r2=1126266&rev=1126266&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-parallel/nuvem/assoc.py (original)
+++ incubator/nuvem/trunk/nuvem-parallel/nuvem/comment.py Sun May 22 22:47:15 2011
@@ -15,6 +15,6 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-def get(r, v, prop):
-    return ("'" + prop.eval(), v.get(r))
+def get(r, prop):
+    return prop.eval()
 

Copied: incubator/nuvem/trunk/nuvem-parallel/nuvem/item.py (from r1104607, incubator/nuvem/trunk/nuvem-parallel/nuvem/assoc.py)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/nuvem/item.py?p2=incubator/nuvem/trunk/nuvem-parallel/nuvem/item.py&p1=incubator/nuvem/trunk/nuvem-parallel/nuvem/assoc.py&r1=1104607&r2=1126266&rev=1126266&view=diff
==============================================================================
    (empty)

Added: incubator/nuvem/trunk/nuvem-parallel/nuvem/keychain.py
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/nuvem/keychain.py?rev=1126266&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-parallel/nuvem/keychain.py (added)
+++ incubator/nuvem/trunk/nuvem-parallel/nuvem/keychain.py Sun May 22 22:47:15 2011
@@ -0,0 +1,38 @@
+#  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, n, a):
+    nv = n.get(r)
+    ntv = nv[1:] if nv[0:1] == "'" else nv
+    av = a.get(r)
+
+    content = filter(lambda e: e[0] == "'content", av[0])
+    account = filter(lambda e: e[0] == "'account", () if len(content) == 0 else content[0])
+    keys = filter(lambda e: e[0] == "'keys", () if len(account) == 0 else account[0])
+    key = filter(lambda e: e[0] == "'key", () if len(keys) == 0 else keys[0])
+    ekey = () if len(key) == 0 else key[0]
+    akey = () if len(ekey) < 2 else ekey[1]
+
+    def namedkey(k):
+        return len(filter(lambda e: e[0] == "'@name" and e[1] == ntv, k)) != 0
+
+    def keyvalue(k):
+        return filter(lambda e: e[0] == "'@value", k)
+
+    kv = map(keyvalue, filter(namedkey, akey))
+    return None if len(kv) == 0 else kv[0][0][1]
+

Copied: incubator/nuvem/trunk/nuvem-parallel/nuvem/select.py (from r1104607, incubator/nuvem/trunk/nuvem-parallel/nuvem/search.py)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/nuvem/select.py?p2=incubator/nuvem/trunk/nuvem-parallel/nuvem/select.py&p1=incubator/nuvem/trunk/nuvem-parallel/nuvem/search.py&r1=1104607&r2=1126266&rev=1126266&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-parallel/nuvem/search.py (original)
+++ incubator/nuvem/trunk/nuvem-parallel/nuvem/select.py Sun May 22 22:47:15 2011
@@ -26,7 +26,7 @@ def get(r, p, l):
         return True
 
     def isAssoc(v):
-        return isList(v) and len(v) == 2 and isinstance(v[0], basestring) and v[0][0:1] ==
"'"
+        return isList(v) and len(v) >= 2 and isinstance(v[0], basestring) and v[0][0:1]
== "'"
 
     def lookup(pv, lv):
         if lv == ():
@@ -49,9 +49,7 @@ def get(r, p, l):
             if len(pv) == 1:
                 return (a,) + lookup(pv, lv[1:])
             # Continue to lookup children if any plus rest of the list
-            if isList(a[1]):
-                return lookup(pv[1:], a[1]) + lookup(pv, lv[1:])
-            return lookup(pv, lv[1:])
+            return lookup(pv[1:], a[1:]) + lookup(pv, lv[1:])
 
         # No match, lookup any children and rest of the list
         if (isList(a[1])):

Modified: incubator/nuvem/trunk/nuvem-parallel/test.py
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-parallel/test.py?rev=1126266&r1=1126265&r2=1126266&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-parallel/test.py (original)
+++ incubator/nuvem/trunk/nuvem-parallel/test.py Sun May 22 22:47:15 2011
@@ -27,9 +27,10 @@ from nuvem import true_
 from nuvem import false_
 from nuvem import number
 from nuvem import text
+from nuvem import comment
 from nuvem import name
 from nuvem import nothing
-from nuvem import assoc
+from nuvem import item
 from nuvem import pair
 from nuvem import call
 from nuvem import if_
@@ -50,7 +51,7 @@ from nuvem import itemnb
 from nuvem import names
 from nuvem import values
 from nuvem import lookup
-from nuvem import search
+from nuvem import select
 from nuvem import reverse
 from nuvem import shuffle_
 from nuvem import range_
@@ -76,6 +77,7 @@ from nuvem import param
 from nuvem import user
 from nuvem import realm
 from nuvem import email
+from nuvem import keychain
 from nuvem import url
 from nuvem import contains
 from nuvem import split
@@ -94,12 +96,14 @@ def testValues():
     assert nothing.get(()) == None
     assert number.get((), mkprop('value', lambda: 1)) == 1
     assert text.get((), mkprop('value', lambda: 'abc')) == 'abc'
+    assert comment.get((), mkprop('value', lambda: 'abc')) == 'abc'
     assert name.get((), mkprop('value', lambda: 'abc')) == "'abc"
-    assert assoc.get((), mkref('value', lambda r: 'def'), mkprop('key', lambda: 'abc')) ==
("'abc", 'def')
+    assert item.get((), mkref('value', lambda r: 'def'), mkprop('name', lambda: 'abc')) ==
("'abc", 'def')
     return True
 
 def testLogic():
-    assert call.get((), mkref('name', lambda r: 'abc'), mkref('proxy', lambda c, r: (c, r)))
== ('abc', ())
+    assert call.get((), mkref('name', lambda r: "'abc"), mkref('proxy', lambda c, r: (c,
r))) == ("'abc", ())
+    assert call.get((), mkref('name', lambda r: 'abc'), mkref('proxy', lambda c, r: (c, r)))
== ("'abc", ())
     assert if_.get((), mkref('cond', lambda r: True), mkref('then', lambda r: 'abc'), mkref('els',
lambda r: 'def')) == 'abc'
     assert if_.get((), mkref('cond', lambda r: False), mkref('then', lambda r: 'abc'), mkref('els',
lambda r: 'def')) == 'def'
     assert and_.get((), mkref('a', lambda r: False), mkref('b', lambda r: True)) == False
@@ -134,9 +138,6 @@ def testLists():
     assert itemnb.get((), mkref('i', lambda r: 1), mkref('l', lambda r: ('abc', 'def', 'ghi')))
== 'def'
     assert names.get((), mkref('l', lambda r: (("'a", 'abc'), ("'d", 'def'), ("'g", 'ghi'),
("'d", 'def2')))) == ("'a", "'d", "'g", "'d")
     assert values.get((), mkref('l', lambda r: (("'a", 'abc'), ("'d", 'def'), ("'g", 'ghi'),
("'d", 'def2')))) == ('abc', 'def', 'ghi', 'def2')
-    assert lookup.get((), mkref('n', lambda r: "'d"), mkref('l', lambda r: (("'a", 'abc'),
("'d", 'def'), ("'g", 'ghi'), ("'d", 'def2')))) == (("'d", 'def'), ("'d", 'def2'))
-    assert search.get((), mkref('n', lambda r: "'d.x"), mkref('l', lambda r: (("'a", 'abc'),
("'d", (("'x", 'def'), ("'y", "yyy"))), ("'g", 'ghi'), ("'d", (("'y", 'yyy'), ("'x", 'def2'))))))
== (("'x", 'def'), ("'x", 'def2'))
-    assert search.get((), mkref('n', lambda r: ("'d", "'x")), mkref('l', lambda r: (("'a",
'abc'), ("'d", (("'x", 'def'), ("'y", "yyy"))), ("'g", 'ghi'), ("'d", (("'y", 'yyy'), ("'x",
'def2')))))) == (("'x", 'def'), ("'x", 'def2'))
     assert reverse.get((), mkref('l', lambda r: ('abc', 'def', 'ghi'))) == ('ghi', 'def',
'abc')
     assert shuffle_.get((), mkref('l', lambda r: ('abc', 'def', 'ghi'))) != ()
     assert range_.get((), mkref('a', lambda r: '1'), mkref('b', lambda r: '4')) == (1, 2,
3)
@@ -146,6 +147,19 @@ def testLists():
     assert reduce_.get((), mkref('item', lambda r: "'i"), mkref('accum', lambda r: "'a"),
mkref('transform', lambda r: valueof.get(r, mkprop('name', lambda: 'a')) + valueof.get(r,
mkprop('name', lambda: 'i'))), mkref('init', lambda r: 0), mkref('list', lambda r: (1, 2,
3, 4))) == 10
     return True
 
+def testSelect():
+    assert lookup.get((), mkref('n', lambda r: "'d"), mkref('l', lambda r: (("'a", 'abc'),
("'d", 'def'), ("'g", 'ghi'), ("'d", 'def2')))) == (("'d", 'def'), ("'d", 'def2'))
+    assert select.get((), mkref('n', lambda r: "'d.x"), mkref('l', lambda r: (("'a", 'abc'),
("'d", (("'x", 'def'), ("'y", "yyy"))), ("'g", 'ghi'), ("'d", (("'y", 'yyy'), ("'x", 'def2'))))))
== (("'x", 'def'), ("'x", 'def2'))
+    assert select.get((), mkref('n', lambda r: "'d.x"), mkref('l', lambda r: (("'a", 'abc'),
("'d", (("'x", 'def'), ("'y", "yyy"))), ("'g", 'ghi'), ("'d", (("'y", 'yyy'), ("'x", 'def2'))))))
== (("'x", 'def'), ("'x", 'def2'))
+    assert select.get((), mkref('n', lambda r: ("'d", "'x")), mkref('l', lambda r: (("'a",
'abc'), ("'d", (("'x", 'def'), ("'y", "yyy"))), ("'g", 'ghi'), ("'d", (("'y", 'yyy'), ("'x",
'def2')))))) == (("'x", 'def'), ("'x", 'def2'))
+
+    dnf = (("'status", 'ok'), ("'origin", (''),), ("'dest", ('sc'),), ("'rows", ((("'elements",
((("'status", 'notfound'),),),),),),),)
+    assert select.get((), mkref('n', lambda r: "'status"), mkref('l', lambda r: dnf)) ==
(("'status", 'ok'), ("'status", 'notfound'))
+    assert select.get((), mkref('n', lambda r: "'rows.elements.status"), mkref('l', lambda
r: dnf)) == (("'status", 'notfound'),)
+
+    dok = (("'status", 'ok'), ("'origin", ('scruz'),), ("'dest", ('sc'),), ("'rows", ((("'elements",
((("'status", 'ok'), ("'duration", ("'value", 3761), ("'text", '1 hour 3 mins'),), ("'distance",
("'value", 82923), ("'text", '51.5 mi'),),),),),),),),)
+    assert select.get((), mkref('n', lambda r: "'distance.text"), mkref('l', lambda r: dok))
== (("'text", '51.5 mi'),)
+
 def testMath():
     assert add.get((), mkref('a', lambda r: 3), mkref('b', lambda r: 2)) == 5
     assert subtract.get((), mkref('a', lambda r: 3), mkref('b', lambda r: 2)) == 1
@@ -163,7 +177,7 @@ def testMath():
     assert max_.get((), mkref('l', lambda r: (1, 3, 2))) == 3
     return True
 
-def testURL():
+def testHTTP():
     assert host.get((), mkprop('host', lambda: 'localhost')) == 'localhost'
     assert path.get((), mkprop('path', lambda: ('abc', 'def'))) == ('abc', 'def')
     assert params.get((), mkprop('params', lambda: (("'a", 'abc'), ("'d", 'def')))) == (("'a",
'abc'), ("'d", 'def'))
@@ -171,7 +185,10 @@ def testURL():
     assert user.get((), mkprop('user', lambda: 'joe')) == 'joe'
     assert realm.get((), mkprop('realm', lambda: 'localhost')) == 'localhost'
     assert email.get((), mkprop('email', lambda: 'joe@localhost')) == 'joe@localhost'
-    assert url.get((), mkref('address', lambda r: 'http://localhost/'), mkref('args', lambda
r: ('test', 'path', ("'a", 1), ("'b", '2')))) == 'http://localhost/test/path?a=1&b=2'
+    kc = (("'entry", ("'title", 'User'), ("'id", 'user'), ("'content", ("'account", ("'description",
'User'), ("'keys", (
+        "'key", ((("'@name", 'key1'), ("'@value", 'value1')), (("'@name", 'key2'), ("'@value",
'value2')), (("'@name", 'key3'), ("'@value", 'value3')))))))),)
+    assert keychain.get((), mkref('n', lambda r: 'key2'), mkref('a', lambda r: kc)) == 'value2'
+    assert keychain.get((), mkref('n', lambda r: 'key4'), mkref('a', lambda r: kc)) is None
     return True
 
 def testText():
@@ -201,8 +218,9 @@ if __name__ == '__main__':
     testValues()
     testLogic()
     testLists()
+    testSelect()
     testMath()
-    testURL()
+    testHTTP()
     testText()
     testEval()
     print 'OK'



Mime
View raw message