@contextmanager
def stdin_encoding(encoding=None):
 import sys
 _stdin = sys.stdin
 sys.stdin = SimpleMock(sys.stdin, 'encoding', encoding)
 (yield)
 sys.stdin = _stdin

@ contextmanager def stdin_encoding ( encoding = None ) : import sys _stdin = sys . stdin sys . stdin = SimpleMock ( sys . stdin , 'encoding' , encoding ) ( yield ) sys . stdin = _stdin
context manager for running bits of code while emulating an arbitrary stdin encoding .