<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import division <EOL> from pycopia import protocols <EOL> class BasicHTTPRequest ( protocols . Protocol ) : <EOL> EOL = "<STR_LIT:\r\n>" <EOL> def initialize ( self , fsm ) : <EOL> fsm . set_default_transition ( self . _enterdefault , fsm . RESET ) <EOL> fsm . add_regex ( r"<STR_LIT>" , fsm . RESET , self . _status200 , <NUM_LIT:1> ) <EOL> fsm . add_regex ( r"<STR_LIT>" , fsm . RESET , self . _statusother , <NUM_LIT:1> ) <EOL> fsm . add_regex ( r"<STR_LIT>" , <NUM_LIT:1> , self . _header , <NUM_LIT:1> ) <EOL> fsm . add ( "<STR_LIT:\r\n>" , <NUM_LIT:1> , None , <NUM_LIT:2> ) <EOL> fsm . add ( fsm . ANY , <NUM_LIT:2> , self . _body , <NUM_LIT:2> ) <EOL> def start ( self ) : <EOL> self . status = None <EOL> self . headers = [ ] <EOL> self . bodychunks = [ ] <EOL> self . iostream . write ( <EOL> "<STR_LIT>" . format ( self . iostream . host ) ) <EOL> def _status200 ( self , mo ) : <EOL> self . status = ( "<STR_LIT>" , mo . groups ( ) [ <NUM_LIT:0> ] ) <EOL> def _statusother ( self , mo ) : <EOL> self . status = mo . groups ( ) <EOL> def _header ( self , mo ) : <EOL> hname , hvalue = mo . groups ( ) <EOL> self . headers . append ( ( hname , hvalue ) ) <EOL> if hname . lower ( ) == "<STR_LIT>" : <EOL> self . _content_length = int ( hvalue ) <EOL> def _body ( self , text ) : <EOL> self . bodychunks . append ( text ) <EOL> def _enterdefault ( self , text ) : <EOL> print ( "<STR_LIT>" , text , file = sys . stderr ) <EOL> class ChunkedHTTPRequest ( protocols . Protocol ) : <EOL> pass <EOL> class BasicHTTPPOST ( protocols . Protocol ) : <EOL> EOL = "<STR_LIT:\r\n>" <EOL> def initialize ( self , fsm ) : <EOL> fsm . set_default_transition ( self . _enterdefault , fsm . RESET ) <EOL> fsm . add_regex ( r"<STR_LIT>" , fsm . RESET , self . _status200 , <NUM_LIT:1> ) <EOL> fsm . add_regex ( r"<STR_LIT>" , fsm . RESET , self . _statusother , <NUM_LIT:1> ) <EOL> fsm . add_regex ( r"<STR_LIT>" , <NUM_LIT:1> , self . _header , <NUM_LIT:1> ) <EOL> fsm . add ( "<STR_LIT:\r\n>" , <NUM_LIT:1> , None , <NUM_LIT:2> ) <EOL> fsm . add ( fsm . ANY , <NUM_LIT:2> , self . _body , <NUM_LIT:2> ) <EOL> def start ( self ) : <EOL> self . status = None <EOL> self . headers = [ ] <EOL> self . bodychunks = [ ] <EOL> data = "<STR_LIT>" <EOL> self . iostream . write ( <EOL> """<STR_LIT>""" . format ( self . iostream . host , len ( data ) , data ) ) <EOL> def _status200 ( self , mo ) : <EOL> self . status = ( "<STR_LIT>" , mo . groups ( ) [ <NUM_LIT:0> ] ) <EOL> def _statusother ( self , mo ) : <EOL> self . status = mo . groups ( ) <EOL> def _header ( self , mo ) : <EOL> hname , hvalue = mo . groups ( ) <EOL> self . headers . append ( ( hname , hvalue ) ) <EOL> if hname . lower ( ) == "<STR_LIT>" : <EOL> self . _content_length = int ( hvalue ) <EOL> def _body ( self , text ) : <EOL> self . bodychunks . append ( text ) <EOL> def _enterdefault ( self , text ) : <EOL> self . log ( "<STR_LIT>" , text , "<STR_LIT>" , self . state ) </s>
