|
|
|
@ -23,33 +23,9 @@ from struct import pack
|
|
|
|
|
from struct import unpack
|
|
|
|
|
|
|
|
|
|
from alfcrypto import Topaz_Cipher
|
|
|
|
|
from utilities import SafeUnbuffered
|
|
|
|
|
|
|
|
|
|
# Wrap a stream so that output gets flushed immediately
|
|
|
|
|
# and also make sure that any unicode strings get
|
|
|
|
|
# encoded using "replace" before writing them.
|
|
|
|
|
class SafeUnbuffered:
|
|
|
|
|
def __init__(self, stream):
|
|
|
|
|
self.stream = stream
|
|
|
|
|
self.encoding = stream.encoding
|
|
|
|
|
if self.encoding == None:
|
|
|
|
|
self.encoding = "utf-8"
|
|
|
|
|
def write(self, data):
|
|
|
|
|
if isinstance(data,str) or isinstance(data,unicode):
|
|
|
|
|
# str for Python3, unicode for Python2
|
|
|
|
|
data = data.encode(self.encoding,"replace")
|
|
|
|
|
try:
|
|
|
|
|
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
|
|
|
# self.stream.buffer for Python3, self.stream for Python2
|
|
|
|
|
buffer.write(data)
|
|
|
|
|
buffer.flush()
|
|
|
|
|
except:
|
|
|
|
|
# We can do nothing if a write fails
|
|
|
|
|
raise
|
|
|
|
|
def __getattr__(self, attr):
|
|
|
|
|
return getattr(self.stream, attr)
|
|
|
|
|
|
|
|
|
|
iswindows = sys.platform.startswith('win')
|
|
|
|
|
isosx = sys.platform.startswith('darwin')
|
|
|
|
|
from argv_utils import unicode_argv
|
|
|
|
|
|
|
|
|
|
def unicode_argv():
|
|
|
|
|
if iswindows:
|
|
|
|
|