예제 #1
0
 def _create_sessionid(self):
     rand = os.urandom(16)
     now = time.time()
     secret_key = self.config.secret_key
     session_id = sha1("%s%s%s%s" % (rand, now, safestr(self.remote_ip), secret_key))
     session_id = session_id.hexdigest()
     return str(session_id).upper() + '|' + self.config.session_version
예제 #2
0
 def _create_sessionid(self):
     rand = os.urandom(16)
     now = time.time()
     secret_key = self.config.secret_key
     session_id = sha1("%s%s%s%s" %
                       (rand, now, safestr(self.remote_ip), secret_key))
     session_id = session_id.hexdigest()
     return str(session_id).upper() + '|' + self.config.session_version
예제 #3
0
    def _key_to_file(self, key):
        """
        Convert the filename into an md5 string. We'll turn the first couple
        bits of the path into directory prefixes to be nice to filesystems
        that have problems with large numbers of files in a directory.

        Thus, a cache key of "foo" gets turnned into a file named
        ``{cache-dir}ac/bd/18db4cc2f85cedef654fccc4a4d8``.
        """
        path = hashlib.md5(safestr(key)).hexdigest()
        path = os.path.join(path[:2], path[2:4], path[4:])
        return os.path.join(self._dir, path)
예제 #4
0
파일: filebased.py 프로젝트: qloog/torngas
    def _key_to_file(self, key):
        """
        Convert the filename into an md5 string. We'll turn the first couple
        bits of the path into directory prefixes to be nice to filesystems
        that have problems with large numbers of files in a directory.

        Thus, a cache key of "foo" gets turnned into a file named
        ``{cache-dir}ac/bd/18db4cc2f85cedef654fccc4a4d8``.
        """
        path = hashlib.md5(safestr(key)).hexdigest()
        path = os.path.join(path[:2], path[2:4], path[4:])
        return os.path.join(self._dir, path)
예제 #5
0
파일: basedb.py 프로젝트: qiwsir/torngas
 def query(self, paramstyle=None):
     """
     Returns the query part of the sql query.
         >>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')])
         >>> q.query()
         'SELECT * FROM test WHERE name=%s'
         >>> q.query(paramstyle='qmark')
         'SELECT * FROM test WHERE name=?'
     """
     s = []
     for x in self.items:
         if isinstance(x, SQLParam):
             x = x.get_marker(paramstyle)
             s.append(safestr(x))
         else:
             x = safestr(x)
             # automatically escape % characters in the query
             # For backward compatability, ignore escaping when the query looks already escaped
             if paramstyle in ['format', 'pyformat']:
                 if '%' in x and '%%' not in x:
                     x = x.replace('%', '%%')
             s.append(x)
     return "".join(s)
예제 #6
0
파일: basedb.py 프로젝트: qloog/torngas
 def query(self, paramstyle=None):
     """
     Returns the query part of the sql query.
         >>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')])
         >>> q.query()
         'SELECT * FROM test WHERE name=%s'
         >>> q.query(paramstyle='qmark')
         'SELECT * FROM test WHERE name=?'
     """
     s = []
     for x in self.items:
         if isinstance(x, SQLParam):
             x = x.get_marker(paramstyle)
             s.append(safestr(x))
         else:
             x = safestr(x)
             # automatically escape % characters in the query
             # For backward compatability, ignore escaping when the query looks already escaped
             if paramstyle in ['format', 'pyformat']:
                 if '%' in x and '%%' not in x:
                     x = x.replace('%', '%%')
             s.append(x)
     return "".join(s)
예제 #7
0
 def make_key(self, key, version=None):
     # Python 2 memcache requires the key to be a byte string.
     return safestr(super(BaseMemcachedCache, self).make_key(key, version))
예제 #8
0
 def unpickle(self, value):
     """
     Unpickles the given value.
     """
     value = safestr(value)
     return pickle.loads(value)
예제 #9
0
파일: basedb.py 프로젝트: qiwsir/torngas
 def __str__(self):
     return safestr(self._str())
예제 #10
0
 def make_key(self, key, version=None):
     # Python 2 memcache requires the key to be a byte string.
     return safestr(super(BaseMemcachedCache, self).make_key(key, version))
예제 #11
0
파일: rediscache.py 프로젝트: qloog/torngas
 def unpickle(self, value):
     """
     Unpickles the given value.
     """
     value = safestr(value)
     return pickle.loads(value)
예제 #12
0
파일: basedb.py 프로젝트: qloog/torngas
 def __str__(self):
     return safestr(self._str())