<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import logging <EOL> import optparse <EOL> import os <EOL> import shlex <EOL> import subprocess <EOL> import sys <EOL> import googletv <EOL> def get_parser ( ) : <EOL> """<STR_LIT>""" <EOL> usage = '<STR_LIT>' <EOL> parser = optparse . OptionParser ( usage = usage ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = <NUM_LIT> , <EOL> type = '<STR_LIT:int>' , <EOL> help = '<STR_LIT>' ) <EOL> return parser <EOL> def generate_cert ( filename , country = '<STR_LIT>' , state = '<STR_LIT>' , city = '<STR_LIT>' , <EOL> cn = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { <EOL> '<STR_LIT>' : city , <EOL> '<STR_LIT>' : cn , <EOL> '<STR_LIT>' : country , <EOL> '<STR_LIT:filename>' : filename , <EOL> '<STR_LIT:state>' : state , <EOL> } <EOL> command = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> command = '<STR_LIT:U+0020>' . join ( command ) % kwargs <EOL> args = shlex . split ( command ) <EOL> p = subprocess . Popen ( args ) <EOL> def main ( ) : <EOL> parser = get_parser ( ) <EOL> options = parser . parse_args ( ) [ <NUM_LIT:0> ] <EOL> host = options . host <EOL> port = options . port <EOL> cert = options . cert <EOL> if not os . path . isfile ( cert ) : <EOL> generate_cert ( cert ) <EOL> print '<STR_LIT>' <EOL> with googletv . PairingProtocol ( host , cert , port = port ) as gtv : <EOL> client_name = raw_input ( '<STR_LIT>' ) <EOL> gtv . send_pairing_request ( client_name ) <EOL> gtv . recv_pairing_request_ack ( ) <EOL> gtv . send_options ( ) <EOL> gtv . recv_options ( ) <EOL> gtv . send_configuration ( ) <EOL> gtv . recv_configuration_ack ( ) <EOL> code = raw_input ( '<STR_LIT>' ) <EOL> gtv . send_secret ( code ) <EOL> to_hex = lambda byte_str : '<STR_LIT>' . join ( [ '<STR_LIT>' % ord ( x ) for x in byte_str ] ) <EOL> try : <EOL> secret = to_hex ( gtv . recv_secret_ack ( ) . secret ) <EOL> print '<STR_LIT>' % secret <EOL> except : <EOL> print '<STR_LIT>' <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
