<s> from __future__ import print_function , unicode_literals , division , absolute_import <EOL> import os , sys , io , locale , threading <EOL> from io import TextIOWrapper <EOL> from contextlib import contextmanager <EOL> from collections import MutableMapping <EOL> try : <EOL> sys_encoding = locale . getdefaultlocale ( ) [ <NUM_LIT:1> ] or "<STR_LIT>" <EOL> except Exception : <EOL> sys_encoding = "<STR_LIT>" <EOL> USING_PYTHON2 = True if sys . version_info < ( <NUM_LIT:3> , <NUM_LIT:0> ) else False <EOL> _stdio_wrapped = False <EOL> if USING_PYTHON2 : <EOL> from cStringIO import StringIO <EOL> from httplib import BadStatusLine <EOL> BytesIO = StringIO <EOL> builtin_str = str <EOL> bytes = str <EOL> str = unicode <EOL> basestring = basestring <EOL> builtin_int = int <EOL> int = long <EOL> open = io . open <EOL> THREAD_TIMEOUT_MAX = sys . maxint <EOL> def input ( prompt = None ) : <EOL> encoded_prompt = prompt . encode ( sys_encoding ) <EOL> with unwrap_stream ( "<STR_LIT>" ) , unwrap_stream ( "<STR_LIT>" ) : <EOL> return raw_input ( encoded_prompt ) . decode ( sys_encoding ) <EOL> def expanduser ( path ) : <EOL> '''<STR_LIT>''' <EOL> if not path . startswith ( '<STR_LIT>' ) : <EOL> return path <EOL> i = path . find ( '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> if i < <NUM_LIT:0> : <EOL> i = len ( path ) <EOL> if i == <NUM_LIT:1> : <EOL> if '<STR_LIT>' not in environ : <EOL> import pwd <EOL> userhome = pwd . getpwuid ( os . getuid ( ) ) . pw_dir <EOL> else : <EOL> userhome = environ [ '<STR_LIT>' ] <EOL> if isinstance ( userhome , bytes ) : <EOL> userhome = userhome . decode ( sys_encoding ) <EOL> else : <EOL> import pwd <EOL> try : <EOL> pwent = pwd . getpwnam ( path [ <NUM_LIT:1> : i ] ) <EOL> except KeyError : <EOL> return path <EOL> userhome = pwent . pw_dir <EOL> userhome = userhome . rstrip ( '<STR_LIT:/>' ) <EOL> return ( userhome + path [ i : ] ) or '<STR_LIT:/>' <EOL> if os . name == '<STR_LIT>' : <EOL> expanduser = os . path . expanduser <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:3> ) : <EOL> from . packages import shlex <EOL> else : <EOL> import shlex <EOL> else : <EOL> from io import StringIO , BytesIO <EOL> from http . client import BadStatusLine <EOL> import shlex <EOL> builtin_str = str <EOL> str = str <EOL> bytes = bytes <EOL> basestring = ( str , bytes ) <EOL> input = input <EOL> builtin_int = int <EOL> int = int <EOL> open = open <EOL> expanduser = os . path . expanduser <EOL> THREAD_TIMEOUT_MAX = threading . TIMEOUT_MAX <EOL> def wrap_stdio_in_codecs ( ) : <EOL> if USING_PYTHON2 : <EOL> global _stdio_wrapped <EOL> if not _stdio_wrapped : <EOL> class StderrTextIOWrapper ( TextIOWrapper ) : <EOL> def write ( self , text ) : <EOL> if type ( text ) is unicode : <EOL> TextIOWrapper . write ( self , text ) <EOL> else : <EOL> TextIOWrapper . write ( self , unicode ( text , self . encoding ) ) <EOL> if hasattr ( sys . stdin , '<STR_LIT>' ) : <EOL> original_stream = sys . stdin <EOL> sys . stdin = io . open ( sys . stdin . fileno ( ) , encoding = getattr ( sys . stdin , '<STR_LIT>' , None ) ) <EOL> sys . stdin . _original_stream = original_stream <EOL> else : <EOL> sys . stderr . write ( __name__ + "<STR_LIT>" ) <EOL> if hasattr ( sys . stdout , '<STR_LIT>' ) : <EOL> original_stream = sys . stdout <EOL> sys . stdout = StderrTextIOWrapper ( io . FileIO ( sys . stdout . fileno ( ) , mode = '<STR_LIT:w>' ) , <EOL> encoding = getattr ( sys . stdout , '<STR_LIT>' , None ) , <EOL> line_buffering = True if sys . stdout . isatty ( ) else False ) <EOL> sys . stdout . _original_stream = original_stream <EOL> else : <EOL> sys . stderr . write ( __name__ + "<STR_LIT>" ) <EOL> if hasattr ( sys . stderr , '<STR_LIT>' ) : <EOL> original_stream = sys . stderr <EOL> sys . stderr = StderrTextIOWrapper ( io . FileIO ( sys . stderr . fileno ( ) , mode = '<STR_LIT:w>' ) , <EOL> encoding = getattr ( sys . stderr , '<STR_LIT>' , None ) , <EOL> line_buffering = True ) <EOL> sys . stderr . _original_stream = original_stream <EOL> else : <EOL> sys . stderr . write ( __name__ + "<STR_LIT>" ) <EOL> _stdio_wrapped = True <EOL> def decode_command_line_args ( ) : <EOL> if USING_PYTHON2 : <EOL> sys . argv = [ i if isinstance ( i , unicode ) else i . decode ( sys_encoding ) for i in sys . argv ] <EOL> return sys . argv <EOL> def _ensure_bytes ( i ) : <EOL> if not isinstance ( i , bytes ) : <EOL> i = i . encode ( sys_encoding ) <EOL> return i <EOL> def _ensure_str ( i ) : <EOL> if isinstance ( i , bytes ) : <EOL> i = i . decode ( sys_encoding ) <EOL> return i <EOL> class _Environ ( MutableMapping ) : <EOL> def __getitem__ ( self , item ) : <EOL> return _ensure_str ( os . environ [ _ensure_bytes ( item ) ] ) <EOL> def __setitem__ ( self , varname , value ) : <EOL> os . environ [ _ensure_bytes ( varname ) ] = _ensure_bytes ( value ) <EOL> def __contains__ ( self , item ) : <EOL> return True if _ensure_bytes ( item ) in os . environ else False <EOL> def __repr__ ( self ) : <EOL> return repr ( dict ( self ) ) <EOL> def __iter__ ( self ) : <EOL> for key in os . environ : <EOL> yield _ensure_str ( key ) <EOL> def __delitem__ ( self , item ) : <EOL> del os . environ [ _ensure_bytes ( item ) ] <EOL> def __len__ ( self ) : <EOL> return len ( os . environ ) <EOL> def copy ( self ) : <EOL> return dict ( self ) <EOL> environ = _Environ ( ) if USING_PYTHON2 else os . environ <EOL> def wrap_env_var_handlers ( ) : <EOL> if USING_PYTHON2 and not getattr ( os , '<STR_LIT>' , None ) : <EOL> native_getenv , native_putenv = os . getenv , os . putenv <EOL> def getenv ( varname , value = None ) : <EOL> v = native_getenv ( varname , value ) <EOL> if isinstance ( v , bytes ) : <EOL> v = v . decode ( sys_encoding ) <EOL> return v <EOL> def putenv ( varname , value ) : <EOL> if not isinstance ( varname , bytes ) : <EOL> varname = varname . encode ( sys_encoding ) <EOL> if not isinstance ( value , bytes ) : <EOL> value = value . encode ( sys_encoding ) <EOL> native_putenv ( varname , value ) <EOL> os . getenv , os . putenv = getenv , putenv <EOL> os . __native_getenv , os . __native_putenv = native_getenv , native_putenv <EOL> def unwrap_env_var_handlers ( ) : <EOL> if USING_PYTHON2 and getattr ( os , __native_getenv , None ) : <EOL> os . getenv , os . putenv = os . __native_getenv , os . __native_putenv <EOL> @ contextmanager <EOL> def unwrap_stream ( stream_name ) : <EOL> """<STR_LIT>""" <EOL> wrapped_stream = None <EOL> try : <EOL> wrapped_stream = getattr ( sys , stream_name ) <EOL> if hasattr ( wrapped_stream , '<STR_LIT>' ) : <EOL> setattr ( sys , stream_name , wrapped_stream . _original_stream ) <EOL> yield <EOL> finally : <EOL> if wrapped_stream : <EOL> setattr ( sys , stream_name , wrapped_stream ) </s>
