本文整理匯總了Python中structure.Structure.store方法的典型用法代碼示例。如果您正苦於以下問題:Python Structure.store方法的具體用法?Python Structure.store怎麽用?Python Structure.store使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類structure.Structure
的用法示例。
在下文中一共展示了Structure.store方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RootDataRef
# 需要導入模塊: from structure import Structure [as 別名]
# 或者: from structure.Structure import store [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 store [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
#.........這裏部分代碼省略.........