如果我正确理解您的问题,为了实现这一点,您将需要覆盖getServiceRequest
您正在使用的 Gateway 类:
from pyamf.remoting.gateway.django import DjangoGateway
from pyamf.remoting.gateway import UnknownServiceError
class MyGateway(DjangoGateway):
def __init__(self, router_func, **kwargs):
self.router = router_func
DjangoGateway.__init__(self, **kwargs)
def getServiceRequest(self, request, target):
try:
return DjangoGateway.getServiceRequest(self, request, target)
except UnknownServiceError, e:
pass
# cached service was not found, try to discover it
try:
service_func = self.router(target)
except:
# perhaps some logging here
service_func = None
if not service_func:
# couldn't find a service matching `target`, crap out appropriately
raise e
self.addService(service_func, target)
return DjangoGateway.getServiceRequest(self, request, target)
self.router
是您提供给网关构造函数的函数。它采用 AMF 远程处理请求的字符串目标并返回匹配函数。如果它返回None
或引发异常,则会将未知的服务响应返回给请求者。
希望这有助于为您的需求奠定基础。