def password_response(password, times_called=None, silent=True):
 fake = Fake('getpass', callable=True)
 if isinstance(password, StringTypes):
  passwords = [password]
 else:
  passwords = list(password)
 echo = (lambda x, y: y.write((x + ('\n' if (x != ' ') else ''))))
 fake = fake.returns(passwords.pop(0))
 if (not silent):
  fake = fake.calls(echo)
 for pw in passwords:
  fake = fake.next_call().returns(pw)
  if (not silent):
   fake = fake.calls(echo)
 if times_called:
  fake = fake.times_called(times_called)
 return patched_context(getpass, 'getpass', fake)

def password_response ( password , times_called = None , silent = True ) : fake = Fake ( 'getpass' , callable = True ) if isinstance ( password , StringTypes ) : passwords = [ password ] else : passwords = list ( password ) echo = ( lambda x , y : y . write ( ( x + ( '\n' if ( x != ' ' ) else '' ) ) ) ) fake = fake . returns ( passwords . pop ( 0 ) ) if ( not silent ) : fake = fake . calls ( echo ) for pw in passwords : fake = fake . next_call ( ) . returns ( pw ) if ( not silent ) : fake = fake . calls ( echo ) if times_called : fake = fake . times_called ( times_called ) return patched_context ( getpass , 'getpass' , fake )
context manager which patches getpass .