コード例 #1
0
ファイル: MainServer.py プロジェクト: utarsuno/GenericProject
 def end_post(self):
     """
     This function will print debug messages.
     :return:
     Void.
     """
     Logger.log(" ---- POST ENDED ---- ")
コード例 #2
0
ファイル: MainServer.py プロジェクト: utarsuno/GenericProject
 def start_post(self):
     """
     This function will print debug messages.
     :return:
     Void.
     """
     Logger.log(" ---- POST STARTED ---- ")
     Logger.log("path:\t" + self.path)
コード例 #3
0
ファイル: MainServer.py プロジェクト: utarsuno/GenericProject
 def send_html_and_okay_header(self):
     """
     This function will send the response and the headers.
     :return:
     Void.
     """
     if self.path == '/register.html' or self.path == '/index.html' or self.path == '/not_valid.html':
         content = bytes(HTMLUtils.get_file_text('/html' + self.path), "UTF-8")
         self.send_response(200)
         self.send_header("Content-type", "text/html")
         self.send_header("Content-Length", len(content))
         self.end_headers()
         #print(self.rfile.read().decode("UTF-8"))
         self.wfile.write(content)
         Logger.log('Sending a valid url.')
     else:
         Logger.log('Sending not valid url.')
         self.send_not_valid_html_and_okay_header()
コード例 #4
0
ファイル: MainServer.py プロジェクト: utarsuno/GenericProject
    def do_GET(self):

        self.start_get()

        if self.path == '/favicon' or self.path == '/favicon.ico':

            self.send_header("Content-type", "image/x-icon")
            self.send_header("Content-length", FAVICON_SIZE)
            self.send_image_from_post(FAVICON_PATH)

        elif self.path == '/favicon-16x16.png':
            self.send_header("Content-type", "image/png")
            self.send_header("Content-length", FAVICON_16_x_16_SIZE)
            self.send_image_from_post(FAVICON_16_x_16_PATH)

        elif self.path == '/favicon-32x32.png':
            self.send_header("Content-type", "image/png")
            self.send_header("Content-length", FAVICON_32_x_32_SIZE)
            self.send_image_from_post(FAVICON_32_x_32_PATH)

        elif self.path == '/resources/background/background.png':
            self.send_header("Content-type", "image/png")
            self.send_header("Content-length", BACKGROUND_SIZE)
            self.send_image_from_post(BACKGROUND_PATH)

        elif self.path.endswith(".html"):
            self.send_html_and_okay_header()

        elif self.path.endswith(".js"):
            self.send_js_and_okay_header()

        elif self.path.endswith(".css"):
            self.send_css_and_okay_header()

        elif self.path.endswith(".ttf"):
            self.send_ttf_and_okay_header()

        else:
            Logger.log("Path was not valid or an error occurred.")

            self.send_not_valid_html_and_okay_header()

        self.end_get()
コード例 #5
0
ファイル: MainServer.py プロジェクト: utarsuno/GenericProject
            #database.MainDatabase.add_transaction()v

        else:
            self.send_response_and_okay_header("Path is not valid")

        self.end_post()

#host_name = "50.129.15.209"
#host_name = "192.168.56.1"
#host_name = '10.0.0.10'
#host_name = '0.0.0.0'
host_name = ""
host_port = 8080

"""
Main program starts here.
"""
Logger.enable_logging()
Logger.enable_time_stamp()

main_server = HTTPServer((host_name, host_port), MainServer)
print(time.asctime(), "Server started - %s:%s" % (host_name, host_port))

try:
    main_server.serve_forever()
except KeyboardInterrupt:
    pass

main_server.server_close()
print(time.asctime(), "Server stopped - %s:%s" % (host_name, host_port))