本文整理汇总了Python中pyon.util.containers.DotDict.get方法的典型用法代码示例。如果您正苦于以下问题:Python DotDict.get方法的具体用法?Python DotDict.get怎么用?Python DotDict.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.util.containers.DotDict
的用法示例。
在下文中一共展示了DotDict.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ChatServerService
# 需要导入模块: from pyon.util.containers import DotDict [as 别名]
# 或者: from pyon.util.containers.DotDict import get [as 别名]
class ChatServerService(BaseChatsService):
def on_init(self):
print "INIT CHAT SERVER"
self.clients = DotDict()
def register(self, user_name='', proc_id=''):
print "Registering user %s, client %s" % (user_name, proc_id)
client = ProcessRPCClient(node=self.container.node, name=proc_id, iface=IChatcService, process=self)
self.clients[user_name] = DotDict(procid=proc_id, user_name=user_name, client=client)
return "OK"
def unregister(self, user_name=''):
log.debug("Unregistering client %s" % proc_id)
del self.clients[user_name]
return "OK"
def message(self, from_name='', to_name='', text=''):
if to_name == "all":
for cl in self.clients.values():
cl['client'].message(from_name=from_name, text=text)
else:
client = self.clients.get(to_name, None)
if client:
client.client.message(from_name=from_name, text=text)
else:
return "USER NOT FOUND"
return "OK"
def list_users(self):
return str(self.clients.keys())
示例2: request
# 需要导入模块: from pyon.util.containers import DotDict [as 别名]
# 或者: from pyon.util.containers.DotDict import get [as 别名]
def request(self, query=None, id_only=True):
if not query:
raise BadRequest('No request query provided')
if "QUERYEXP" in query and self.ds_discovery:
# Support for datastore queries
pass
else:
if not query.has_key('query'):
raise BadRequest('Unsuported request. %s')
#==============================
# Check the form of the query
#==============================
#@todo: convert to IonObject
if not (query.has_key('query')):
raise BadRequest('Improper query request: %s' % query)
# Inject RR query execution e.g. for postgres
if self.ds_discovery:
res = self.ds_discovery.execute_query(query, id_only=id_only)
return res
# ---------------------------
# Number of results to return
# ---------------------------
limit = int(query.get('limit',self.MAX_SEARCH_RESULTS))
query_queue = list()
query = DotDict(query)
# -- former tier-1 (no and/or) search, returns an elasticsearch object
if (len(query.get('and',[])) + len(query.get('or',[])) == 0 ):
return self.query_request(query.query,limit=self.SEARCH_BUFFER_SIZE)[:limit]
query_queue.append(self.query_request(query.query,limit=self.SEARCH_BUFFER_SIZE, id_only=True))
#==================
# Intersection
#==================
for q in query.get('and',[]):
query_queue.append(self.query_request(q, limit=self.SEARCH_BUFFER_SIZE, id_only=True))
while len(query_queue) > 1:
tmp = self.intersect(query_queue.pop(), query_queue.pop())
query_queue.append(tmp)
#==================
# Union
#==================
for q in query.get('or',[]):
query_queue.append(self.query_request(q, limit=self.SEARCH_BUFFER_SIZE, id_only=True))
while len(query_queue) > 1:
tmp = self.union(query_queue.pop(), query_queue.pop())
query_queue.append(tmp)
if id_only:
return query_queue[0][:limit]
objects = self.clients.resource_registry.read_mult(query_queue[0][:limit])
return objects