.htaccess - Questions about a simple Python web server -


import string,cgi,time os import curdir, sep basehttpserver import basehttprequesthandler, httpserver  class myhandler(basehttprequesthandler):      def do_get(self):         try:             if self.path.endswith(".html"):                 f = open(curdir + sep + self.path)                  self.send_response(200)                 self.send_header('content-type','text/html')                 self.end_headers()                 self.wfile.write(f.read())                 f.close()                 return             except ioerror:             self.send_error(404,'file not found: %s' % self.path)           def do_post(self):         global rootnode         try:             ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))             if ctype == 'multipart/form-data':                 query=cgi.parse_multipart(self.rfile, pdict)             self.send_response(301)              self.end_headers()             upfilecontent = query.get('upfile')             print "filecontent", upfilecontent[0]             self.wfile.write("<html>post ok.<br><br>");             self.wfile.write(upfilecontent[0]);          except :             pass  def main():     try:         server = httpserver(('', 80), myhandler)         print 'started httpserver...'         server.serve_forever()     except keyboardinterrupt:         print '^c received, shutting down server'         server.socket.close()  if __name__ == '__main__':     main() 

upload.html

<html><body>  <form method='post' enctype='multipart/form-data' action='http://127.0.0.1/'>  file upload: <input type=file name=upfile><br>  <br> <input type=submit value=press> upload file! </form>  </body> </html> 

questions

  1. in upload.html, action post, so, post translate do_post on server python side?

  2. does python server need type of htaccess rule apache server?

  3. what send_response(200) mean?

  4. what's self.wfile.write(f.read())?


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -