Changeset 1199:798c6f9a368c


Ignore:
Timestamp:
Mar 31, 2013, 1:16:00 PM (7 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Python 2/3 compatibility changes, based on a `2to3` run.
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • find_deprecated_code.py

    r1188 r1199  
    2828      ...
    2929"""
     30
     31from __future__ import print_function
    3032
    3133import os
     
    8183    for title, regex, positions in deprecated_features:
    8284        if title != last_title:
    83             print
    84             print title, "..."
    85             print
     85            print()
     86            print(title, "...")
     87            print()
    8688            last_title = title
    8789        if not positions:
    88             print "   no deprecated code found"
     90            print("   no deprecated code found")
    8991            continue
    90         file_names = positions.keys()
    91         file_names.sort()
    92         for file_name in file_names:
    93             print file_name
     92        for file_name in sorted(positions.keys()):
     93            print(file_name)
    9494            for line_number, line in positions[file_name]:
    95                 print "%5d: %s" % (line_number, line)
    96     print
    97     print "If possible, check your code also by other means."
     95                print("%5d: %s" % (line_number, line))
     96    print()
     97    print("If possible, check your code also by other means.")
    9898
    9999
     
    116116    if len(sys.argv) == 2:
    117117        if sys.argv[1] in ("-h", "--help"):
    118             print __doc__
     118            print(__doc__)
    119119            sys.exit(0)
    120120        start_dir = sys.argv[1]
    121121        if not os.path.isdir(start_dir):
    122             print >> sys.stderr, "Directory %s not found." % start_dir
     122            print("Directory %s not found." % start_dir, file=sys.stderr)
    123123            sys.exit()
    124124    else:
    125         print >> sys.stderr, "Usage: %s start_dir" % sys.argv[0]
     125        print("Usage: %s start_dir" % sys.argv[0], file=sys.stderr)
    126126        sys.exit()
    127127    main(start_dir)
  • ftputil/__init__.py

    r1196 r1199  
    1 # Copyright (C) 2002-2012, Stefan Schwarzer <sschwarzer@sschwarzer.net>
     1# Copyright (C) 2002-2013, Stefan Schwarzer <sschwarzer@sschwarzer.net>
    22# Copyright (C) 2008, Roger Demetrescu <roger.demetrescu@gmail.com>
    33# See the file LICENSE for licensing terms.
     
    848848            with ftputil.error.ftplib_error_to_ftp_os_error:
    849849                if self.use_list_a_option:
    850                     self._session.dir(u"-a", path, callback)
     850                    self._session.dir("-a", path, callback)
    851851                else:
    852852                    self._session.dir(path, callback)
  • ftputil/compat.py

    r1136 r1199  
    1717
    1818
    19 if sys.version_info[0] == 2:
     19if sys.version_info.major == 2:
    2020
    2121    # As a low-level networking library, ftputil mostly works on
     
    2525        return byte_string
    2626
    27     # Similarly for `StringIO` and such.
    28     import StringIO
    29     byte_string_io = StringIO.StringIO
     27    int_types = (int, long)
    3028
    3129else:
     
    3432        return bytes(byte_string, encoding="ASCII")
    3533
    36     import io
    37     byte_string_io = io.BytesIO
     34    int_types = (int,)
  • ftputil/file.py

    r1196 r1199  
    156156        return self
    157157
    158     def next(self):
     158    def __next__(self):
    159159        """
    160160        Return the next line or raise `StopIteration`, if there are
     
    167167        else:
    168168            raise StopIteration
     169
     170    # For Python 2 compatibility
     171    next = __next__
    169172
    170173    def write(self, data):
  • ftputil/lrucache.py

    r1192 r1199  
    4848# The suffix after the hyphen denotes modifications by the
    4949# ftputil project with respect to the original version.
    50 __version__ = "0.2-11"
     50__version__ = "0.2-12"
    5151__all__ = ['CacheKeyError', 'LRUCache', 'DEFAULT_SIZE']
    5252__docformat__ = 'reStructuredText en'
     
    5454# Default size of a new LRUCache object, if no 'size' argument is given.
    5555DEFAULT_SIZE = 16
     56
     57# For Python 2/3 compatibilty
     58try:
     59    long
     60    int_types = (int, long)
     61except NameError:
     62    int_types = (int,)
    5663
    5764
     
    248255        if name == 'size':
    249256            size = value
    250             if not isinstance(size, (int, long)):
     257            if not isinstance(size, int_types):
    251258                raise TypeError("cache size (%r) must be an integer" % size)
    252259            if size <= 0:
     
    282289if __name__ == "__main__":
    283290    cache = LRUCache(25)
    284     print cache
     291    print(cache)
    285292    for i in range(50):
    286293        cache[i] = str(i)
    287     print cache
     294    print(cache)
    288295    if 46 in cache:
    289296        del cache[46]
    290     print cache
     297    print(cache)
    291298    cache.size = 10
    292     print cache
     299    print(cache)
    293300    cache[46] = '46'
    294     print cache
    295     print len(cache)
     301    print(cache)
     302    print(len(cache))
    296303    for c in cache:
    297         print c
    298     print cache
    299     print cache.mtime(46)
     304        print(c)
     305    print(cache)
     306    print(cache.mtime(46))
    300307    for c in cache:
    301         print c
     308        print(c)
  • ftputil/stat.py

    r1196 r1199  
    372372        # st_mode
    373373        #  Default to read access only; in fact, we can't tell.
    374         st_mode = 0400
     374        st_mode = 0o400
    375375        if dir_or_size == "<DIR>":
    376376            st_mode = st_mode | stat.S_IFDIR
Note: See TracChangeset for help on using the changeset viewer.