Beispiel #1
0
 def _create(cls, api):
     data = singleton(LocaleData, api, factory=LocaleData._create)
     translator = singleton(Translator, api, factory=Translator._create)
     locale = api.request.locale()
     if not locale:
         ns_cfg = api.config.ns('draco2.draco.locale')
         locale = ns_cfg.get('default')
     locale = cls(data, locale, translator)
     return locale
Beispiel #2
0
 def _create(cls, api):
     """Factory method."""
     request = cls(api.iface)
     robots = singleton(RobotSignatures, api,
                        factory=RobotSignatures._create)
     request._set_robots(robots)
     return request
Beispiel #3
0
def dispatch_request(iface):
    """Dispatch a request to the proper handler."""
    api = singleton(API, factory=API._create)
    api._install()
    try:
        api.iface = iface
        api.options = options
        api.logger = logging.getLogger('draco2.site')

        # Singleton objects.
        api.changes = singleton(ChangeManager, api,
                                factory=ChangeManager._create)
        api.config = singleton(Config, api, factory=Config._create)
        api.loader = singleton(Loader, api, factory=Loader._create)
        api.events = singleton(EventManager, api,
                               factory=EventManager._create)
        api.database = singleton(DatabaseManager, api,
                                 factory=DatabaseManager._create)
        api.models = singleton(ModelManager, api,
                               factory=ModelManager._create)
        api.sendmail = singleton(Sendmail, api, factory=Sendmail._create)

        # Per request objects.
        api.handler = Handler._create(api)
        api.request = api.handler.Request._create(api)
        api.response = api.handler.Response._create(api)
        api.security = SecurityContext._create(api)

        # Optional objects
        if api.handler.Locale:
            api.locale = api.handler.Locale._create(api)
        if api.handler.Session:
            api.session = api.handler.Session._create(api)

        # Run all change contexts. If a change is detected, this will
        # upgrade 'rwlock' and wait for all threads to serialize outside
        # draco_request(). Then, the change callbacks are run.
        api.changes.run_all_contexts(rwlock, api)

        # Handle the request!
        api.handler._dispatch(api)

    finally:
        if hasattr(api, 'models'):
            api.models._finalize()
        if hasattr(api, 'database'):
            api.database._finalize()
        if hasattr(api, 'events'):
            api.events._finalize()
        api._finalize()
Beispiel #4
0
 def _create(cls, api):
     """Factory method."""
     taglib = super(DracoTagLibrary, cls)._create(api)
     config = api.config.ns('draco2')
     taglib._set_extension(config['extension'])
     config = api.config.ns('draco2.api.rewriter')
     if config.has_key('rewritelinks'):
         taglib._set_rewrite_links(config['rewritelinks'])
     if config.has_key('rewriteimages'):
         taglib._set_rewrite_images(config['rewriteimages'])
     images = singleton(ImageInfo, api, factory=ImageInfo._create)
     taglib._set_image_info(images)
     return taglib