コード例 #1
0
ファイル: session.py プロジェクト: midnightskinhead/chula
    def __init__(self, config, existing_guid=None):
        """
        Create a user session object

        @param config: Application configuration
        @type config: Instance of chula.config object
        @param existing_guid: Used to attach to an existing user's session
        @type existing_guid: chula.guid.guid()
        """
        
        self._persist_immediately = False
        self._config = config
        self._cache = self._config.session_memcache
        self._timeout = self._config.session_timeout
        self._expired = False

        if existing_guid is None:
            self._guid = guid.guid()
        else:
            self._guid = existing_guid

        # Initialize memache client
        if not isinstance(self._cache, memcache.Client):
            self._cache = memcache.Client(self._cache, debug=0)
        
        # Retrieve session
        self.load()
コード例 #2
0
ファイル: controller.py プロジェクト: jbloetz/chula
    def __init__(self, env, config):
        """
        Initialize the web request, performing taks common to all web
        requests.

        @param env: Normalized environment (wsgi at a minimum)
        @type env: env WSGI environ object with a few extra objects
        """
        
        self.content_type = 'text/html'

        # Add some convenience attributes
        self.config = config
        self.env = env
        self.form = env.form

        # Start up session using the cookie's guid (or a fake one)
        if self.config.session_name in self.env.cookies:
            guid_ = self.env.cookies[self.config.session_name].value
            self.session = session.Session(self.config, guid_)
        else:
            # Create a new guid create a cookie
            guid_ = guid.guid()
            self.session = session.Session(self.config, guid_)
            self.env.cookies[self.config.session_name] = guid_

        # Create a default model. This object is optionally populated by the
        # controller, or it can do it's own thing.
        self.model = collection.Collection()
        self.model.session = self.session
        self.model.env = self.env
コード例 #3
0
ファイル: base.py プロジェクト: jmcfarlane/chula
    def __init__(self, env, config):
        """
        Initialize the web request, performing tasks common to all web
        requests.

        :param env: Normalized environment (wsgi at a minimum)
        :type env: Subclass of :class:`chula.www.adapters.env.BaseEnv`
        :param config: Configuration
        :type config: :class:`chula.config.Config`

        Default :attr:`chula.www.adapters.env.BaseEnv.content_type` is
        set to ``text/html`` if not specified.
        """

        self.content_type = 'text/html'

        # Add some convenience attributes
        self.config = config
        self.env = env
        self.form = env.form
        self.log = logger.Logger(config).logger('chula.www.controller.base')

        # Create a default model. This object is optionally populated by the
        # controller, or it can do it's own thing.
        self.model = collection.Collection()
        self.model.env = self.env

        # Start up session using the cookie's guid (or a fake one)
        if self.config.session:
            if self.config.session_name in self.env.cookies:
                guid_ = self.env.cookies[self.config.session_name].value
            else:
                # Create a new guid create a cookie
                guid_ = guid.guid()
                self.env.cookies[self.config.session_name] = guid_

            # Instantiate session and expose to the model
            self.session = session.Session(self.config, guid_)
            self.model.session = self.session
コード例 #4
0
ファイル: test_guid.py プロジェクト: jbloetz/chula
 def test_guid_length_is_64_characters(self):
     self.assertEquals(len(guid.guid()), 64)
コード例 #5
0
ファイル: test_guid.py プロジェクト: jbloetz/chula
 def unique(self, max=50):
     unique = set()
     for x in xrange(max):
         unique.add(guid.guid())
     return len(unique)