Exemple #1
0
    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()
Exemple #2
0
    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
Exemple #3
0
    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
Exemple #4
0
 def test_guid_length_is_64_characters(self):
     self.assertEquals(len(guid.guid()), 64)
Exemple #5
0
 def unique(self, max=50):
     unique = set()
     for x in xrange(max):
         unique.add(guid.guid())
     return len(unique)