本文整理汇总了Python中core.event_bus.EventBus类的典型用法代码示例。如果您正苦于以下问题:Python EventBus类的具体用法?Python EventBus怎么用?Python EventBus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventBus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: album_delete_handler
def album_delete_handler(reply):
users = [ {
'firstname': 'Michael',
'lastname': 'Kuty',
'email': '[email protected]',
'username': 'admin',
'password': 'admin'
},{
'firstname': 'Jakub',
'lastname': 'Josef',
'email': '[email protected]',
'username': 'kuba',
'password': 'kuba'
},{
'firstname': 'Test',
'lastname': 'Test',
'email': '[email protected]',
'username': 'test',
'password': 'pass'
}
]
# Insert albums - in real life 'price' would probably be stored in a different collection, but, hey, this is a demo.
for i in range(0, len(users)):
EventBus.send('vertx.mongopersistor', {
'action': 'save',
'collection': 'users',
'document': users[i]
}, reply_handler=None)
示例2: get_auth_uid
def get_auth_uid(msg):
if (msg.body != None):
document["userID"] = msg.body
def save_file_db(message):
fs.move(filename, path_upload+msg.body+"/"+upload.filename, handler = None)
#logger.info(message.body)
EventBus.send("vertx.mongopersistor", {"action": "save","collection":"files","document":document}, reply_handler=save_file_db)
示例3: handler
def handler(msg):
print "Received message"
flights = JsonArray()
for flight in msg.body:
the_flight = JsonObject()
#print str(flight)
#the_flight.putString("name", flight.getString("callsign"))
#the_flight.putString("planeType", flight.getString("equipment") )
the_flight.putString("speed", flight.get("properties").get("direction"))
the_flight.putString("alt", flight.get("properties").get("route"))
position_array = flight.get("geometry").get("coordinates")
#print position_array
#There can sometimes be two positions readings but I am not sure what they do so I am just going to take the first
#position = position_array[0]
the_flight.putNumber("lat", position_array[1])
the_flight.putNumber("lon", position_array[0])
#build the object to persist to mongo
forMongo = JsonObject()
forMongo.putString("action", "save")
forMongo.putString("collection", "buses")
forMongo.putObject("document", the_flight)
#persist it
EventBus.publish('vertx.mongopersistor', forMongo)
#add now to the array
flights.addObject(the_flight)
#Sent the array on the EventBus - this is the one the page should subscribe to
EventBus.publish('flights.updated', flights)
print("published the flights")
示例4: handler_func
def handler_func(self, msg):
tu.azzert(msg.address == address)
tu.azzert(msg.body['message'] == json['message'])
EventBus.unregister_handler(self.id)
self.count[0] += 1
if self.count[0] == num_handlers:
tu.test_complete()
示例5: init_autostart
def init_autostart(config):
for i, cfg in enumerate(config.get('autostart', [])):
if not cfg.get('enabled', True):
logger.info("Skipping disabled config #%d" % i)
continue
cfg['id'] = "autostart-" + str(i)
EventBus.send('hbdriver:start', cfg, lambda msg: logger.info("Started hosebird for config #%d: %s" % (i, msg.body)))
示例6: body_handler
def body_handler(body):
if resp.status_code == 200:
favs['favorites'] = json.loads(body.to_string())
else:
print "Failed to fetch favorites: %s" % body.to_string()
EventBus.send('log.event', "user.favorites.list.result")
EventBus.send('user.favorites.list.result', json.dumps(favs))
示例7: deploy_handler
def deploy_handler(err, id):
if err is None:
# import static_data
print "loaded " + id
def bla(reply,r2): print 'bla',reply,r2
EventBus.send_with_timeout("campudus.jsonvalidator", {
"action" : "addSchema",
"key" : "simpleAddSchema",
"jsonSchema" : {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
}
}, 1000, bla)
EventBus.send("campudus.jsonvalidator", {"action":"getSchemaKeys"}, bla)
else:
print 'Failed to deploy %s' % err
err.printStackTrace()
示例8: mkdir_path
def mkdir_path(message):
logger.info(message.body)
sessionID = message.body.get("sessionID", None)
if (sessionID == None): message.reply("sessionID is not valid")
userID = ""
def get_auth_uid(uid):
if (uid.body == None): message.reply("AUTHORISE_FAIL")
else:
userID = uid.body
if (userID != None):
def exists_handler(msge):
if (msge.body == True) or (msge.body == False):
if (msge.body == True):
def mkdir_handler(result):
logger.info(result.body)
message.reply(result.body)
folder = message.body.get("name", None)
if (folder != None):
EventBus.send("mkdir_handler",{"userID":userID,"name":folder},mkdir_handler)
elif (msge.body == False):
logger.info("must be created")
def mkdir_handler(result):
logger.info(result.body)
message.reply(result.body)
EventBus.send("mkdir_handler",{"userID":userID,"name":""},mkdir_handler)
else: message.reply("error")
else: message.reply("error")
EventBus.send("exists.handler", {"uid":uid.body} , exists_handler)
EventBus.send("get_auth_uid", {"sessionID":sessionID}, get_auth_uid)
示例9: user_save_or_update
def user_save_or_update(message):
user = message.body.get("user", None)
if 'password2' in user: del user['password2']
#logger.info(user)
def user_existss(msg):
#logger.info(msg.body)
if (msg.body == None):
#logger.info(msg.body)
def save_result_handler(msg):
def login(login):
if "password" in user: del user["password"]
message.reply({"user":user,"sessionID":login.body})
def reply(res):
logger.info(res.body)
EventBus.send("login_user", {"username":user.get("username"),"password":user.get("password")}, login)
EventBus.send("registration_mail",{"user":user},reply)
EventBus.send("vertx.mongopersistor",{"action":"save", "collection":message.body.get("collection"), "document": user},save_result_handler)
else:
#TODO upsert create new document when 0 result from criteria :-)
update = {"action":"update", "collection": message.body.get("collection"),
"criteria": {"_id": msg.body},
"objNew" : user,
"upsert": False,
"multi": False
}
def update_result_handler(msg):
message.reply(user.get('_id'))
EventBus.send("vertx.mongopersistor",update,update_result_handler)
EventBus.send("get_user_uid", {"username": user.get("username")}, user_existss)
示例10: simple_search
def simple_search(message):
matcher = None
collection = message.body.get("collection", None)
tmp_matcher = message.body.get("matcher", None)
sessionID = message.body.get("sessionID", None)
public = message.body.get("public", None)
#use python $regex
matcher = {
"filename": {
'$regex': tmp_matcher.get("filename"),
'$options': 'ix'
},
}
logger.info(public)
if ((sessionID != None) and (collection != None) and (matcher != None)):
def get_auth_uid(uid):
if (uid.body == None): message.reply(None)
else:
userID = uid.body
if (public == None):
matcher["public"] = True
else:
matcher["userID"] = userID
matcher["public"] = False
def reply_handler(msg):
message.reply(msg.body)
EventBus.send("search",{"collection":collection,"matcher":matcher}, reply_handler)
EventBus.send("get_auth_uid", {"sessionID":sessionID}, get_auth_uid)
else:
matcher["public"] = True
def reply_handler(msg):
message.reply(msg.body)
EventBus.send("search",{"collection":collection,"matcher":matcher}, reply_handler)
示例11: search
def search(message):
collection = message.body.get("collection")
matcher = message.body.get("matcher")
if (collection != None) and (matcher != None):
def result_handler(msg):
status = msg.body.get("status")
if (status == "ok"):
logger.info(msg.body.get("results"))
#if (msg.body.get("results") == []): #message.reply("WARN")
reply = {
"status": "ok",
"files": {}
}
files = []
for res in msg.body.get("results"):
#del res["_id"]
files.append(res)
reply["files"] = files
message.reply(reply)
else:
logger.war("mongo fail %s"% status)
message.reply(status)
EventBus.send("vertx.mongopersistor", {"action":"find","collection":collection,"matcher":matcher},result_handler)
else:
message.reply("search wrong params")
示例12: get_file
def get_file(message):
sessionID = message.body.get("sessionID", None)
fileID = message.body.get("fileID", None)
if (sessionID != None and fileID != None):
def authorize_handler(msg):
if (msg.body != None):
def get_user_id(uid):
if (uid.body != None):
def reply_handler(msg):
logger.info(msg.body)
if msg.body != None:
message.reply(msg.body)
else: message.reply(None)
EventBus.send("get_file_from_db",{"fileID":fileID},reply_handler)
else: message.reply(None)
EventBus.send("get_user_uid", {"username":msg.body}, get_user_id)
else: message.reply(None)
EventBus.send("local.authorize", {"sessionID":sessionID}, authorize_handler)
elif (fileID != None):
def reply_handler(msg):
logger.info(msg.body)
if msg.body != None:
message.reply(msg.body)
else: message.reply(None)
EventBus.send("get_file_from_db",{"fileID":fileID},reply_handler)
示例13: upload_handler
def upload_handler(upload):
# create path for file with new name
#TODO SEPARATION collections
document = {
"filename": upload.filename,
"size": upload.size,
"content_type":upload.content_type,
"ext": upload.filename.split('.')[len(upload.filename.split('.'))-1],
"content_transfer_encoding": upload.content_transfer_encoding,
"charset": upload.charset,
"create_time": date.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
}
if (sessionID == None):
document["public"] = True
document["_id"] = file_id
def save_file_db(message):
def mkdir_handler(err, mkdir_res):
if not err:
fs.move(filename, path_public+ file_id + "/" + upload.filename, handler = None)
fs.mkdir(path_public + file_id + "/",perms=None,handler=mkdir_handler)
#TODO create dir from uid in public section and move file into
EventBus.send("vertx.mongopersistor", {"action": "save","collection":"files","document":document}, reply_handler=save_file_db)
else:
document["public"] = False
def get_auth_uid(msg):
if (msg.body != None):
document["userID"] = msg.body
def save_file_db(message):
fs.move(filename, path_upload+msg.body+"/"+upload.filename, handler = None)
#logger.info(message.body)
EventBus.send("vertx.mongopersistor", {"action": "save","collection":"files","document":document}, reply_handler=save_file_db)
EventBus.send("get_auth_uid", {"sessionID":sessionID}, get_auth_uid)
示例14: login_handler
def login_handler(msg):
user = msg.body
id = vertx.config()['user-prefix'] + str(uuid.uuid4())
users.add(user)
EventBus.register_handler(id,
handler=lambda msg: command_handler(user, msg))
EventBus.publish(vertx.config()['users-address'], user)
msg.reply({'id': id, 'users': list(users)})
示例15: body_handler
def body_handler(body):
if resp.status_code == 200:
data = json.loads(body.to_string())
print data
def bla(reply): print dir(reply), reply.message
EventBus.send("auth.github.login", data, bla)
else:
print resp.status_code, body.to_string()