GAAM(Google App Engine)的pyAMF,需要的帮助很少:(pyAMF for GAE (Google App Engine), little help needed:)

编程入门 行业动态 更新时间:2024-10-20 05:47:40
GAAM(Google App Engine)的pyAMF,需要的帮助很少:(pyAMF for GAE (Google App Engine), little help needed:) # I need this behaviour: # 1) check if the service from flash is included in the services array # 2) if not, return false or an error | if yes, step 3 # 3) combine the rootPath('app.controllers') with the service name('sub1.sub2.sub3.function_name') # 4) and then get the function('function_name') from the 'app.controllers.sub1.sub2.sub3.function_name' package # 5) then run the function the way that would be done normally by pyAMF from app.controllers.users.login import login from app.controllers.users.logout import logout from app.controllers.profiles.edit import edit as profilesEdit from app.controllers.profiles.new import new as profilesNew from app.controllers.invitations.invite import invite as invitationsInvite from app.controllers.invitations.uninvite import uninvite as invitationsUninvite def main(): services = { 'users.login': login, 'users.logout': logout, 'profiles.edit': profilesEdit, 'profiles.new': profilesNew, 'invitations.invite': invitationsInvite, 'invitations.uninvite': invitationsUninvite } gateway = WebAppGateway(services, logger=logging, debug=True) application = webapp.WSGIApplication([('/', Init), ('/ajax', gateway)], debug=True) run_wsgi_app(application)

我希望:

def main(): services = [ 'users.login', 'users.logout', 'profiles.edit', 'profiles.new', 'invitations.invite', 'invitations.uninvite', 'sub1.sub2.sub3.function_name' ] rootPath = 'app.controllers' gateway = WebAppGateway(services, rootPath, logger=logging, debug=True) application = webapp.WSGIApplication([('/', Init), ('/ajax', gateway)], debug=True) run_wsgi_app(application) # and then I would extend the WebAppGateway in some way to have this behaviour: # 1) check if the service from flash is included in the services array # 2) if not, return false or an error | if yes, step 3 # 3) combine the rootPath('app.controllers') with the service name('sub1.sub2.sub3.function_name') # 4) and then get the function('function_name') from the 'app.controllers.sub1.sub2.sub3.function_name' package # 5) then run the function the way that would be done normally by pyAMF

这可能吗? 谢谢

# I need this behaviour: # 1) check if the service from flash is included in the services array # 2) if not, return false or an error | if yes, step 3 # 3) combine the rootPath('app.controllers') with the service name('sub1.sub2.sub3.function_name') # 4) and then get the function('function_name') from the 'app.controllers.sub1.sub2.sub3.function_name' package # 5) then run the function the way that would be done normally by pyAMF from app.controllers.users.login import login from app.controllers.users.logout import logout from app.controllers.profiles.edit import edit as profilesEdit from app.controllers.profiles.new import new as profilesNew from app.controllers.invitations.invite import invite as invitationsInvite from app.controllers.invitations.uninvite import uninvite as invitationsUninvite def main(): services = { 'users.login': login, 'users.logout': logout, 'profiles.edit': profilesEdit, 'profiles.new': profilesNew, 'invitations.invite': invitationsInvite, 'invitations.uninvite': invitationsUninvite } gateway = WebAppGateway(services, logger=logging, debug=True) application = webapp.WSGIApplication([('/', Init), ('/ajax', gateway)], debug=True) run_wsgi_app(application)

insted of this I would like:

def main(): services = [ 'users.login', 'users.logout', 'profiles.edit', 'profiles.new', 'invitations.invite', 'invitations.uninvite', 'sub1.sub2.sub3.function_name' ] rootPath = 'app.controllers' gateway = WebAppGateway(services, rootPath, logger=logging, debug=True) application = webapp.WSGIApplication([('/', Init), ('/ajax', gateway)], debug=True) run_wsgi_app(application) # and then I would extend the WebAppGateway in some way to have this behaviour: # 1) check if the service from flash is included in the services array # 2) if not, return false or an error | if yes, step 3 # 3) combine the rootPath('app.controllers') with the service name('sub1.sub2.sub3.function_name') # 4) and then get the function('function_name') from the 'app.controllers.sub1.sub2.sub3.function_name' package # 5) then run the function the way that would be done normally by pyAMF

is this possible? thanks

最满意答案

昨晚解决了! 谢谢@njoyce

from pyamf.remoting.gateway.google import WebAppGateway import logging class TottysGateway(WebAppGateway): def __init__(self, services_available, root_path, not_found_service, logger, debug): # override the contructor and then call the super self.services_available = services_available self.root_path = root_path self.not_found_service = not_found_service WebAppGateway.__init__(self, {}, logger=logging, debug=True) def getServiceRequest(self, request, target): # override the original getServiceRequest method try: # try looking for the service in the services list return WebAppGateway.getServiceRequest(self, request, target) except: pass try: # don't know what it does but is an error for now service_func = self.router(target) except: if(target in self.services_available): # only if is an available service import it's module # so it doesn't access services that should be hidden try: module_path = self.root_path + '.' + target paths = target.rsplit('.') func_name = paths[len(paths) - 1] import_as = '_'.join(paths) + '_' + func_name import_string = "from "+module_path+" import "+func_name+' as service_func' exec import_string except: service_func = False if(not service_func): # if is not found load the default not found service module_path = self.rootPath + '.' + self.not_found_service import_string = "from "+module_path+" import "+func_name+' as service_func' # add the service loaded above assign_string = "self.addService(service_func, target)" exec assign_string return WebAppGateway.getServiceRequest(self, request, target)

Solved last night! thanks @njoyce

from pyamf.remoting.gateway.google import WebAppGateway import logging class TottysGateway(WebAppGateway): def __init__(self, services_available, root_path, not_found_service, logger, debug): # override the contructor and then call the super self.services_available = services_available self.root_path = root_path self.not_found_service = not_found_service WebAppGateway.__init__(self, {}, logger=logging, debug=True) def getServiceRequest(self, request, target): # override the original getServiceRequest method try: # try looking for the service in the services list return WebAppGateway.getServiceRequest(self, request, target) except: pass try: # don't know what it does but is an error for now service_func = self.router(target) except: if(target in self.services_available): # only if is an available service import it's module # so it doesn't access services that should be hidden try: module_path = self.root_path + '.' + target paths = target.rsplit('.') func_name = paths[len(paths) - 1] import_as = '_'.join(paths) + '_' + func_name import_string = "from "+module_path+" import "+func_name+' as service_func' exec import_string except: service_func = False if(not service_func): # if is not found load the default not found service module_path = self.rootPath + '.' + self.not_found_service import_string = "from "+module_path+" import "+func_name+' as service_func' # add the service loaded above assign_string = "self.addService(service_func, target)" exec assign_string return WebAppGateway.getServiceRequest(self, request, target)

更多推荐

本文发布于:2023-08-06 03:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444470.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:App   Google   GAAM   Engine   needed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!