def factory(cfg_manager, protocols, methods): if not _Protocols.isProtocols(protocols): #Maybe it is just one protocol try: protocols[0] except TypeError: raise TypeError( 'protocols "%s" must be either a non-empty sequence or a Protocols' % protocols) except IndexError: raise TypeError( 'protocols "%s" must be either a non-empty sequence or a Protocols' % protocols) for i in protocols: if not _Protocols.isProtocols(i): raise TypeError( 'protocol "%s" inside protocols "%s" not a valid Protocols value' % (i, protocols)) if not isinstance(methods, list) and not isinstance( methods, dict) and not isinstance(methods, tuple): raise TypeError('methods "%s" must be a dict, tuple or list' % methods) def build_server(cfg_manager, protocol): #If protocols is a valid protocol (ie 'Direct') it will look for the following class: # mySystem.calls.Direct.ServerDirect moduleName = 'Server' + protocol #mySystem will be something like 'voodoo.gen.' mySystem = __name__[:__name__.find('generators')] full_module_name = mySystem + 'protocols.' + protocol + '.' + moduleName mod = __import__(full_module_name, globals(), locals(), [moduleName]) return mod.generate(cfg_manager, methods) # "servers" will be a dictionary with the name of the callback as key # and a class which uses this protocol to offer the parameters asked # in "methods". The value is a class (not an instance) servers = {} # If it is only one protocol if _Protocols.isProtocols(protocols): servers[protocols] = build_server(cfg_manager, protocols) # If there is a sequence of protocols else: for i in protocols: servers[i] = build_server(cfg_manager, i) return _generate_server_skel(methods, servers)
def factory(cfg_manager, protocols, methods): if not _Protocols.isProtocols(protocols): #Maybe it is just one protocol try: protocols[0] except TypeError: raise TypeError('protocols "%s" must be either a non-empty sequence or a Protocols' % protocols) except IndexError: raise TypeError('protocols "%s" must be either a non-empty sequence or a Protocols' % protocols) for i in protocols: if not _Protocols.isProtocols(i): raise TypeError('protocol "%s" inside protocols "%s" not a valid Protocols value' % (i,protocols)) if not isinstance(methods,list) and not isinstance(methods,dict) and not isinstance(methods,tuple): raise TypeError('methods "%s" must be a dict, tuple or list' % methods) def build_server(cfg_manager, protocol): #If protocols is a valid protocol (ie 'Direct') it will look for the following class: # mySystem.calls.Direct.ServerDirect moduleName = 'Server' + protocol #mySystem will be something like 'voodoo.gen.' mySystem = __name__[:__name__.find('generators')] full_module_name = mySystem+'protocols.'+protocol+'.'+moduleName mod = __import__(full_module_name, globals(), locals(), [ moduleName ]) return mod.generate(cfg_manager, methods) # "servers" will be a dictionary with the name of the callback as key # and a class which uses this protocol to offer the parameters asked # in "methods". The value is a class (not an instance) servers = {} # If it is only one protocol if _Protocols.isProtocols(protocols): servers[protocols] = build_server(cfg_manager, protocols) # If there is a sequence of protocols else: for i in protocols: servers[i] = build_server(cfg_manager, i) return _generate_server_skel(methods, servers)
def factory(protocol, methods): if not _Protocols.isProtocols(protocol): raise TypeError('protocol "%s" not a valid Protocols value' % protocol) if not isinstance(methods,list) and not isinstance(methods,dict): raise TypeError('methods "%s" not a dict or list' % methods) #If protocol is a valid protocol (ie 'Direct') it will look for the following class: # mySystem.calls.Direct.ClientDirect moduleName = 'Client'+protocol #mySystem will be something like 'voodoo.' mySystem = __name__[:__name__.find('generators')] full_module_name = mySystem+'protocols.'+protocol+'.'+moduleName __import__(full_module_name, globals(), locals()) module = sys.modules[full_module_name] return module.generate(methods)