本文整理汇总了Python中structure.Structure.get方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.get方法的具体用法?Python Structure.get怎么用?Python Structure.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类structure.Structure
的用法示例。
在下文中一共展示了Structure.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RootDataRef
# 需要导入模块: from structure import Structure [as 别名]
# 或者: from structure.Structure import get [as 别名]
class RootDataRef(DataRef):
'''A reference to a root of a Firbase.'''
def __init__(self, url, ssl_options=None):
'''Construct a new Firebase reference from a full Firebase URL.'''
self.connection = Connection(url, self, ssl_options=ssl_options)
self.base_url = url
self.structure = Structure(self)
self.subscriptions = {}
self.history = []
self.connection.daemon = True
self.connection.start()
self._keep_alive()
atexit.register(self.close)
DataRef.__init__(self, self, '')
def _process(self, message):
'''Process a single incoming message'''
# This whole thing needs to be rewritten to use all the new information about the protocol
debug(message)
# If message type is data
if message['t'] == 'd':
data = message['d']
# If r is in data and set to 1 then it's probably a response
# to something we sent like a sub request or an auth token
if 'r' in data:
historical_entry = self.history[data['r']-1]
request = historical_entry['message']
callbacks = historical_entry['callbacks']
error = data['b']['s']
if error != 'ok':
if error == 'permission_denied':
path = request['d']['b']['p']
print 'FIREBASE WARNING: on() or once() for %s failed: %s' % (path, error)
elif error == 'expired_token' or error == 'invalid_token':
print 'FIREBASE WARNING: auth() failed: %s' % (error)
else:
path = request['d']['b']['p']
print 'FIREBASE WARNING: unknown for %s failed: %s' % (path, error)
onCancel = callbacks.get('onCancel', None)
if not onCancel is None:
onCancel(error)
onComplete = callbacks.get('onComplete', None)
if not onComplete is None:
onComplete(error if error != 'ok' else None)
# If t is in data then it's the response to the initial connection, maybe
elif 't' in data:
pass
# If a is in data, it's a new data blob for a node, maybe
elif 'a' in data:
if data['a'] == 'c':
# This type of message is created when we lose permission to read
# and it requires some extra effort to implement as we call onCancel
# for all effected callbacks, which are any anscestors of the path
pass
else:
b_data = data['b']
path = b_data['p']
path_data = b_data['d']
self._store(path, path_data)
# If message type is... control?
if message['t'] == 'c':
pass
def _store(self, path, path_data):
'''Store a single path worth of data into the strucutre.'''
if not path or path[0] != "/":
path = "/%s" % path
self.structure.store(path, path_data)
def _send(self, message, callbacks=None):
'''Send a single message to Firebase.'''
historical_entry = {
'message': message,
'callbacks': {} if callbacks is None else callbacks
}
self.history.append(historical_entry)
message['d']['r'] = len(self.history)
self.connection.send(message)
def _subscribe(self, path, query, callbacks=None):
'''Subscribe to updates regarding a path'''
isSubscribed = self._is_subscribed(path, query)
# A subscription (listen) request takes two main arguments, p (path) and q (query).
if not isSubscribed:
#.........这里部分代码省略.........
示例2: RootDataRef
# 需要导入模块: from structure import Structure [as 别名]
# 或者: from structure.Structure import get [as 别名]
class RootDataRef(DataRef):
"""A reference to a root of a Firbase."""
def __init__(self, url):
"""Construct a new Firebase reference from a full Firebase URL."""
self.connection = Connection(url, self)
self.base_url = url
self.structure = Structure(self)
self.subscriptions = {}
self.history = []
self.connection.daemon = True
self.connection.start()
atexit.register(self.close)
DataRef.__init__(self, self, "")
def _process(self, message):
"""Process a single incoming message"""
# This whole thing needs to be rewritten to use all the new information about the protocol
debug(message)
# If message type is data
if message["t"] == "d":
data = message["d"]
# If r is in data and set to 1 then it's probably a response
# to something we sent like a sub request or an auth token
if "r" in data:
historical_entry = self.history[data["r"] - 1]
request = historical_entry["message"]
callbacks = historical_entry["callbacks"]
error = data["b"]["s"]
if error != "ok":
if error == "permission_denied":
path = request["d"]["b"]["p"]
print "FIREBASE WARNING: on() or once() for %s failed: %s" % (path, error)
elif error == "expired_token" or error == "invalid_token":
print "FIREBASE WARNING: auth() failed: %s" % (error)
else:
path = request["d"]["b"]["p"]
print "FIREBASE WARNING: unknown for %s failed: %s" % (path, error)
onCancel = callbacks.get("onCancel", None)
if not onCancel is None:
onCancel(error)
onComplete = callbacks.get("onComplete", None)
if not onComplete is None:
onComplete(error if error != "ok" else None)
# If t is in data then it's the response to the initial connection, maybe
elif "t" in data:
pass
# If a is in data, it's a new data blob for a node, maybe
elif "a" in data:
if data["a"] == "c":
# This type of message is created when we lose permission to read
# and it requires some extra effort to implement as we call onCancel
# for all effected callbacks, which are any anscestors of the path
pass
else:
b_data = data["b"]
path = b_data["p"]
path_data = b_data["d"]
self._store(path, path_data)
# If message type is... control?
if message["t"] == "c":
pass
def _store(self, path, path_data):
"""Store a single path worth of data into the strucutre."""
if not path or path[0] != "/":
path = "/%s" % path
self.structure.store(path, path_data)
def _send(self, message, callbacks=None):
"""Send a single message to Firebase."""
historical_entry = {"message": message, "callbacks": {} if callbacks is None else callbacks}
self.history.append(historical_entry)
message["d"]["r"] = len(self.history)
self.connection.send(message)
def _subscribe(self, path, query, callbacks=None):
"""Subscribe to updates regarding a path"""
isSubscribed = self._is_subscribed(path, query)
# A subscription (listen) request takes two main arguments, p (path) and q (query).
if not isSubscribed:
message = {"t": "d", "d": {"r": 0, "a": "l", "b": {"p": path}}}
if not query is None:
message["d"]["b"]["q"] = query
#.........这里部分代码省略.........