本文整理汇总了Python中core.event_bus.EventBus.send方法的典型用法代码示例。如果您正苦于以下问题:Python EventBus.send方法的具体用法?Python EventBus.send怎么用?Python EventBus.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.event_bus.EventBus
的用法示例。
在下文中一共展示了EventBus.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deploy_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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()
示例2: body_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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))
示例3: mkdir_path
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)
示例4: search
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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")
示例5: upload_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)
示例6: simple_search
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)
示例7: init_autostart
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)))
示例8: user_save_or_update
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)
示例9: album_delete_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)
示例10: get_auth_uid
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)
示例11: get_file
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)
示例12: body_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
def body_handler(body):
print "JOO", body
EventBus.send('smart.session.manager', {'action': 'start'}, bla)
if resp.status_code == 200:
data = json.loads(body.to_string())
print data
else:
logger.error(body)
示例13: body_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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()
示例14: save_result_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
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)
示例15: register_
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import send [as 别名]
def register_(public_actions):
for package in public_actions:
for module in package:
#TODO IMPORT HERE
for action in module:
def reply(msg):
logger.info(msg.body)
EventBus.send("register_method",{"address:action","method":method,"module":module}, reply)