Thrift Python server code generation

Summary: Yep, it's up and running. We now have full client/server support in all of C++ Java PHP and Python. Well, not quite... there's no PHP server, but honestly who wants one? Actually, if we do want one the framework will support writing is as a PHP file that can be served in apache like a web service (i.e. restserver.php would be thriftserver.php). But now that's rambling and nothing to do with this commit.

Notes: cheever, let's chat about porting your multithreaded Pillar Python server over to Thrift


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664783 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/server/TServer.py b/lib/py/src/server/TServer.py
new file mode 100644
index 0000000..69be260
--- /dev/null
+++ b/lib/py/src/server/TServer.py
@@ -0,0 +1,32 @@
+from thrift.Thrift import TProcessor
+from thrift.transport import TTransport
+
+class TServer:
+
+  """Base interface for a server, which must have a run method."""
+
+  def __init__(self, proc):
+    self.processor = proc
+
+  def run(self):
+    pass
+
+class TSimpleServer(TServer):
+
+  """Simple single-threaded server that just pumps around one transport."""
+
+  def __init__(self, proc, trans):
+    TServer.__init__(self, proc)
+    self.transport = trans
+
+  def run(self):
+    self.transport.listen()
+    while True:
+      client = TTransport.TBufferedTransport(self.transport.accept())
+      try:
+        while True:
+          self.processor.process(client, client)
+      except Exception, x:
+        print x
+        print 'Client died.'
+      client.close()