Last active
July 24, 2021 12:15
-
-
Save ygkn/d78f2d6e2a9be798ae0e65b2876b41fd to your computer and use it in GitHub Desktop.
小林さんちのメイドラゴンで出てきたコード(小林さんを探せ!) ref: https://qiita.com/ygkn/items/6b3be1afa31e4092826e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Session Management | |
(from web.py) | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?????e = ShelfStore(shelve.open('sess #見切れ | |
XXX: ?helveはスレッドセーフ?要確認。 | |
""" | |
def __init__(self, shelf): | |
self.shelf = shelf | |
def __contains__(self, key): | |
return key in self.shelf | |
def __getitem__(self, key): | |
atime, v = self.shelf[key] | |
self[key] = v # update atime | |
return v# 入力中 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __delitem__(self, key): | |
self.db.delete(self.table, where="session_id=$key", vars=# 見切れ | |
def cleanup(self, timeout): | |
timeout = datetime.# 入力中 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, time, datetime, random, base64 | |
import os.path | |
from copy import deepcopy | |
try: | |
import cPickle as pickle | |
except ImportError: | |
import pickle | |
from hashlib import sha1 | |
from .# 入力中 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _validate_ip(self): | |
# IPアドレスの変更を確認する | |
if self.session_id and self.get('ip', None) != web.ctx.ip: | |
if not self._config.ignore_change_ip: | |
return self.expired() | |
def _save(self): | |
if not self.get('_killed'): | |
self._setcookie(self.session_id) | |
self.store[self.session_id] = dict(self._data) | |
else: | |
self._setcookie(self.session_id, expires=-1) | |
def _setcookie(self, session_id, expires='', **kw): | |
cookie_name = self._config.cookie_name | |
cookie_domain = self._config.cookie_domain | |
cookie_path = self._config.cookie_path | |
httponly = self._config.httponly | |
secure = self._config.secure | |
web.setcookie(cookie_name, session_id, expires=expires, domain=cookie_domain, httponly=httponly, secure=sec#見切れ | |
def _generate_session_id(self): | |
"""ランダムのセッションIDを生成する""" | |
while True: | |
rand = os.urandom(16) | |
now = time.time() | |
secret_key = self._config.secret_key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment