Beispiel #1
0
    def from_js(self, json):
        """Documentation"""
        if isinstance(json, dict):
            json_dict = json
        else:
            from tic.utils.simplejson import loads
            json_dict = loads(json)

        for key, prop in self.properties().items():
            value = json_dict[key]
            prop.from_js(value)
Beispiel #2
0
    def process_request(self, req):
        """

        """
        json_command = simplejson.loads(req.read())
        class_name = json_command['_cc_']
        command = self._new_instance(self._get_class(class_name))
        command.from_js(json_command)
        result = None
        for command_handler in self.command_handlers:
            if(isinstance(command, command_handler.command)):
                command_handler.request = req

                result = command_handler.execute(command)
                result = result if isinstance(result, basestring) else result.to_json()
                logging.debug("Result:")
                logging.debug(result)
#                return result
        req.send(result, "application/json")
Beispiel #3
0
 def from_js(self, value):
     return self.validate(loads(value))
Beispiel #4
0
    def __init__(self, cookie_path = SESSION_SETTINGS["DEFAULT_COOKIE_PATH"],
            cookie_domain = SESSION_SETTINGS["DEFAULT_COOKIE_DOMAIN"],
            cookie_name = SESSION_SETTINGS["COOKIE_NAME"],
            session_expire_time = SESSION_SETTINGS["SESSION_EXPIRE_TIME"],
            clean_check_percent = SESSION_SETTINGS["CLEAN_CHECK_PERCENT"],
            integrate_flash = SESSION_SETTINGS["INTEGRATE_FLASH"],
            check_ip = SESSION_SETTINGS["CHECK_IP"],
            check_user_agent = SESSION_SETTINGS["CHECK_USER_AGENT"],
            set_cookie_expires = SESSION_SETTINGS["SET_COOKIE_EXPIRES"],
            session_token_ttl = SESSION_SETTINGS["SESSION_TOKEN_TTL"],
            last_activity_update = SESSION_SETTINGS["UPDATE_LAST_ACTIVITY"],
            writer = SESSION_SETTINGS["WRITER"]):
        """
        Initializer

        Args:
          cookie_path: The path setting for the cookie.
          cookie_domain: The domain setting for the cookie. (Set to False
                        to not use)
          cookie_name: The name for the session cookie stored in the browser.
          session_expire_time: The amount of time between requests before the
              session expires.
          clean_check_percent: The percentage of requests the will fire off a
              cleaning routine that deletes stale session data.
          integrate_flash: If appengine-utilities flash utility should be
              integrated into the session object.
          check_ip: If browser IP should be used for session validation
          check_user_agent: If the browser user agent should be used for
              sessoin validation.
          set_cookie_expires: True adds an expires field to the cookie so
              it saves even if the browser is closed.
          session_token_ttl: Number of sessions a session token is valid
              for before it should be regenerated.
        """

        self.cookie_path = cookie_path
        self.cookie_domain = cookie_domain
        self.cookie_name = cookie_name
        self.session_expire_time = session_expire_time
        self.integrate_flash = integrate_flash
        self.check_user_agent = check_user_agent
        self.check_ip = check_ip
        self.set_cookie_expires = set_cookie_expires
        self.session_token_ttl = session_token_ttl
        self.last_activity_update = last_activity_update
        self.writer = writer

        # make sure the page is not cached in the browser
        print self.no_cache_headers()
        # Check the cookie and, if necessary, create a new one.
        self.cache = {}
        string_cookie = os.environ.get(u"HTTP_COOKIE", u"")
        self.cookie = Cookie.SimpleCookie()
        self.output_cookie = Cookie.SimpleCookie()
        if string_cookie == "":
            self.cookie_vals = {}
        else:
            self.cookie.load(string_cookie)
            try:
                self.cookie_vals = \
                    simplejson.loads(self.cookie["%s_data" % (self.cookie_name)].value)
                    # sync self.cache and self.cookie_vals which will make those
                    # values available for all gets immediately.
                for k in self.cookie_vals:
                    self.cache[k] = self.cookie_vals[k]
                    # sync the input cookie with the output cookie
                    self.output_cookie["%s_data" % (self.cookie_name)] = \
                        simplejson.dumps(self.cookie_vals) #self.cookie["%s_data" % (self.cookie_name)]
            except Exception, e:
                self.cookie_vals = {}