Skip to content

finalizer #47866

Closed
Closed

Description

@vstinner
BPO 3616
Nosy @pitrou, @vstinner, @Kentzo
Superseder
  • bpo-3187: os.listdir can return byte strings
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-08-20.09:36:39.218>
    created_at = <Date 2008-08-20.09:00:58.040>
    labels = ['library']
    title = 'finalizer'
    updated_at = <Date 2015-07-18.07:43:06.162>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2015-07-18.07:43:06.162>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-08-20.09:36:39.218>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2008-08-20.09:00:58.040>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 3616
    keywords = []
    message_count = 6.0
    messages = ['71521', '71524', '72084', '72088', '246888', '246889']
    nosy_count = 3.0
    nosy_names = ['pitrou', 'vstinner', 'Ilya.Kulakov']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '3187'
    type = None
    url = 'https://bugs.python.org/issue3616'
    versions = ['Python 2.5', 'Python 3.0']

    Activity

    1. vstinner commented on Aug 20, 2008

      @vstinner
      MemberAuthor

      If the directory contains invalid filenames (invalid in the system
      charset), an exception is raised by os.path.join() used by
      shutil.rmtree():

          fullname = os.path.join(path, name)
        File "/home/haypo/prog/py3k/Lib/posixpath.py", line 64, in join
          if b.startswith('/'):
      TypeError: expected an object with the buffer interface

      name is an bytes object, not a str object. My system charset is utf-8.

      Example to reproduce the problem:

      mkdir x
      # create a file with an invalid name
      touch -- $(echo -e 'x/--\0250--')
      python -c "import shutils; shutil.rmtree('x')"

      => TypeError: expected an object with the buffer interface

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Aug 20, 2008
    3. pitrou commented on Aug 20, 2008

      @pitrou
      Member

      This is certainly a consequence of bpo-3187, which is very high priority
      but also very difficult to find a satisying solution to.

    4. vstinner commented on Aug 28, 2008

      @vstinner
      MemberAuthor

      Python 2.5 has the same problem (at least, on Linux). rmtree(<unicode
      directory name>) fails if the directory contains invalid unicode
      string. Backtrace:
      ---
      File "shutil.py", line 163, in rmtree
      fullname = os.path.join(path, name)
      File "posixpath.py", line 65, in join
      path += '/' + b
      UnicodeDecodeError: 'ascii' codec can't decode byte 0xac in position
      3: ordinal not in range(128)
      ---

      The filename:
      $ ls /tmp/run-3/exitcode1/run-4/run-1/session-2/
      ?I?#??????????|?*? Pum

      The instruction was
      rmtree(u"/tmp/run-3/exitcode1/run-4/run-1/session-2").

    5. pitrou commented on Aug 28, 2008

      @pitrou
      Member

      Selon STINNER Victor <[email protected]>:

      Python 2.5 has the same problem (at least, on Linux). rmtree(<unicode
      directory name>) fails if the directory contains invalid unicode
      string. Backtrace:

      Well, I'm not sure we should call it the same problem, although the roots are
      the same. The difference is that in 2.x, using bytes strings for file and
      directory names is quite normal, especially under Linux where they are just
      bytes at the OS level. In 3.0 though, those strings are supposed to be unicode
      at the Python level, which makes the problem much more critical.

    6. Kentzo commented on Jul 18, 2015

      Kentzomannequin
      Mannequin

      This issue is marked as closed as a duplicate without a reference to the original task.

      I still have this issues on Python 3.4.2, on Windows when shutil.rmtree fails to

    7. changed the title [-]shutil.rmtree() fails on invalid filename[/-] [+]finalizer[/+] on Jul 18, 2015
    8. vstinner commented on Jul 18, 2015

      @vstinner
      MemberAuthor

      Hi, the issue was fixed in Python 3. On Windows, you must use Unicode.
      Otherwise, you can get errors like that. On other platforms, Unicode is now
      also the best choice on Python 3.

      See the second message for the superseder issue.

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions