@@ -101,11 +101,11 @@ def start(self):
101
101
class Tube (object ):
102
102
def __init__ (self , _sock ):
103
103
self ._sock = _sock
104
- self .buf = ''
104
+ self .buf = b ''
105
105
106
106
def readline (self ):
107
107
while True :
108
- i = self .buf .find ('\n ' )
108
+ i = self .buf .find (b '\n ' )
109
109
if i >= 0 :
110
110
result , self .buf = self .buf [:i + 1 ], self .buf [i + 1 :]
111
111
return result
@@ -194,7 +194,7 @@ def handle_client(self, sock,addr,idx):
194
194
wrapped_sock .shutdown (socket .SHUT_WR )
195
195
wrapped_sock .close ()
196
196
except Exception as e :
197
- f .write (traceback .format_exc ())
197
+ f .write (traceback .format_exc (). encode ( 'utf-8' ) )
198
198
f .flush ()
199
199
f .close ()
200
200
@@ -210,7 +210,7 @@ def recvline(self):
210
210
return l
211
211
self .f .flush ()
212
212
self .f .write (l )
213
- sys .stdout .write (self .host + ': ' + l )
213
+ sys .stdout .write (self .host + ': ' + l . decode ( 'utf-8' ) )
214
214
return l
215
215
216
216
@staticmethod
@@ -240,7 +240,7 @@ def handle(self, **kwargs):
240
240
self .f .write (request )
241
241
self .f .flush ()
242
242
request = self .sock .read ()
243
- self .sock .write ("HTTP/1.1 200 OK\r \n Content-Length: 0\r \n \r \n " )
243
+ self .sock .write (b "HTTP/1.1 200 OK\r \n Content-Length: 0\r \n \r \n " )
244
244
245
245
class AnonFileHandler (ConnectionHandler ):
246
246
def handle (self , logfile = '' ):
@@ -252,7 +252,7 @@ def handle(self, logfile=''):
252
252
file_url = ('https' if LOG_VIEWER_HTTPS else 'http' ) + '://' + FQDN + ':' + str (LOG_VIEWER_PORT ) + os .sep + logfile [len (LOG_DIR )+ 1 :]
253
253
print ('Finished receiving file %s' % (logfile ,))
254
254
print ('Available at %s' % (file_url ,))
255
- self .sock .write (file_url + '\n ' )
255
+ self .sock .write (( file_url + '\n ' ). encode ( 'utf-8' ) )
256
256
257
257
@staticmethod
258
258
def get_file_ext ():
@@ -263,32 +263,38 @@ class SmtpHandler(ConnectionHandler):
263
263
def handle (self , ** kwargs ):
264
264
print (self .host + ': RX begin >>>>' )
265
265
266
- self .sock .send ('220 ' + FQDN + ' ESMTP Postfix\r \n ' )
266
+ self .sock .send (( b '220 ' + FQDN . encode ( 'ascii' ) + b ' ESMTP Postfix\r \n ') )
267
267
self .recvline ()
268
- self .sock .send ('250 ' + FQDN + ', I am glad to meet you\r \n ' )
268
+ self .sock .send (b '250 ' + FQDN . encode ( 'ascii' ) + b ', I am glad to meet you\r \n ' )
269
269
270
270
while True :
271
271
l = self .recvline ()
272
272
if l == None :
273
273
print (self .host + ': Socket closed <<<<' )
274
274
return
275
- if l .startswith ('DATA' ):
276
- self .sock .send ('354 End data with <CR><LF>.<CR><LF>\r \n ' )
275
+ if l .startswith (b 'DATA' ):
276
+ self .sock .send (b '354 End data with <CR><LF>.<CR><LF>\r \n ' )
277
277
break
278
- if l .startswith ('QUIT' ):
278
+ if l .startswith (b 'QUIT' ):
279
279
print (self .host + ': Successfully RX <<<<' )
280
280
return
281
- self .sock .send ('250 Ok\r \n ' )
281
+ self .sock .send (b '250 Ok\r \n ' )
282
282
283
283
while True :
284
284
l = self .recvline ()
285
- if l == '.\r \n ' :
285
+ if l == None :
286
+ print (self .host + ': Socket closed <<<<' )
287
+ return
288
+ if l == b'.\r \n ' :
286
289
break
287
- self .sock .send ('250 Ok: queued as 12345\r \n ' )
290
+ self .sock .send (b '250 Ok: queued as 12345\r \n ' )
288
291
289
292
while True :
290
293
l = self .recvline ()
291
- if l .startswith ('QUIT' ):
294
+ if l == None :
295
+ print (self .host + ': Socket closed <<<<' )
296
+ return
297
+ if l .startswith (b'QUIT' ):
292
298
break
293
299
print (self .host + ': Successfully RX <<<<' )
294
300
0 commit comments