<s> """<STR_LIT>""" <EOL> from obfsproxy . transports . base import BaseTransport <EOL> import base64 <EOL> import obfsproxy . common . log as logging <EOL> log = logging . get_obfslogger ( ) <EOL> def _get_b64_chunks_from_str ( string ) : <EOL> """<STR_LIT>""" <EOL> chunks = [ ] <EOL> while True : <EOL> pad_loc = string . find ( '<STR_LIT:=>' ) <EOL> if pad_loc < <NUM_LIT:0> or pad_loc == len ( string ) - <NUM_LIT:1> or pad_loc == len ( string ) - <NUM_LIT:2> : <EOL> chunks . append ( string ) <EOL> return chunks <EOL> if pad_loc != len ( string ) - <NUM_LIT:1> and string [ pad_loc + <NUM_LIT:1> ] == '<STR_LIT:=>' : <EOL> pad_loc += <NUM_LIT:1> <EOL> chunks . append ( string [ : pad_loc + <NUM_LIT:1> ] ) <EOL> string = string [ pad_loc + <NUM_LIT:1> : ] <EOL> return chunks <EOL> class B64Transport ( BaseTransport ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( B64Transport , self ) . __init__ ( ) <EOL> def receivedDownstream ( self , data ) : <EOL> """<STR_LIT>""" <EOL> decoded_data = '<STR_LIT>' <EOL> b64_chunks = _get_b64_chunks_from_str ( data . peek ( ) ) <EOL> for chunk in b64_chunks : <EOL> try : <EOL> decoded_data += base64 . b64decode ( chunk ) <EOL> except TypeError : <EOL> log . info ( "<STR_LIT>" % chunk ) <EOL> return <EOL> data . drain ( ) <EOL> self . circuit . upstream . write ( decoded_data ) <EOL> def receivedUpstream ( self , data ) : <EOL> """<STR_LIT>""" <EOL> self . circuit . downstream . write ( base64 . b64encode ( data . read ( ) ) ) <EOL> return <EOL> class B64Client ( B64Transport ) : <EOL> pass <EOL> class B64Server ( B64Transport ) : <EOL> pass </s>
