Ignore:
Timestamp:
Dec 23, 2015, 5:21:44 PM (4 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Raise `CommandNotImplementedError` if `rest` is used for text files

Using `rest` for text files is confusing, don't support it.

For example, if a UTF-8-encoded file starts with "äbcdef", a `rest`
argument 3 would start reading at byte 3, but at the same time at
character 2 ("c") since "ä" is encoded in two bytes. Line ending
conversions would also result in deviations between byte and character
offsets.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/file.py

    r1618 r1619  
    1 # Copyright (C) 2003-2014, Stefan Schwarzer <sschwarzer@sschwarzer.net>
     1# Copyright (C) 2003-2015, Stefan Schwarzer <sschwarzer@sschwarzer.net>
    22# and ftputil contributors (see `doc/contributors.txt`)
    33# See the file LICENSE for licensing terms.
     
    7575        is_binary_mode = "b" in mode
    7676        is_read_mode = "r" in mode
    77         # Always use binary mode (see above).
     77        # `rest` is only allowed for binary mode.
     78        if (not is_binary_mode) and (rest is not None):
     79            raise ftputil.error.CommandNotImplementedError(
     80                    "`rest` argument can't be used for text files")
     81        # Always use binary mode (see comments above).
    7882        transfer_type = "I"
    7983        command = "TYPE {0}".format(transfer_type)
Note: See TracChangeset for help on using the changeset viewer.