コード例 #1
0
    def _generate_session_id(self):
        """Generate a random id for session"""

        while True:
            rand = os.urandom(16)
            now = time.time()
            secret_key = self._config.secret_key
            session_id = sha1("%s%s%s%s" % (rand, now, utils.safestr(web.ctx.ip), secret_key))
            session_id = session_id.hexdigest()
            if session_id not in self.store:
                break
        return session_id
コード例 #2
0
    def _generate_session_id(self):
        """Generate a random id for session"""

        while True:
            rand = os.urandom(16)
            now = time.time()
            secret_key = self._config.secret_key
            session_id = hashlib.sha1(("%s%s%s%s" % (rand, now, utils.safestr(web.ctx.ip), secret_key)).encode("utf-8"))
            session_id = session_id.hexdigest()
            if session_id not in self.store:
                break
        return session_id
コード例 #3
0
ファイル: db.py プロジェクト: chendean/test01
 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)
コード例 #4
0
ファイル: db.py プロジェクト: chendean/test01
 def __str__(self):
     return safestr(self._str())