From a5f97b799bc9e33b35404d36d8092b2a6c634389 Mon Sep 17 00:00:00 2001 From: kerem3338 <73388608+kerem3338@users.noreply.github.com> Date: Sat, 1 Jan 2022 12:56:11 +0300 Subject: [PATCH] Add files via upload 2.0.1 --- sabe.py | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/sabe.py b/sabe.py index 6f83ae5..52b4a70 100644 --- a/sabe.py +++ b/sabe.py @@ -3,18 +3,19 @@ from colorama import init from termcolor import colored import webbrowser +import flask +from waitress import serve init() - class Sabe: """Sabe web uygulamarını daha kolay ve hızlı şekilde yapabilmek için yazılmıştır""" + def __init__(self): self.app = Flask(__name__) self.route_list = [] self.url_list = [] - self.version = "2.0" - + self.version = "2.0.1" def info(self): print("Sabe © Kerem ata\n\nSabe kolay web sitesi oluşturmak için yazılmış bir frameworkdür\nTemelinde flask bulunmaktadır") @@ -23,8 +24,7 @@ def version(self): """return version""" return self.version - - def render_website(self, url): + def render_website(self, route, url): """get file content render content (cannot get css or js file(s))""" try: import requests @@ -32,7 +32,11 @@ def render_website(self, url): print(colored("requests modülü bulunamadı", "red")) try: url = requests.get(url) - return url.text + + @self.app.route(route) + def page(): + return url.text + self.url_list.append(url) except requests.exceptions.MissingSchema: #print(colored(f"Geçersiz Url: Bunu mu demek istedinizi? (https://{url})", "red")) @@ -42,6 +46,7 @@ def render_website(self, url): def url_routes(self): """return all websites urls""" return(self.url_routes) + def routes(self): """return all routes""" return(self.route_list) @@ -50,7 +55,6 @@ def route(self, route, code): """add route for application""" self.route_list.append(route) - @self.app.route(route) def page(): return code @@ -61,6 +65,10 @@ def error_page_add(self, error_code, code): @self.app.errorhandler(404) def not_found(e): return code + elif error_code == "500": + @self.app.errorhandler(500) + def server_error(e): + return code else: print(colored(f"Hata kodu {error_code} bulunamadı", "red")) @@ -69,20 +77,11 @@ def render_file(self, filename, encoding="utf8"): with open(filename, encoding=encoding) as filecontant: return filecontant.read() - - def run(self, run="classic"): + def run(self): """Run application""" - if run == "classic": - if __name__ == "__main__": - self.app.run() - elif run == "auto": - if __name__ == "__main__": - self.app.run() - webbrowser.open("http://127.0.0.1:5000/") - else: - print("Tanımlanmayan mod") - - - + self.app.run() + def __str__(self): + return "" +