class RootRequest(website.Request): @debug.log @debug.catch async def handle(self) -> website.Request: website.log.request.info(f"/{'/'.join(self.request)}", self.client) try: return await self.tree.traverse(self) except (website.error.TreeTraversal, website.error.BufferRead) as err: website.log.request.info(f"/{'/'.join(self.request)} -> FAIL", self.client, exc_info=err) return await Err404Request(self) tree = website.Tree( pqst.home, pqst.home, js=JSRequest, img=ImgRequest, audio=AudioRequest, video=VideoRequest, style=CSSRequest, key=pqst.program["admin"], hi=pqst.program["hi"], ig=pqst.program["instagram"], vol=pqst.program["volume"], hue=pqst.program["light"], candela=pqst.program["candela"], coldwater=pqst.program["coldwater"], cupboard=pqst.program["cupboard"], dressme=pqst.program["clothing"], **{ "favicon.ico": website.buffer.File(f"{website.path}resource/image/favicon.ico"), }, )
class RedirectStatus(ARequest): root = website.Request state = False _tree = None _redirect = website.Tree( *[ website.Request.redirect( hostname="192.168.1.111", port=53331, scheme="https") ] * 3, ) @classmethod async def change(cls, state: bool): if state: try: await Interface.process(urllib.request.urlopen, "http://192.168.1.111:53335/") except urllib.error.URLError: state = False if state: cls._tree, cls.root.tree = cls.root.tree, cls._redirect elif cls._tree: cls.root.tree = cls._tree cls.state = state async def extra(self): return f"<p>Redirection Status: {self.state}<p>"
class Login(website.Request): async def handle(self): chat = self.request[self.segment-1] # or self.client.query["chatname"].title().replace("+", "").replace("%20", "") if chat not in self.client.session.chats: # Login if "chatpassword" not in self.client.query or chat not in dbc.chat or self.client.query["chatpassword"] != dbc.chat[chat].password: return Home(self) self.client.session.chats.add(chat) chat = dbc.chat[chat] if "msg" in self.client.query: # Message Request elms = self.client.query["elm"].split(";") dbi = chat.db(self.client.session.id) data = await Interface.gather(*(rchat.Message(self, chat, dbi, int(eid)) for eid in elms)) self.client.header << website.Header("Content-Type", "text/html") self.client.buffer << "\n".join(filter(None, data)) if elms: self.client.session.eid = int(elms[-1]) return if "ig" in self.client.query: # IG Request coro = [] for mtype, eid in [(i[0], i[1:]) for i in self.client.query["elm"].split(";")]: if mtype == "m": coro.append(rchat.IGReq(self, chat, int(eid))) elif mtype == "p": coro.append(rchat.ProfilePic(self, chat, int(eid))) return await Interface.gather(*coro) try: self.client.query["elm"] = int(self.request[self.segment]) except (IndexError, ValueError): if "elm" not in self.client.query: self.client.query["elm"] = self.client.session.eid # try: return await self.tree.traverse(self, chat) # except website.error.TreeTraversal: tree = website.Tree( rchat.Chat, rchat.Chat, default__=rchat.Chat, search = rchat.SearchPage, s = rchat.Search, save = rchat.Save, media = rchat.Media, )
class RootRequest(website.Request): sessions = website.Sessions(Session) @website.Request.secure async def handle(self): self.client.session = self.sessions[self.client.cookie.value("sid")] self.client.cookie["sid"] = self.client.session.id self.client.cookie["sid"]["path"] = "/ig" self.client.cookie["sid"]["Max-Age"] = 86400 self.client.cookie["sid"]["Secure"] = self.client.cookie["sid"]["HttpOnly"] = True return await self.tree.traverse(self) tree = website.Tree( Home, end__=Home, default__=Login, )
self.client.buffer << website.buffer.Python( website.path + "page/volume/home.html", self) # class Youtube(website.Request): # async def handle(self): # self.client.buffer << website.buffer.Python(website.path+"page/volume/youtube.html", self) # class Spotify(website.Request): # async def handle(self): # self.client.buffer << website.buffer.Python(website.path+"page/volume/spotify.html", self) # class Groove(website.Request): # async def handle(self): # self.client.buffer << website.buffer.Python(website.path+"page/volume/groove.html", self) # class RootRequest(website.Request): # async def handle(self): # return await self.tree(self) request = website.Tree( Home, end__=Home, default__=Home, cmd=Command, # upload=player.Uploader, # player=player.Home, # youtube=Home.Youtube, # spotify=Home.Spotify, # groove=Home.Groove )
f"{website.path}page/404Error.html", self) @website.buffer.wrap def data(self): return f"/{'/'.join(self.request)}" async def get_pages(self) -> str: links = [] for n, l in self.pages.items(): links.append(f"""<a class="link page" href="/key/{l}">{n}</a>""") return "".join(links) pages = { "Kill Server": "exit", "Purge Caches": "cache", } request = website.Tree(Index, Index, exit=Shutdown, cache=ClearCache, redirect=website.Tree( RedirectStatus, RedirectStatus, RedirectStatus, enable=EnableServerRedirect, disable=DisableServerRedirect, )) RedirectStatus._redirect.insert("key", request)