inicio mail me! sindicaci;ón

FTP Uploader (.NET vs Python)

Michele Bersani showed a very simple example of FTP uploader using a third party library (in .NET 1.1 you don’t have any FTP support at all) and hence I wrote a Python version.

Here is his script: Read the rest of this entry »

HttpListener (.NET) vs BaseHTTPServer (Python)

06 Dec 05 - UPDATE: with this post I start a series of posts comparing scripts in .NET (C# or so) and Python (CPython)

Michele Bersani of the local .NET user group wrote a basic use case of .NET 2.0 HttpListener class but he states in his post that (I translate from italian) it works “only under Windows XP SP2 or Windows Server 2003“. What a pity!

Hence I wrote a Python similar version that runs on quite all platforms (Windows, Linux and so on).

  1. from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
  2. import webbrowser
  3.  
  4. class RequestHandler(BaseHTTPRequestHandler):
  5.     def _writeheaders(self):
  6.         self.send_response(200)
  7.         self.send_header(‘Content-type’, ‘text/html’)
  8.         self.end_headers()
  9.  
  10.     def do_HEAD(self):
  11.         self._writeheaders()
  12.  
  13.     def do_GET(self):
  14.         self._writeheaders()
  15.         self.wfile.write(
  16.             “”“<html><body><h1>This is the HTML body</h1></body></html>”“”)
  17.        
  18. address = (‘localhost’, 8765)
  19. print “Connected on: %s:%s” % address
  20. server = HTTPServer(address, RequestHandler)
  21.  
  22. webbrowser.browser = “iexplore.exe”
  23. webbrowser.open(“http://%s:%d” % address)
  24.  
  25. server.serve_forever()

Just tweak the webbrowser part for make it work under all browsers.

06 Dec 05 - UPDATE: Valentino Volonghi wrote a version using the Twisted Matrix framework: A Web server in Twisted