ginsfsm / ginsfsm / protocols / sockjs / server / c_session.py

The default branch has multiple heads

# -*- encoding: utf-8 -*-
"""
    SockJS session implementation.

    All transport urls come with /{server_id}/{session_id} subpath.

    The :class:GSockjsSession and :class:GSessionId classes
    captures these segments.

"""
from ginsfsm.gobj import GObj
from ginsfsm.protocols.sockjs.server.transports.xhrstreaming import (
    GXhrStreaming,
)
from ginsfsm.protocols.sockjs.server.transports.xhr import (
    GXhrPolling,
    GXhrSend,
)

#----------------------------------------------------------------#
#                   GSockjsSession GClass
#----------------------------------------------------------------#
GSOCKJSSESSION_GCONFIG = {
    'sockjs_server': [None, None, 0, None, ""],
}


class GSockjsSession(GObj):
    """  GSockjsSession GObj aka GServerID.
    This gobj treats the {server_id} segment of the url.
    The main reason for this segment is to make it easier
    to configure load balancer
    and enable sticky sessions based on first part of the url.
    The sockjs serve must ignore it.

    This gobj would be called GServerID instead of GSockjsSession.
    We don't name this gobj as GServerID for a better understanding of the
    parent gobj view point.
    """
    def __init__(self):
        GObj.__init__(self, {}, GSOCKJSSESSION_GCONFIG)

    def start_up(self):
        """ Initialization zone.
        """
        self.session_id = self.create_gobj(
            'session_id',
            GSessionId,
            self,
            re_name='^[^/.]+$',
            sockjs_server=self.sockjs_server,
        )

#----------------------------------------------------------------#
#                   GSessionId GClass
#----------------------------------------------------------------#
GSESSIONID_GCONFIG = {
    'sockjs_server': [None, None, 0, None, ""],
}


class GSessionId(GObj):
    """  GSessionId GObj.
    """
    def __init__(self):
        GObj.__init__(self, {}, GSESSIONID_GCONFIG)

    def start_up(self):
        """ Initialization zone.
        """
        #-------------------------------------------#
        #           Global handlers
        #               /xhr_send
        #               /jsonp_send
        #-------------------------------------------#

        self.create_gobj(
            'xhr_send',
            GXhrSend,
            self,
            sockjs_server=self.sockjs_server,
        )
        """
        self.sockjs_server.pyramid_config.add_view(
            context=GSessionId,
            name='jsonp_send',
            view=transports.JSONPSendHandler,
            attr='get',
            path_info=self.resource_path(),
            request_method='GET',
            permission=self.sockjs_server.permission,
        )
        """

        #-------------------------------------------#
        #           Transports
        #               /websocket
        #               /xhr
        #               /xhr_streaming
        #               /jsonp
        #               /eventsource
        #               /htmlfile
        #-------------------------------------------#
        """
        self.sockjs_server.pyramid_config.add_view(
            context=GSessionId,
            name='websocket',
            view=transports.WebSocketTransport,
            attr='get',
            path_info=self.resource_path(),
            request_method='GET',
            permission=self.sockjs_server.permission,
        )
        """
        self.create_gobj(
            'xhr',
            GXhrPolling,
            self,
            sockjs_server=self.sockjs_server,
        )

        self.create_gobj(
            'xhr_streaming',
            GXhrStreaming,
            self,
            sockjs_server=self.sockjs_server,
        )

        """
        self.sockjs_server.pyramid_config.add_view(
            context=GSessionId,
            name='jsonp',
            view=transports.JSONPTransport,
            attr='get',
            path_info=self.resource_path(),
            request_method='GET',
            permission=self.sockjs_server.permission,
        )
        self.sockjs_server.pyramid_config.add_view(
            context=GSessionId,
            name='eventsource',
            view=transports.EventSourceTransport,
            attr='get',
            path_info=self.resource_path(),
            request_method='GET',
            permission=self.sockjs_server.permission,
        )
        self.sockjs_server.pyramid_config.add_view(
            context=GSessionId,
            name='htmlfile',
            view=transports.HtmlFileTransport,
            attr='get',
            path_info=self.resource_path(),
            request_method='GET',
            permission=self.sockjs_server.permission,
        )
        """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.