def loadfile( site: site.Site, src: ContentSrc, bin: bool, filecache: shelve.DbfilenameShelf ) -> List[Tuple[ContentSrc, Optional[bytes]]]: curstat = src.stat() key = f"{src.package}_::::_{src.srcpath}" stat, bodies = filecache.get(key, (None, None)) if stat: if stat == curstat: return cast(List[Tuple[ContentSrc, Optional[bytes]]], bodies) if not bin: assert src.srcpath ext = os.path.splitext(src.srcpath)[1] loader = FILELOADERS.get(ext, binloader) else: loader = binloader ret: List[Tuple[ContentSrc, Optional[bytes]]] = [] for contentsrc, body in loader(site, src): assert contentsrc.metadata["loader"] if isinstance(body, bytes): ret.append((contentsrc, body)) if isinstance(body, str): ret.append((contentsrc, body.encode("utf-8"))) else: ret.append((contentsrc, None)) filecache[key] = curstat, ret return ret
def get_friends(cache: DbfilenameShelf = None, name: str = SHLOMO): if cache is not None: friends = cache.get(name) if friends is not None: return cache[name] response = get_first_request(name) first_page_singers = response[0] parallel_searcher = response[1] pages_range = response[2] if not pages_range: # only 1 page friends = first_page_singers else: with TPool(INNER_MAX_WORKERS) as pool: next_pages_singers = pool.map(parallel_searcher, pages_range) friends = first_page_singers.union(*next_pages_singers) if cache is not None: cache[name] = friends cache.sync() return friends
<p>You are not logged in.</p> <p> <a href="login.py">Login</a> | <a href="accounts/register.py">Register</a> </p> </section>""" try: cookie = SimpleCookie() http_cookie_header = environ.get('HTTP_COOKIE') if http_cookie_header: cookie.load(http_cookie_header) if 'sid' in cookie: sid = cookie['sid'].value session_store = DbfilenameShelf('sessions/sess_' + sid, writeback=False) if session_store.get('authenticated'): message = '' form_data = FieldStorage() username = session_store.get('username') form = """<p> Hey, %s. Sorry to see you go. </p> <p> <strong>Warning! This action is permenant.</strong> All of your scores will be lost. </p> <form action="delete_account.py" method="post"> <label for="pass1">Enter password: </label> <input type="password" name="pass1" id="pass1" placeholder="Enter password" required /> <label for="pass2">Reenter password: </label> <input type="password" name="pass2" id="pass2" placeholder="Reenter password" required /> <label for="confirm">Confirm Deletion: </label>
def get_eye_position(shelf: shelve.DbfilenameShelf): return shelf.get(EYE_POSITION, 0)
try: cookie = SimpleCookie() http_cookie_header = environ.get('HTTP_COOKIE') if not http_cookie_header: sid = sha256(repr(time()).encode()).hexdigest() cookie['reset'] = sid else: cookie.load(http_cookie_header) if 'reset' not in cookie: sid = sha256(repr(time()).encode()).hexdigest() cookie['reset'] = sid else: sid = cookie['reset'].value session_store = DbfilenameShelf('../sessions/reset_' + sid, writeback=True) if session_store.get('code'): code = escape(form_data.getfirst('code', '').strip()) if code: form = """<form action="forgot.py" method="post"> <label for="code">Code: </label> <input type="number" name="code" id="code" min="0" max="99999" value="%s" required /> <label for="pass1">Enter new password: </label> <input type="password" name="pass1" id="pass1" required /> <label for="pass2">Reenter password: </label> <input type="password" name="pass2" id="pass2" required /> <input type="submit" /> </form>""" % code if session_store.get('code') == code: pass1 = escape(form_data.getfirst('pass1', '').strip()) pass2 = escape(form_data.getfirst('pass2', '').strip()) if len(pass1) < 8 or len(pass2) < 8:
</p> <p> <a href="guest.html">Play as a Guest!</a> </p> </section>""" footer = '' try: cookie = SimpleCookie() http_cookie_header = environ.get('HTTP_COOKIE') if http_cookie_header: cookie.load(http_cookie_header) if 'sid' in cookie: sid = cookie['sid'].value session_store = DbfilenameShelf('sessions/sess_' + sid, writeback=False) if session_store.get('authenticated'): script = '<script src="game.js" type="module"></script>' result = """<canvas width="750" height="750"></canvas> <p>Level: <span id="level">1</span></p> <label for="health">Health:</label> <progress value="0" max="100" id="health"></progress> <p> Score: <span id="score">0</span> | <span id="username">%s</span> </p> <figure> <figcaption> Use the arrow keys to move around. </figcaption> <img src="media/keys.png" alt="Arrow keys from a computer keyboard" /> </figure> <audio src="media/back1.mp3" loop>