<s> from __future__ import ( unicode_literals , division , absolute_import , print_function ) <EOL> import sys <EOL> import socket <EOL> import errno <EOL> import os <EOL> try : <EOL> from posix import environ <EOL> except ImportError : <EOL> from os import environ <EOL> sys . path . pop ( <NUM_LIT:0> ) <EOL> try : <EOL> from powerline . lib . encoding import get_preferred_output_encoding <EOL> except ImportError : <EOL> sys . path . append ( os . path . dirname ( os . path . dirname ( os . path . abspath ( os . path . realpath ( __file__ ) ) ) ) ) <EOL> from powerline . lib . encoding import get_preferred_output_encoding <EOL> if len ( sys . argv ) < <NUM_LIT:2> : <EOL> print ( '<STR_LIT>' , file = sys . stderr ) <EOL> raise SystemExit ( <NUM_LIT:1> ) <EOL> use_filesystem = not sys . platform . lower ( ) . startswith ( '<STR_LIT>' ) <EOL> if sys . argv [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> address = sys . argv [ <NUM_LIT:2> ] <EOL> if not use_filesystem : <EOL> address = '<STR_LIT>' + address <EOL> del sys . argv [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> else : <EOL> address = ( '<STR_LIT>' if use_filesystem else '<STR_LIT>' ) % os . getuid ( ) <EOL> sock = socket . socket ( family = socket . AF_UNIX ) <EOL> def eintr_retry_call ( func , * args , ** kwargs ) : <EOL> while True : <EOL> try : <EOL> return func ( * args , ** kwargs ) <EOL> except EnvironmentError as e : <EOL> if getattr ( e , '<STR_LIT>' , None ) == errno . EINTR : <EOL> continue <EOL> raise <EOL> try : <EOL> eintr_retry_call ( sock . connect , address ) <EOL> except Exception : <EOL> args = [ '<STR_LIT>' ] + sys . argv [ <NUM_LIT:1> : ] <EOL> os . execvp ( '<STR_LIT>' , args ) <EOL> fenc = get_preferred_output_encoding ( ) <EOL> def tobytes ( s ) : <EOL> if isinstance ( s , bytes ) : <EOL> return s <EOL> else : <EOL> return s . encode ( fenc ) <EOL> args = [ tobytes ( '<STR_LIT>' % ( len ( sys . argv ) - <NUM_LIT:1> ) ) ] <EOL> args . extend ( ( tobytes ( s ) for s in sys . argv [ <NUM_LIT:1> : ] ) ) <EOL> try : <EOL> cwd = os . getcwd ( ) <EOL> except EnvironmentError : <EOL> pass <EOL> else : <EOL> if not isinstance ( cwd , bytes ) : <EOL> cwd = cwd . encode ( fenc ) <EOL> args . append ( cwd ) <EOL> args . extend ( ( tobytes ( k ) + b'<STR_LIT:=>' + tobytes ( v ) for k , v in environ . items ( ) ) ) <EOL> EOF = b'<STR_LIT>' <EOL> for a in args : <EOL> eintr_retry_call ( sock . sendall , a + b'<STR_LIT>' ) <EOL> eintr_retry_call ( sock . sendall , EOF ) <EOL> received = [ ] <EOL> while True : <EOL> r = sock . recv ( <NUM_LIT> ) <EOL> if not r : <EOL> break <EOL> received . append ( r ) <EOL> sock . close ( ) <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> sys . stdout . write ( b'<STR_LIT>' . join ( received ) ) <EOL> else : <EOL> sys . stdout . buffer . write ( b'<STR_LIT>' . join ( received ) ) </s>
