Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc tarfile fixes #58220

Closed
merwok opened this issue Feb 14, 2012 · 13 comments
Closed

Misc tarfile fixes #58220

merwok opened this issue Feb 14, 2012 · 13 comments
Labels
pending The issue will be closed if no feedback is provided stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@merwok
Copy link
Member

merwok commented Feb 14, 2012

BPO 14012
Nosy @gustaebel, @merwok, @bitdancer, @serhiy-storchaka
Files
  • tarfile-misc-bugs-3.2.diff
  • tarfile-misc-bugs-3.2-2.diff
  • tarfile-misc-bugs-3.2-3.diff
  • tarfile-misc-bugs-3.4.diff
  • 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 = None
    created_at = <Date 2012-02-14.16:10:36.837>
    labels = ['type-bug', 'library']
    title = 'Misc tarfile fixes'
    updated_at = <Date 2014-10-10.01:28:10.710>
    user = 'https://github.com/merwok'

    bugs.python.org fields:

    activity = <Date 2014-10-10.01:28:10.710>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2012-02-14.16:10:36.837>
    creator = 'eric.araujo'
    dependencies = []
    files = ['24520', '24601', '24610', '31146']
    hgrepos = []
    issue_num = 14012
    keywords = ['patch']
    message_count = 11.0
    messages = ['153348', '153734', '153954', '154026', '181514', '186739', '186963', '194333', '195076', '195127', '228938']
    nosy_count = 4.0
    nosy_names = ['lars.gustaebel', 'eric.araujo', 'r.david.murray', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue14012'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @merwok
    Copy link
    Member Author

    merwok commented Feb 14, 2012

    I found a few possible bugs in tarfile:

    • “mode in 'raw'” can give false positives for '' or 'ra'. Most of the code also checks for “len(mode) > 1”, but I find clearer and safer to just use “mode in ('r', 'a', 'w')”.

    • To use the shadowed builtin “open”, tarfile uses both “import as” and a local alias “bltin_open = open”. However, the second idiom would break if tarfile were reloaded.

    • Error messages don’t say what the invalid mode was. (Error messages are not part of the language, but nonetheless maybe it’s best not to commit that to stable branches.)

    @merwok merwok added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 14, 2012
    @gustaebel gustaebel mannequin self-assigned this Feb 18, 2012
    @merwok
    Copy link
    Member Author

    merwok commented Feb 19, 2012

    Another one: now that shutil provides archiving operations, there is a circular dependency between tarfile and shutil. It does not cause problems*, as both modules use qualified names, but it may be a good thing to avoid import cascades for performance reasons. The single shutil function used by tarfile could be inlined, as I did in distutils2, or you may reject this idea.

    @gustaebel
    Copy link
    Mannequin

    gustaebel mannequin commented Feb 22, 2012

    I updated your patch:

    • I removed the "import as" bit completely and changed all occurrences of _open() to builtins.open() which is more readable and explanatory.

    • I object to changing the error messages in the 3.2 branch due to backwards compatibility, although I left them in the patch for now. (I changed the style of %-formatting with a single item tuple in order to match the coding style of the rest of the module.)

    • I inlined the shutil.copyfileobj() method to remove the shutil import.

    @merwok
    Copy link
    Member Author

    merwok commented Feb 23, 2012

    I removed the "import as" bit completely and changed all occurrences of _open() to
    builtins.open() which is more readable and explanatory.

    Truly. tokenize got a similar fix in ea260d393cde (without a test, so I think that here we don’t need one either); locale has a similar bug.

    I object to changing the error messages in the 3.2 branch due to backwards compatibility,
    although I left them in the patch for now.

    I removed these changes in the attached patch. I’ll make another patch for 3.3 for that.

    (I changed the style of %-formatting with a single item tuple in order to match the coding
    style of the rest of the module.)

    My reason was not style (I hate %-formatting with single-element tuples) but defensive coding, in case someone gives a tuple as argument. OTOH, that will just change the type of error they get for the same line, and the doc clearly says what is allowed, so it does not matter.

    I inlined the shutil.copyfileobj() method to remove the shutil import.

    Great, this will eliminate a circular dependency I had in a shutil refactoring (I need to access tarfile.compression_formats, but the tarfile module is not ready when shutil gets imported), and also reduce the diff with the tarfile backport we have in distutils2.

    Tell me if you want me to commit.

    @serhiy-storchaka
    Copy link
    Member

    The patch is desynchronized from current sources.

    @serhiy-storchaka
    Copy link
    Member

    Éric, can you please update your patch?

    @merwok
    Copy link
    Member Author

    merwok commented Apr 15, 2013

    I should be able to do that but can’t say when.

    @serhiy-storchaka
    Copy link
    Member

    Here is updated for 3.4 patch.

    @merwok
    Copy link
    Member Author

    merwok commented Aug 13, 2013

    Thanks, LGTM.

    @serhiy-storchaka
    Copy link
    Member

    Lets push it. Lars?

    @bitdancer
    Copy link
    Member

    The patch no longer applies again.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel
    Copy link
    Member

    The code has moved on since this patch was created. Can we close this?

    @iritkatriel iritkatriel added the pending The issue will be closed if no feedback is provided label Oct 28, 2023
    @merwok
    Copy link
    Member Author

    merwok commented Oct 29, 2023

    FTR the first item was fixed in ce644a0

    @merwok merwok closed this as completed Oct 29, 2023
    @merwok merwok closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    pending The issue will be closed if no feedback is provided stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    Status: Done
    Development

    No branches or pull requests

    4 participants