【发布时间】:2009-09-09 06:33:35
【问题描述】:
将远程 FIFO 队列实现为 Python GAE 应用程序然后将名称-值对字典推入/拉出它的最简单方法是什么?
例如,当对 GAE 应用程序进行 http get 时,GAE 应用程序将返回发布到应用程序且之前未从队列中拉出的最早的名称-值对集合。然后,这些名称-值对将在客户端重新实例化为字典。 urllib.urlencode 提供了一种将字典编码为参数的简单机制,但是当您 http“获取”参数时,将参数解码为字典的类似简单方法是什么?当队列中没有项目时,GAE 应用程序应返回 null 或客户端可以响应的其他更合适的标识符。
#A local python script
import urllib
targetURL="http://myapp.appspot.com/queue"
#Push to dictionary to GAE queue
params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
f = urllib.urlopen(targetURL, params)
print f.read()
params = urllib.urlencode({'foo': 1, 'bar': 2})
f = urllib.urlopen(targetURL, params)
print f.read()
#Pull oldest set of name-value pairs from the GAE queue and create a local dictionary from them.
#f = urllib.urlopen(targetURL, ……)
#returnedDictionary = ????
实现这个简短的 GAE 应用程序的最简单方法是什么?
#queue.py a url handler in a GAE application.
# For posts, create an object from the posted name-value pairs and insert it into the queue as the newest item in the queue
# For gets, return the name-value pairs for the oldest object in the queue and remove the object from the queue.
# If there are no items in the queue, return null
【问题讨论】: