Created
December 21, 2010 11:30
-
-
Save sakti/749822 to your computer and use it in GitHub Desktop.
simple webserver
This file contains 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
###################################################### | |
# namafile : webserver.py | |
# implementasi HTTP web server di python dengan fitur tambahan untuk | |
# menjalankan server-side CGI script; menyediakan file-file/script dari | |
# 'current working dir'; Python script harus diletakkan di webdir/cgi-bin | |
###################################################### | |
webdir = '.' # Tempat html file berada dan cgi-bin directory | |
port = 8080 # default http://localhost/, atau menggunakan http://localhost:xxxx/ | |
import os, sys | |
from BaseHTTPServer import HTTPServer | |
from CGIHTTPServer import CGIHTTPRequestHandler | |
# jika platform windows: os.environ tidak dipropagasikan | |
# ke subproses dengan os.popen2, dipaksa dijalankan in-process | |
if sys.platform[:3] == 'win': | |
CGIHTTPRequestHandler.have_popen2 = False | |
CGIHTTPRequestHandler.have_popen3 = False | |
os.chdir(webdir) # berjalan di HTML root directory | |
srvraddr = ("", port) # nama host, nomor port | |
srvrobj = HTTPServer(srvraddr, CGIHTTPRequestHandler) | |
srvrobj.serve_forever( ) # jalankan deamon selamanya |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment