Changeset 840:09c54f758f74

Show
Ignore:
Timestamp:
2010-02-10 21:57:27 (6 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Removed `xreadlines` stuff as announced in
http://codespeak.net/pipermail/ftputil/2009q1/000256.html .
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • _test_ftp_file.py

    r708 r840  
    1 # Copyright (C) 2002-2008, Stefan Schwarzer 
     1# Copyright (C) 2002-2010, Stefan Schwarzer 
    22# All rights reserved. 
    33# 
     
    216216        input_.close() 
    217217 
    218     def test_ascii_xreadlines(self): 
    219         """Read ASCII text with `xreadlines`.""" 
    220         host = _test_base.ftp_host_factory(session_factory=ReadMockSession) 
    221         # open file, skip some bytes 
    222         input_ = host.file('dummy', 'r') 
    223         data = input_.read(3) 
    224         xrl_obj = input_.xreadlines() 
    225         self.failUnless(xrl_obj.__class__ is ftp_file._XReadlines) 
    226         self.failUnless(xrl_obj._ftp_file.__class__ is ftp_file._FTPFile) 
    227         data = xrl_obj[0] 
    228         self.assertEqual(data, 'e 1\n') 
    229         # try to skip an index 
    230         self.assertRaises(RuntimeError, operator.__getitem__, xrl_obj, 2) 
    231         # continue reading 
    232         data = xrl_obj[1] 
    233         self.assertEqual(data, 'another line\n') 
    234         data = xrl_obj[2] 
    235         self.assertEqual(data, 'yet another line') 
    236         # try to read beyond EOF 
    237         self.assertRaises(IndexError, operator.__getitem__, xrl_obj, 3) 
    238  
    239218    def test_binary_iterator(self): 
    240219        """Test the iterator interface of `FTPFile` objects.""" 
  • ftp_file.py

    r729 r840  
    1 # Copyright (C) 2003-2008, Stefan Schwarzer <sschwarzer@sschwarzer.net> 
     1# Copyright (C) 2003-2010, Stefan Schwarzer <sschwarzer@sschwarzer.net> 
    22# All rights reserved. 
    33# 
     
    3636# $Id$ 
    3737 
    38 import warnings 
    39  
    4038import ftp_error 
    4139 
     
    6462    """ 
    6563    return text.replace('\n', '\r\n') 
    66  
    67  
    68 # helper class for xreadline protocol for ASCII transfers 
    69 #XXX maybe we can use the `xreadlines` module instead of this? 
    70 class _XReadlines(object): 
    71     """Represents `xreadline` objects for ASCII transfers.""" 
    72  
    73     def __init__(self, ftp_file): 
    74         self._ftp_file = ftp_file 
    75         self._next_index = 0 
    76  
    77     def __getitem__(self, index): 
    78         """Return next line with specified index.""" 
    79         if index != self._next_index: 
    80             raise RuntimeError( "_XReadline access index " 
    81                   "out of order (expected %s but got %s)" % 
    82                   (self._next_index, index) ) 
    83         line = self._ftp_file.readline() 
    84         if not line: 
    85             raise IndexError("_XReadline object out of data") 
    86         self._next_index += 1 
    87         return line 
    8864 
    8965 
     
    197173        return lines 
    198174 
    199     def xreadlines(self): 
    200         """ 
    201         Return an appropriate `xreadlines` object with built-in line 
    202         separator conversion support. 
    203         """ 
    204         warnings.warn(("FTPFile.xreadlines is deprecated and will be removed " 
    205           "in ftputil 2.5"), DeprecationWarning, stacklevel=2) 
    206         if self._bin_mode: 
    207             return self._fo.xreadlines() 
    208         return _XReadlines(self) 
    209  
    210175    def __iter__(self): 
    211176        """Return a file iterator."""