Skip to content

Wrong encoding in files saved from IDLE (3.0rc2 on Windows) #48573

Closed

Description

@andre
mannequin
BPO 4323
Nosy @loewis, @amauryfa, @vstinner
Files
  • idle_dialog.png
  • idle_remove_coding_dialog.py
  • idle_coding_dialog_cancel.patch
  • remove_coding_option.py
  • 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-12-29.18:47:20.646>
    created_at = <Date 2008-11-14.11:03:13.728>
    labels = ['type-bug']
    title = 'Wrong encoding in files saved from IDLE (3.0rc2 on Windows)'
    updated_at = <Date 2008-12-29.18:47:20.644>
    user = 'https://bugs.python.org/andre'

    bugs.python.org fields:

    activity = <Date 2008-12-29.18:47:20.644>
    actor = 'loewis'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-12-29.18:47:20.646>
    closer = 'loewis'
    components = []
    creation = <Date 2008-11-14.11:03:13.728>
    creator = 'andre'
    dependencies = []
    files = ['12003', '12004', '12005', '12060']
    hgrepos = []
    issue_num = 4323
    keywords = ['patch']
    message_count = 8.0
    messages = ['75855', '75856', '75857', '75858', '75869', '76057', '76215', '78474']
    nosy_count = 4.0
    nosy_names = ['loewis', 'amaury.forgeotdarc', 'vstinner', 'andre']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4323'
    versions = ['Python 3.0']

    Activity

    1. andre commented on Nov 14, 2008

      andremannequin
      MannequinAuthor

      When saving a source file with non-ascii characters from an IDLE window,
      on Windows platform (XP and Server 2003 at least)
      with locale English US

        locale.getdefaultlocale()
        ('en_US', 'cp1252')

      IDLE prompts in IOBinding.py with the message
      "non Ascii found, yet no encoding declared, Add a line like # --
      coding: cp1252 -
      -"

      If accepted, the file is saved with the wrong encoding.
      Afterwards, it is read back by IDLE without any problem and it looks
      good in the IDLE window.

      However, if a string with non-ascii characters is sent to another
      module (i.e. email MIMEText)
      the string is wrong.

      The same source would be rejected by python in terminal mode and by
      IDLE on Linux.

    2. added
      type-bugAn unexpected behavior, bug, or error
      on Nov 14, 2008
    3. vstinner commented on Nov 14, 2008

      @vstinner
      Member

      If accepted, the file is saved with the wrong encoding

      "accept" means click on the "OK" button. You have to click on the
      biggest button "Edit my file" to create a valid file.

      The problem here is the text in the dialog but also the possibility to
      create an invalid file.

      Two solutions:

      • don't ask user for a confirmation (always insert the header)
      • replace "OK" button by "Cancel" button: the user wants maybe an
        ASCII only file but inserted by error an unicode character (eg. non
        breaking space!)
    4. vstinner commented on Nov 14, 2008

      @vstinner
      Member

      Quick but ugly solution: force the #coding: header without asking the
      user for that.

    5. vstinner commented on Nov 14, 2008

      @vstinner
      Member

      Implementation of the second solution: replace Ok button by a Cancel
      button. Escape key is Cancel, whereas Return key is the default
      action: edit the file.

    6. loewis commented on Nov 14, 2008

      loewismannequin
      Mannequin

      The entire dialog should go away. The default source encoding is UTF-8
      in Python 3.0, and IDLE should know that. The locale's encoding
      shouldn't ever be considered.

    7. loewis commented on Nov 19, 2008

      loewismannequin
      Mannequin

      Here is a patch that removes the entire IDLE coding option machinery,
      thus implementing PEP-3120.

    8. amauryfa commented on Nov 21, 2008

      @amauryfa
      Contributor

      The patch is good and does simplify things: the py3k conversion to
      unicode may have some advantages sometimes!

      I suggest to also remove the remaining two occurrences of
      "frameEncoding" in configDialog.py. This will suppress the extra space
      between the last two blocks of the dialog.

    9. loewis commented on Dec 29, 2008

      loewismannequin
      Mannequin

      Thanks for the review. Committed (with the proposed change) as r68022
      and r68023.

    10. 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

      type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions