<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import os <EOL> import sys <EOL> from six import PY2 <EOL> from getpass import getpass <EOL> from . . utils import auto_repr <EOL> from . base import InteractiveUI <EOL> """<STR_LIT>""" <EOL> from progressbar import Bar , ETA , FileTransferSpeed , Percentage , ProgressBar , RotatingMarker <EOL> class BarWithFillText ( Bar ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fill_text , ** kwargs ) : <EOL> super ( BarWithFillText , self ) . __init__ ( ** kwargs ) <EOL> self . fill_text = fill_text <EOL> def update ( self , pbar , width ) : <EOL> orig = super ( BarWithFillText , self ) . update ( pbar , width ) <EOL> if len ( self . fill_text ) > width : <EOL> fill_text = '<STR_LIT>' + self . fill_text [ - ( width - <NUM_LIT:4> ) : ] <EOL> else : <EOL> fill_text = self . fill_text <EOL> fill_text = fill_text [ : min ( len ( fill_text ) , int ( round ( width * pbar . percentage ( ) / <NUM_LIT> ) ) ) ] <EOL> return fill_text + "<STR_LIT:U+0020>" + orig [ len ( fill_text ) + <NUM_LIT:1> : ] <EOL> @ auto_repr <EOL> class ConsoleLog ( object ) : <EOL> def __init__ ( self , out = sys . stdout ) : <EOL> self . out = out <EOL> def message ( self , msg , cr = '<STR_LIT:\n>' ) : <EOL> self . out . write ( msg ) <EOL> if cr : <EOL> self . out . write ( cr ) <EOL> def error ( self , error ) : <EOL> self . out . write ( "<STR_LIT>" % error ) <EOL> def get_progressbar ( self , label = '<STR_LIT>' , fill_text = None , currval = None , maxval = None ) : <EOL> """<STR_LIT>""" <EOL> bar = dict ( marker = RotatingMarker ( ) ) <EOL> widgets = [ '<STR_LIT>' % label , <EOL> BarWithFillText ( fill_text = fill_text , marker = RotatingMarker ( ) ) , '<STR_LIT:U+0020>' , <EOL> Percentage ( ) , '<STR_LIT:U+0020>' , <EOL> ETA ( ) , '<STR_LIT:U+0020>' , <EOL> FileTransferSpeed ( ) ] <EOL> if currval is not None : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> return ProgressBar ( widgets = widgets , maxval = maxval , fd = self . out ) . start ( ) <EOL> @ auto_repr <EOL> class DialogUI ( ConsoleLog , InteractiveUI ) : <EOL> def question ( self , text , <EOL> title = None , choices = None , <EOL> default = None , <EOL> hidden = False ) : <EOL> if default and default not in choices : <EOL> raise ValueError ( "<STR_LIT>" <EOL> % ( default , choices ) ) <EOL> if title : <EOL> self . out . write ( title + "<STR_LIT:\n>" ) <EOL> def mark_default ( x ) : <EOL> return "<STR_LIT>" % x if default is not None and x == default else x <EOL> if choices is not None : <EOL> msg = "<STR_LIT>" % ( text , '<STR_LIT:U+002CU+0020>' . join ( map ( mark_default , choices ) ) ) <EOL> else : <EOL> msg = text <EOL> """<STR_LIT>""" <EOL> attempt = <NUM_LIT:0> <EOL> while True : <EOL> attempt += <NUM_LIT:1> <EOL> if attempt >= <NUM_LIT:100> : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> if not hidden : <EOL> self . out . write ( msg + "<STR_LIT>" ) <EOL> self . out . flush ( ) <EOL> response = ( raw_input if PY2 else input ) ( ) <EOL> else : <EOL> response = getpass ( msg + "<STR_LIT>" ) <EOL> if not response and default : <EOL> response = default <EOL> break <EOL> if choices and response not in choices : <EOL> self . error ( "<STR_LIT>" <EOL> % ( response , choices ) ) <EOL> continue <EOL> break <EOL> return response <EOL> @ auto_repr <EOL> class UnderAnnexUI ( DialogUI ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = sys . stderr <EOL> super ( UnderAnnexUI , self ) . __init__ ( ** kwargs ) </s>
