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 errno
|
||||
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print('Must provide at least one argument.', file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
|
@ -42,22 +43,23 @@ fenc = sys.getfilesystemencoding() or 'utf-8'
|
|||
if fenc == 'ascii':
|
||||
fenc = 'utf-8'
|
||||
|
||||
args = [bytes('%x' % (len(sys.argv) - 1))]
|
||||
args.extend((x.encode(fenc) if isinstance(x, type('')) else x for x in sys.argv[1:]))
|
||||
tobytes = lambda s: s if isinstance(s, bytes) else s.encode(fenc)
|
||||
|
||||
args = [tobytes('%x' % (len(sys.argv) - 1))]
|
||||
args.extend((tobytes(s) for s in sys.argv[1:]))
|
||||
|
||||
|
||||
try:
|
||||
cwd = os.getcwd()
|
||||
except EnvironmentError:
|
||||
pass
|
||||
else:
|
||||
if isinstance(cwd, type('')):
|
||||
if not isinstance(cwd, bytes):
|
||||
cwd = cwd.encode(fenc)
|
||||
args.append(cwd)
|
||||
|
||||
|
||||
env = (k + b'=' + 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)
|
||||
args.extend((tobytes(k) + b'=' + tobytes(v) for k, v in os.environ.items()))
|
||||
|
||||
EOF = b'\0\0'
|
||||
|
||||
|
@ -75,4 +77,7 @@ while True:
|
|||
|
||||
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