示例#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
    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
 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())