Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: eryk sun Newsgroups: comp.lang.python Subject: Re: cannot open file with non-ASCII filename Date: Mon, 14 Dec 2015 21:20:18 -0600 Lines: 50 Message-ID: References: <566F0BD0.8020106@udel.edu> <4412672.gUIyRlH8Kf@PointedEars.de> <201512150007.tBF07nMo021611@fido.openend.se> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de dRvFFLIT3ot+roFBOIvkqwfvb3SUVuv4RqDeTJXNeMjw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url:sourceforge': 0.03; 'received:209.85.223': 0.03; 'testing,': 0.05; 'mask': 0.07; 'mouse': 0.07; 'subject:file': 0.07; 'url:msdn': 0.07; '[1]:': 0.09; '[2]:': 0.09; '[3]:': 0.09; 'closest': 0.09; 'creighton': 0.09; 'input,': 0.09; 'output,': 0.09; 'url:github': 0.09; 'bug': 0.10; 'python': 0.10; '2.7': 0.13; 'instead.': 0.15; '[1].': 0.16; 'api,': 0.16; 'bitwise': 0.16; 'curses': 0.16; 'instead:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:non': 0.16; 'wrote:': 0.16; 'byte': 0.18; 'frameworks': 0.18; 'laura': 0.18; 'creates': 0.18; 'gui': 0.18; 'input': 0.18; 'windows': 0.20; '2015': 0.20; 'extension': 0.20; '(the': 0.22; 'keyboard': 0.22; 'platform,': 0.22; 'dec': 0.23; 'matching': 0.23; 'url:edu': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'module': 0.25; 'skip:" 20': 0.26; 'message-id:@mail.gmail.com': 0.27; '14,': 0.27; '[2]': 0.27; 'module.': 0.27; 'said,': 0.27; 'function': 0.28; "skip:' 10": 0.28; 'character': 0.29; 'random': 0.29; 'code': 0.30; 'skip:[ 10': 0.31; "i'd": 0.31; 'skip:_ 10': 0.32; 'url:python': 0.33; 'builds': 0.33; 'file': 0.34; 'worked': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'maps': 0.35; 'unicode': 0.35; 'should': 0.36; 'instead': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'url:library': 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'version': 0.38; 'received:209': 0.38; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'url:3': 0.60; 'high': 0.60; 'skip:u 10': 0.61; 'avoid': 0.61; 'linked': 0.63; 'url:%20': 0.63; 'news': 0.68; 'url:en-us': 0.72; '8bit%:92': 0.72; 'url:htm': 0.75; 'hitch': 0.84; 'latin': 0.84; 'toolkit.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=whVSCd8Wr6/NcbI+6+Qx9XC/iKDk1MEU43GyXmmKEyQ=; b=glxo+vLaSdQRXlbR7yyAz3mW+eLqAp/8xOiyb3y6mqxsf2dJJoWN/7+naVEw+/HYk2 lTDfzi1oOP6sehoCNSc74pGOLTG5jlUQv5VhCslx0UsTB2jfDaTXJHA+w5kmiNOM+g2M hyHl7Ng5fZVRebOLxm7H9tGWOKii3cP3+kiCKBU8CEO/I523SKxWoJTm8Y3ech7ZzXDK vo7+S9Bm70MamOMjVOX3or3qVZsg48kkMxHviKpzpyHgs0yEV7B/uYSHCV6MfHB+fJ3E JNWjVXN39YJwmf+NjViDZCWddaIbTn9+XiiffPBQC5GleKZHEKLXwvc1JxlJ7C6qtg3O giag== X-Received: by 10.107.137.226 with SMTP id t95mr32377987ioi.188.1450149658524; Mon, 14 Dec 2015 19:20:58 -0800 (PST) In-Reply-To: <201512150007.tBF07nMo021611@fido.openend.se> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100446 On Mon, Dec 14, 2015 at 6:07 PM, Laura Creighton wrote: > In a message of Mon, 14 Dec 2015 23:41:21 +0100, "Thomas 'PointedEars' La= hn" wr > ites: > >>Why do you have to use msvcrt? >> >>I would use curses for user input, but: >> >>,- >>,- >>| >>| No one has made a Windows port of the curses module. On a Windows >>| platform, try the Console module written by Fredrik Lundh. The Console >>| module provides cursor-addressable text output, plus full support for >>| mouse and keyboard input, and is available from >>| http://effbot.org/zone/console-index.htm. >> >>So you should try that instead. > > If going for curses, I'd try this instead: > http://pdcurses.sourceforge.net/ Christoph Gohlke has an extension module based on PDCurses [1]. The good news for Python 3 users is that it uses the [W]ide-character console API, such as ReadConsoleInputW. Also, its _get_key_count [2] function is designed to support the alt numpad event sequences that the system creates for the input filepath when dragging a file into the console. In my limited testing, dragging filepaths from Explorer worked without a hitch using a random Latin-1 name "=C2=A8=C2=B0=C2=B8=C3= =80=C3=88=C3=90=C3=98=C3=A0=C3=A8=C3=B0=C3=B8" and a Latin Extended-B name "=C6=A0=C6=A8=C6=B0=C6=B8=C7=80=C7=88=C7=90=C7=98=C7= =A0=C7=A8=C7=B0=C7=B8". Unfortunately the Python 2.7 version is linked against the [A]NSI API, which maps each Unicode character to either the closest matching character in the console's codepage or "?". Moreover the PDCurses code has a bug in narrow builds in that it returns the UnicodeChar from the KEY_EVENT_RECORD [3] instead of the AsciiChar (the name is a misnomer). In this case the high byte is junk. You can mask it out using a bitwise & with 0xFF. That said, IIRC, the OP wants to avoid using any frameworks such as curses or a GUI toolkit. [1]: http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses [2]: https://github.com/wmcbrine/PDCurses/blob/PDCurses_3_4/win32/pdckbd.c#= L259 [3]: https://msdn.microsoft.com/en-us/library/ms684166