#!/usr/bin/python

import sys
import os
import glob
#sys.path.append(os.path.join(os.path.dirname(__file__), "gen-py"))
sys.path.append(os.path.join(os.path.dirname(__file__),"gen-py/thrift_solr/"))
sys.path.append(os.path.dirname(__file__) )

from thrift.transport import TSocket 
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer 
from thrift.protocol.TBinaryProtocol import TBinaryProtocolAccelerated

#import thrift_solr


import ExtractorService

import sys

import readability

import readability

def extract_with_python_readability( raw_content ):
    doc = readability.Document( raw_content )
    
    return [ u'' + doc.short_title(),
             u'' + doc.summary() ]

class ExtractorHandler:
    def extract_html( self, raw_html ):

        #print raw_html

        #raw_html = raw_html.encode( 'utf-8' )

        ret =  extract_with_python_readability( raw_html )
        #print ret[1]
        return ret

handler = ExtractorHandler()
processor = ExtractorService.Processor(handler)
listening_socket = TSocket.TServerSocket(port=9090)
tfactory = TTransport.TBufferedTransportFactory()
#pfactory = TBinaryProtocol.TBinaryProtocolFactory()
pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()

server = TServer.TThreadPoolServer(processor, listening_socket, tfactory, pfactory)

print ("[Server] Started")
server.serve()

@@ -807,16 +807,138 @@
 tml ):%0A%0A
+        print %3E%3E sys.stderr, %22in ExtractorHandler.extract_html%22%0A        print %3E%3E sys.stderr, %22type: %22, type ( raw_html )%0A%0A
         
@@ -1282,17 +1282,16 @@
 ctory()%0A
-#
 pfactory
@@ -1326,32 +1326,33 @@
 otocolFactory()%0A
+#
 pfactory = TBina

Switch back to pure Python binary protocol because the C version screws up Unicode.