Changeset 1938:e19cc39c2c9c


Ignore:
Timestamp:
May 25, 2020, 1:56:16 PM (15 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
amend_source:
ee7a1565d45dbaa82793813c251736de7d8d5fa7
Message:
Use `errno.EEXIST` instead of literal 17

The concrete value for a symbolic constant like `EEXIST` may differ
between platforms, so using the symbolic name is both a bit clearer
and more portable.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ftputil/host.py

    r1937 r1938  
    1010
    1111import datetime
     12import errno
    1213import ftplib
    1314import stat
     
    705706                        # Before PEP 3151, if `exist_ok` is `False`, trying to
    706707                        # create an existing directory in the local file system
    707                         # results in an `OSError` with `errno` 17, so emulate
    708                         # this also for FTP.
     708                        # results in an `OSError` with `errno.EEXIST, so
     709                        # emulate this also for FTP.
    709710                        ftp_os_error = ftputil.error.PermanentError(
    710711                            "path {!r} exists".format(path)
    711712                        )
    712                         ftp_os_error.errno = 17
     713                        ftp_os_error.errno = errno.EEXIST
    713714                        raise ftp_os_error
    714715        finally:
  • test/test_host.py

    r1937 r1938  
    44
    55import datetime
     6import errno
    67import ftplib
    78import io
     
    709710                host.makedirs("/part1/part2")
    710711            assert isinstance(exc_info.value, ftputil.error.PermanentError)
    711             assert exc_info.value.errno == 17
     712            assert exc_info.value.errno == errno.EEXIST
    712713        # `exist_ok` explicitly set to `False`
    713714        script = [
     
    724725                host.makedirs("/part1/part2", exist_ok=False)
    725726            assert isinstance(exc_info.value, ftputil.error.PermanentError)
    726             assert exc_info.value.errno == 17
     727            assert exc_info.value.errno == errno.EEXIST
    727728
    728729    def test_exist_ok_true(self):
Note: See TracChangeset for help on using the changeset viewer.