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

Unicode fix for test in tkFileDialog.py #36382

Closed
ber mannequin opened this issue Apr 4, 2002 · 4 comments
Closed

Unicode fix for test in tkFileDialog.py #36382

ber mannequin opened this issue Apr 4, 2002 · 4 comments
Assignees

Comments

@ber
Copy link
Mannequin

ber mannequin commented Apr 4, 2002

BPO 539392
Nosy @loewis
Files
  • python_cvs20020404_tkFileDialog_umlaut.patch: Patch for python cvs 20020404
  • 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 = 'https://github.com/loewis'
    closed_at = <Date 2002-04-08.15:00:56.000>
    created_at = <Date 2002-04-04.18:59:22.000>
    labels = ['expert-tkinter']
    title = 'Unicode fix for test in tkFileDialog.py'
    updated_at = <Date 2002-04-08.15:00:56.000>
    user = 'https://bugs.python.org/ber'

    bugs.python.org fields:

    activity = <Date 2002-04-08.15:00:56.000>
    actor = 'loewis'
    assignee = 'loewis'
    closed = True
    closed_date = None
    closer = None
    components = ['Tkinter']
    creation = <Date 2002-04-04.18:59:22.000>
    creator = 'ber'
    dependencies = []
    files = ['4111']
    hgrepos = []
    issue_num = 539392
    keywords = ['patch']
    message_count = 4.0
    messages = ['39464', '39465', '39466', '39467']
    nosy_count = 2.0
    nosy_names = ['loewis', 'ber']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue539392'
    versions = []

    @ber
    Copy link
    Mannequin Author

    ber mannequin commented Apr 4, 2002

    Patch is against current CVS form 20020404.
    It also gives pointers to the problem described
    in
    http://mail.python.org/pipermail/python-list/2001-June/048787.html

    Python's open() uses the Py_FileSystemDefaultEncoding.
    Py_FileSystemDefaultEncoding is NULL (bltinmodule.c)
    for most systems.
    Setlocate will set it. Thus we fixed the example and
    set the locale to
    the user defaults. Now "enc" will have a useful
    encoding thus the
    example will work with a non ascii characters in the
    filename,
    e.g. with umlauts in it. It bombed on them before.

            Traceback (most recent call last):
      File "tkFileDialog.py", line 105, in ?
        print "open", askopenfilename(filetypes=[("all
    filez", "*")])
      UnicodeError: ASCII encoding error: ordinal not in
    range(128)

    open() will work with the string directly now.
    encode(enc) is only needed for terminal output,
    thus we enchanced the example to show the two uses of
    the returned filename
    string separatly.

    (It might be interesting to drop a note about this in
    the right part of the user documentation.)

    If you comment out the setlocale() you can see that
    open fails,
    which illustrates what seems to be a design flaw in tk.
    Tk should be able to give you a string in exactly
    the encoding in which the filesystem gave it to tk.

    4.4.2002
    Bernhard <bernhard@intevation.de>
    Bernhard <bh@intevation.de>

    @ber ber mannequin closed this as completed Apr 4, 2002
    @ber ber mannequin assigned loewis Apr 4, 2002
    @ber ber mannequin added the topic-tkinter label Apr 4, 2002
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Apr 4, 2002

    Logged In: YES
    user_id=21627

    I think this patch is not acceptable. If the application
    wants to support non-ASCII file names, it must invoke
    setlocale(); it is not the library's responsibility to make
    this decision behind the application's back.

    People question the validity of using CODESET in the file
    system, so each developer needs to make a concious decision.
    BTW, how does Tcl come up with the names in the first place?

    @ber
    Copy link
    Mannequin Author

    ber mannequin commented Apr 7, 2002

    Logged In: YES
    user_id=113859

    I agree with your analysis that the appplication has
    to set the locale, if it wants to support non-ASCII filenames.

    This is why we fixed the _test_ code to demonstrate exactly
    this. The code of the modules itself is untouched.
    If you do not fix the _test_ code it will bomb on non-ascii
    file names.

    Our code also demonstrates that there might be a difference
    in the file system encoding (suitable for open) and the
    terminal encoding (suitable for printing).

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Apr 8, 2002

    Logged In: YES
    user_id=21627

    Sorry, I misinterpreted your patch first.

    I agree with your distinction of a file system encoding, and
    a terminal encoding; I still hope to enhance Python to
    expose an estimate of both - then leaving it to the
    application to make use of either as appropriate (the file
    system encoding would be used implicitly as is done today).

    As for the flaw in Tk: it turns out that Tcl has a different
    notion of the default encoding than Python - Tcl always uses
    a locale-aware default encoding, whereas Python has a
    system-wide fixed default encoding (usually ASCII).

    It is a good thing that Tkinter manages to represent file
    names correctly (i.e. as Unicode strings) in most cases - if
    you want to get the file name in the encoding in which the
    file system gave it to you, you need to establish the value
    of Tcl's "encoding system" command.

    Committed as tkFileDialog.py 1.7.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants