def _create(self): def change_color(): self.doc["nav_saver"].style.transition = "opacity 0s" self.doc["nav_saver"].style.opacity = 1 self.doc["nav_saver"].html = "" def display(msg): self.timer.set_timeout(change_color, 15000) self.doc["nav_saver"].style.transition = "opacity 15s" # self.doc["nav_saver"].style.opacity = 1 self.doc["nav_saver"].html = msg self.doc["nav_saver"].style.opacity = 0 def on_complete(request): if request.status == 200 or request.status == 0: display(request.text) else: display("error " + request.text) codename = self.codename.split(".") codename = "/".join(codename[1:-1]) + ".{}".format(codename[-1]) display("Creating.. " + codename) code = ecd(bytearray(self.gui.code.encode("UTF8"))).decode("utf-8") # code = ecd(bytearray(HTMLParser().unescape(self.gui.code).encode("UTF8"))).decode("utf-8") jsrc = json.dumps({'codename': codename, 'code': code}) # print(SAVE, jsrc) req = self.ajax.ajax() req.bind('complete', on_complete) req.set_timeout('20000', lambda *_: display("NOT SAVED: TIMEOUT")) req.open('POST', "/game/__create", True) req.set_header('content-type', 'application/json') # x-www-form-urlencoded') req.send(jsrc)
def __save(self, codename, contents, creator=lambda *_: None, request_path="__save", action_name="Saving", address=None): def change_color(): self.doc['nav_waiter'].style.visibility = "hidden" self.doc["nav_saver"].style.transition = "opacity 45s" self.doc["nav_saver"].style.opacity = 1 self.doc["nav_saver"].html = "" def display(msg, waiter="visible"): self.doc['nav_waiter'].style.visibility = waiter # self.doc["nav_saver"].style.opacity = 1 self.doc["nav_saver"].style.transition = "opacity 45s" self.doc["nav_saver"].style.opacity = 0 self.doc["nav_saver"].html = msg self.timer.set_timeout(change_color, 25000) def on_complete(request): if request.status == 200 or request.status == 0: if "404" in request.text: self.timer.set_timeout(lambda *_: creator(contents), 1000) display("Attempting to create..") if action_name else None else: display(request.text, waiter="hidden") if action_name else None else: display("error " + request.text) display("{}.. {}".format(action_name, codename)) if action_name else None code = ecd(bytearray(contents.encode("UTF8"))).decode("utf-8") # code = ecd(bytearray(HTMLParser().unescape(self.gui.code).encode("UTF8"))).decode("utf-8") jsrc = json.dumps({'codename': codename, 'code': code}) # print(SAVE, jsrc) req = self.ajax.ajax() req.bind('complete', on_complete) req.set_timeout('20000', lambda *_: display("NOT SAVED: TIMEOUT")) address = address if address else "/game/{}".format(request_path) req.open('POST', address, True) req.set_header('content-type', 'application/json') # x-www-form-urlencoded') req.send(jsrc)
def __save(self): def on_complete(request): if request.status == 200 or request.status == 0: self.doc["nav_saver"].html = request.text else: self.doc["nav_saver"].html = "error " + request.text codename = self.codename.split(".") codename = "/".join(codename[1:-1]) + ".{}".format(codename[-1]) self.doc["nav_saver"].html = "Saving.. " + codename req = self.ajax.ajax() req.bind('complete', on_complete) # send a POST request to the url req.open('POST', "/game/__save", True) req.set_header('content-type', 'application/x-www-form-urlencoded') # send data as a dictionary code = ecd(bytearray(self.gui.code.encode("UTF8"))).decode("utf-8") req.send({'codename': codename, 'code': code})
def gamer(mod, name): modl, namel = mod.lower(), name.lower() try: code_file = DS.get_file_contents(modl, namel) code = code_file.content # code = dcd(str.encode(code_file.content)).decode("utf-8") except Exception as err: code = "# " + ".".join([modl, namel, "main.py"]) code = ecd(bytearray(code.encode("UTF8"))).decode("utf-8") print("Play gamer Exception", code, err) return dict( pagetitle='PLAY - SuPyGirls - {} - {}'.format(mod.capitalize(), name.capitalize()), title=name, modText=mod.capitalize(), nameText=name.capitalize(), image="supygirls_logo.png", mod=mod.replace(',', '_').lower(), code=code, brython_css=CSS, brython_js=JS, menu=[m.split(",") for m in MENU.split(":")])