Solve encoding issues in powerline python client
This commit is contained in:
parent
74d147a0be
commit
dc76396912
|
@ -8,6 +8,7 @@ import socket
|
||||||
import os
|
import os
|
||||||
import errno
|
import errno
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print('Must provide at least one argument.', file=sys.stderr)
|
print('Must provide at least one argument.', file=sys.stderr)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
@ -42,22 +43,23 @@ fenc = sys.getfilesystemencoding() or 'utf-8'
|
||||||
if fenc == 'ascii':
|
if fenc == 'ascii':
|
||||||
fenc = 'utf-8'
|
fenc = 'utf-8'
|
||||||
|
|
||||||
args = [bytes('%x' % (len(sys.argv) - 1))]
|
tobytes = lambda s: s if isinstance(s, bytes) else s.encode(fenc)
|
||||||
args.extend((x.encode(fenc) if isinstance(x, type('')) else x for x in sys.argv[1:]))
|
|
||||||
|
args = [tobytes('%x' % (len(sys.argv) - 1))]
|
||||||
|
args.extend((tobytes(s) for s in sys.argv[1:]))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if isinstance(cwd, type('')):
|
if not isinstance(cwd, bytes):
|
||||||
cwd = cwd.encode(fenc)
|
cwd = cwd.encode(fenc)
|
||||||
args.append(cwd)
|
args.append(cwd)
|
||||||
|
|
||||||
|
|
||||||
env = (k + b'=' + v for k, v in os.environ.items())
|
args.extend((tobytes(k) + b'=' + tobytes(v) for k, v in os.environ.items()))
|
||||||
env = (x if isinstance(x, bytes) else x.encode(fenc, 'replace') for x in env)
|
|
||||||
args.extend(env)
|
|
||||||
|
|
||||||
EOF = b'\0\0'
|
EOF = b'\0\0'
|
||||||
|
|
||||||
|
@ -75,4 +77,7 @@ while True:
|
||||||
|
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
sys.stdout.write(b''.join(received))
|
if sys.version_info < (3,):
|
||||||
|
sys.stdout.write(b''.join(received))
|
||||||
|
else:
|
||||||
|
sys.stdout.buffer.write(b''.join(received))
|
||||||
|
|
Loading…
Reference in New Issue