2424# the dummy data returned by server over the data channel when
2525# RETR, LIST and NLST commands are issued
2626RETR_DATA = 'abcde12345\r \n ' * 1000
27- RETR_TEXT = 'abcd\xe9 12345\r \n ' * 1000
2827LIST_DATA = 'foo\r \n bar\r \n '
2928NLST_DATA = 'foo\r \n bar\r \n '
3029
@@ -38,7 +37,7 @@ def __init__(self, conn, baseclass):
3837 self .baseclass .last_received_data = ''
3938
4039 def handle_read (self ):
41- self .baseclass .last_received_data += self .recv (1024 ).decode ('latin-1 ' )
40+ self .baseclass .last_received_data += self .recv (1024 ).decode ('ascii ' )
4241
4342 def handle_close (self ):
4443 # XXX: this method can be called many times in a row for a single
@@ -50,7 +49,7 @@ def handle_close(self):
5049 self .dtp_conn_closed = True
5150
5251 def push (self , what ):
53- super (DummyDTPHandler , self ).push (what .encode ('latin-1 ' ))
52+ super (DummyDTPHandler , self ).push (what .encode ('ascii ' ))
5453
5554 def handle_error (self ):
5655 raise
@@ -69,7 +68,6 @@ def __init__(self, conn):
6968 self .last_received_data = ''
7069 self .next_response = ''
7170 self .rest = None
72- self .current_type = 'a'
7371 self .push ('220 welcome' )
7472
7573 def collect_incoming_data (self , data ):
@@ -177,16 +175,7 @@ def cmd_pwd(self, arg):
177175 self .push ('257 "pwd ok"' )
178176
179177 def cmd_type (self , arg ):
180- # ASCII type
181- if arg .lower () == 'a' :
182- self .current_type = 'a'
183- self .push ('200 type ok' )
184- # Binary type
185- elif arg .lower () == 'i' :
186- self .current_type = 'i'
187- self .push ('200 type ok' )
188- else :
189- self .push ('504 unsupported type' )
178+ self .push ('200 type ok' )
190179
191180 def cmd_quit (self , arg ):
192181 self .push ('221 quit ok' )
@@ -205,10 +194,7 @@ def cmd_retr(self, arg):
205194 offset = int (self .rest )
206195 else :
207196 offset = 0
208- if self .current_type == 'i' :
209- self .dtp .push (RETR_DATA [offset :])
210- else :
211- self .dtp .push (RETR_TEXT [offset :])
197+ self .dtp .push (RETR_DATA [offset :])
212198 self .dtp .close_when_done ()
213199 self .rest = None
214200
@@ -525,7 +511,7 @@ def callback(data):
525511 def test_retrlines (self ):
526512 received = []
527513 self .client .retrlines ('retr' , received .append )
528- self .assertEqual ('' .join (received ), RETR_TEXT .replace ('\r \n ' , '' ))
514+ self .assertEqual ('' .join (received ), RETR_DATA .replace ('\r \n ' , '' ))
529515
530516 def test_storbinary (self ):
531517 f = io .BytesIO (RETR_DATA .encode ('ascii' ))
@@ -544,7 +530,7 @@ def test_storbinary_rest(self):
544530 self .client .storbinary ('stor' , f , rest = r )
545531 self .assertEqual (self .server .handler_instance .rest , str (r ))
546532
547- def test_storlines_bytes (self ):
533+ def test_storlines (self ):
548534 f = io .BytesIO (RETR_DATA .replace ('\r \n ' , '\n ' ).encode ('ascii' ))
549535 self .client .storlines ('stor' , f )
550536 self .assertEqual (self .server .handler_instance .last_received_data , RETR_DATA )
@@ -554,16 +540,6 @@ def test_storlines_bytes(self):
554540 self .client .storlines ('stor foo' , f , callback = lambda x : flag .append (None ))
555541 self .assertTrue (flag )
556542
557- def test_storlines_str (self ):
558- f = io .StringIO (RETR_TEXT .replace ('\r \n ' , '\n ' ))
559- self .client .storlines ('stor' , f )
560- self .assertEqual (self .server .handler_instance .last_received_data , RETR_TEXT )
561- # test new callback arg
562- flag = []
563- f .seek (0 )
564- self .client .storlines ('stor foo' , f , callback = lambda x : flag .append (None ))
565- self .assertTrue (flag )
566-
567543 def test_nlst (self ):
568544 self .client .nlst ()
569545 self .assertEqual (self .client .nlst (), NLST_DATA .split ('\r \n ' )[:- 1 ])
0 commit comments