<s> import json <EOL> import sys <EOL> from getpass import getpass <EOL> from . compat import input <EOL> from . utils import JSONEncoder <EOL> class ConsoleOutput ( object ) : <EOL> def __init__ ( self , output , livestreamer , json = False ) : <EOL> self . livestreamer = livestreamer <EOL> self . logger = livestreamer . logger . new_module ( "<STR_LIT>" ) <EOL> self . json = json <EOL> self . set_output ( output ) <EOL> def set_level ( self , level ) : <EOL> self . livestreamer . set_loglevel ( level ) <EOL> def set_output ( self , output ) : <EOL> self . output = output <EOL> self . livestreamer . set_logoutput ( output ) <EOL> def ask ( self , msg , * args , ** kwargs ) : <EOL> formatted = msg . format ( * args , ** kwargs ) <EOL> sys . stderr . write ( formatted ) <EOL> try : <EOL> answer = input ( ) <EOL> except : <EOL> answer = "<STR_LIT>" <EOL> return answer . strip ( ) <EOL> def askpass ( self , msg , * args , ** kwargs ) : <EOL> formatted = msg . format ( * args , ** kwargs ) <EOL> return getpass ( formatted ) <EOL> def msg ( self , msg , * args , ** kwargs ) : <EOL> formatted = msg . format ( * args , ** kwargs ) <EOL> formatted = "<STR_LIT>" . format ( formatted ) <EOL> self . output . write ( formatted ) <EOL> def msg_json ( self , obj ) : <EOL> if not self . json : <EOL> return <EOL> if hasattr ( obj , "<STR_LIT>" ) : <EOL> obj = obj . __json__ ( ) <EOL> msg = json . dumps ( obj , cls = JSONEncoder , <EOL> indent = <NUM_LIT:2> ) <EOL> self . msg ( "<STR_LIT>" , msg ) <EOL> if isinstance ( obj , dict ) and obj . get ( "<STR_LIT:error>" ) : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def exit ( self , msg , * args , ** kwargs ) : <EOL> formatted = msg . format ( * args , ** kwargs ) <EOL> if self . json : <EOL> obj = dict ( error = formatted ) <EOL> self . msg_json ( obj ) <EOL> else : <EOL> msg = "<STR_LIT>" . format ( formatted ) <EOL> self . msg ( "<STR_LIT>" , msg ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> __all__ = [ "<STR_LIT>" ] </s>
