<s> import dshell <EOL> import util <EOL> import dpkt <EOL> import gzip <EOL> import cStringIO <EOL> class HTTPDecoder ( dshell . TCPDecoder ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . noresponse = True <EOL> self . gunzip = True <EOL> dshell . TCPDecoder . __init__ ( self , ** kwargs ) <EOL> self . requests = { } <EOL> def errorH ( self , ** x ) : <EOL> return True <EOL> def blobHandler ( self , conn , blob ) : <EOL> '''<STR_LIT>''' <EOL> if conn not in self . requests : <EOL> try : <EOL> self . requests [ conn ] = ( <EOL> blob . starttime , dpkt . http . Request ( blob . data ( self . errorH ) ) ) <EOL> except Exception , e : <EOL> self . UnpackError ( e ) <EOL> else : <EOL> try : <EOL> if '<STR_LIT>' in dir ( self ) : <EOL> response = dpkt . http . Response ( blob . data ( self . errorH ) ) <EOL> if self . gunzip and '<STR_LIT>' in util . getHeader ( response , '<STR_LIT>' ) : <EOL> bodyUnzip = self . decompressGzipContent ( response . body ) <EOL> if bodyUnzip != None : <EOL> response . body = bodyUnzip <EOL> self . HTTPHandler ( conn = conn , <EOL> request = self . requests [ conn ] [ <NUM_LIT:1> ] , <EOL> response = response , <EOL> requesttime = self . requests [ conn ] [ <NUM_LIT:0> ] , <EOL> responsetime = blob . starttime ) <EOL> del self . requests [ conn ] <EOL> except Exception , e : <EOL> self . UnpackError ( e ) <EOL> self . HTTPHandler ( conn = conn , request = self . requests [ conn ] [ <EOL> <NUM_LIT:1> ] , response = None , requesttime = self . requests [ conn ] [ <NUM_LIT:0> ] , responsetime = blob . starttime ) <EOL> del self . requests [ conn ] <EOL> def connectionHandler ( self , conn ) : <EOL> '''<STR_LIT>''' <EOL> if conn in self . requests : <EOL> if self . noresponse and '<STR_LIT>' in dir ( self ) : <EOL> self . HTTPHandler ( conn = conn , <EOL> request = self . requests [ conn ] [ <NUM_LIT:1> ] , <EOL> response = None , <EOL> requesttime = self . requests [ conn ] [ <NUM_LIT:0> ] , <EOL> responsetime = self . requests [ conn ] [ <NUM_LIT:0> ] ) <EOL> del self . requests [ conn ] <EOL> def decompressGzipContent ( self , httpcontent ) : <EOL> '''<STR_LIT>''' <EOL> cstr = cStringIO . StringIO ( httpcontent ) <EOL> try : <EOL> return gzip . GzipFile ( fileobj = cstr ) . read ( ) <EOL> except : <EOL> return None <EOL> def UnpackError ( self , error ) : <EOL> self . _exc ( error ) <EOL> class displaystub ( dshell . Decoder ) : <EOL> def __init__ ( self ) : <EOL> dshell . Decoder . __init__ ( self , <EOL> name = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> longdescription = "<STR_LIT>" <EOL> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> dObj = displaystub ( ) <EOL> print dObj <EOL> else : <EOL> dObj = displaystub ( ) </s>
