Created
September 27, 2019 19:04
-
-
Save 64lines/3c8bf8dcea16b30375975291dd685b70 to your computer and use it in GitHub Desktop.
[PYTHON] - Server class to serve simple html objects.
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 http.server | |
import socketserver | |
import sys | |
class Server: | |
""" | |
Server class to serve simple html objects. | |
""" | |
DEFAULT_PORT = 8000 | |
def run_server(self): | |
""" | |
This method run the server. | |
""" | |
port = self.__validate_port() | |
Handler = http.server.SimpleHTTPRequestHandler | |
with socketserver.TCPServer(("", port), Handler) as httpd: | |
print("Serving at port", port) | |
httpd.serve_forever() | |
def __validate_port(self): | |
return int(sys.argv[1]) if len(sys.argv) > 1 else self.DEFAULT_PORT | |
Server().run_server() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment