示例#1
0
    def load(self, module):
        """Load a specific module.
        
        This method:
            Get the Controller class defined in the module
            Get the controller's bundle
            Instanciate the Controller class
            Set the server instance attribute
            Write the newly created object in the bundle's controllers
            Return the object
        
        """
        bundle_name = Rule.bundle_name(module)
        bundle = self.server.bundles[bundle_name]
        name = Rule.module_name(module)
        class_name = name.capitalize()
        ctl_class = getattr(module, class_name)
        ctl_object = ctl_class(bundle)
        ctl_object.server = self.server

        # Write the object in the bundle
        bundle.controllers[class_name] = ctl_object

        # Add the controller's routes
        routes = tuple(bundle.config.routes.items())
        routes = [(name, infos) for name, infos in routes if infos[1] == \
                class_name]
        for route, (pattern, ctl_name, action, methods) in routes:
            action = getattr(ctl_object, action)
            self.server.dispatcher.add_route(route, pattern, ctl_object, \
                    action, methods)

        return ctl_object
示例#2
0
 def load(self, module):
     """Load a specific module.
     
     This method:
         Get the Controller class defined in the module
         Get the controller's bundle
         Instanciate the Controller class
         Set the server instance attribute
         Write the newly created object in the bundle's controllers
         Return the object
     
     """
     bundle_name = Rule.bundle_name(module)
     bundle = self.server.bundles[bundle_name]
     name = Rule.module_name(module)
     class_name = name.capitalize()
     ctl_class = getattr(module, class_name)
     ctl_object = ctl_class(bundle)
     ctl_object.server = self.server
     
     # Write the object in the bundle
     bundle.controllers[class_name] = ctl_object
     
     # Add the controller's routes
     routes = tuple(bundle.config.routes.items())
     routes = [(name, infos) for name, infos in routes if infos[1] == \
             class_name]
     for route, (pattern, ctl_name, action, methods) in routes:
         action = getattr(ctl_object, action)
         self.server.dispatcher.add_route(route, pattern, ctl_object, \
                 action, methods)
     
     return ctl_object
示例#3
0
 def unload(self, module):
     """Unload th emodule containing the controllers.
     
     Delete all the routes connected with this controller.
     
     """
     name = Rule.module_name(module)
     class_name = name.capitalize()
     ctl_class = getattr(module, class_name)
     self.server.dispatcher.delete_routes_for_controller(ctl_class)
示例#4
0
 def unload(self, module):
     """Unload th emodule containing the controllers.
     
     Delete all the routes connected with this controller.
     
     """
     name = Rule.module_name(module)
     class_name = name.capitalize()
     ctl_class = getattr(module, class_name)
     self.server.dispatcher.delete_routes_for_controller(ctl_class)
示例#5
0
文件: model.py 项目: v-legoff/pa-poc2
 def load(self, module):
     """Load a specific module.
     
     This method:
         Get the Model class defined in the module
         Set the data_connector class attribute of this class
         Write this dclass in the model's bundle
         Return the class
     
     """
     name = Rule.module_name(module)
     class_name = name.capitalize()
     mod_class = getattr(module, class_name)
     mod_class.data_connector = self.data_connector
     self.data_connector.record_model(mod_class)
     
     # Write the class in the bundles
     bundle_name = Rule.bundle_name(module)
     self.server.bundles[bundle_name].models[class_name] = mod_class
     return mod_class
示例#6
0
文件: model.py 项目: v-legoff/pa-poc2
    def load(self, module):
        """Load a specific module.
        
        This method:
            Get the Model class defined in the module
            Set the data_connector class attribute of this class
            Write this dclass in the model's bundle
            Return the class
        
        """
        name = Rule.module_name(module)
        class_name = name.capitalize()
        mod_class = getattr(module, class_name)
        mod_class.data_connector = self.data_connector
        self.data_connector.record_model(mod_class)

        # Write the class in the bundles
        bundle_name = Rule.bundle_name(module)
        self.server.bundles[bundle_name].models[class_name] = mod_class
        return mod_class
示例#7
0
 def load(self, module):
     """Load a specific package.
     
     This method:
         Get the Plugin class defined in the module
         Register this plugin in the plugin manager
         Subscribe this plugins.
         Return the class
     
     """
     name = Rule.module_name(module)
     plg_class = getattr(module, "Plugin")
     self.server.plugin_manager.register(name, plg_class)
     return plg_class
示例#8
0
 def load(self, module):
     """Load a specific package.
     
     This method:
         Get the Plugin class defined in the module
         Register this plugin in the plugin manager
         Subscribe this plugins.
         Return the class
     
     """
     name = Rule.module_name(module)
     plg_class = getattr(module, "Plugin")
     self.server.plugin_manager.register(name, plg_class)
     return plg_class
示例#9
0
    def load(self, module):
        """Load a specific module.
        
        This method:
            Get the Service class defined in the module
            Register this class in the server's services
            Return the class
        
        """
        name = Rule.module_name(module)
        class_name = name.capitalize()
        svc_class = getattr(module, class_name)

        # Register the service in the server
        self.server.services.register(class_name, svc_class)
        return svc_class
示例#10
0
    def load(self, module):
        """Load a specific module.
        
        This method:
            Get the Service class defined in the module
            Register this class in the server's services
            Return the class
        
        """
        name = Rule.module_name(module)
        class_name = name.capitalize()
        svc_class = getattr(module, class_name)

        
        # Register the service in the server
        self.server.services.register(class_name, svc_class)
        return svc_class
示例#11
0
 def load(self, module):
     """Load a specific module.
     
     This method:
         Get the WebSocketHandler class defined in the module
         Return the class
     
     """
     name = Rule.module_name(module)
     class_name = name.capitalize()
     wsh_class = getattr(module, class_name)
     
     wsh_class.handlers = []
     if not wsh_class.ws_point:
         raise ValueError("the 'ws_point' class attribute is not " \
                 "set in {}".format(wsh_class))
     
     return wsh_class
示例#12
0
    def load(self, module):
        """Load a specific module.
        
        This method:
            Get the WebSocketHandler class defined in the module
            Return the class
        
        """
        name = Rule.module_name(module)
        class_name = name.capitalize()
        wsh_class = getattr(module, class_name)

        wsh_class.handlers = []
        if not wsh_class.ws_point:
            raise ValueError("the 'ws_point' class attribute is not " \
                    "set in {}".format(wsh_class))

        return wsh_class