[issue5815] locale.getdefaultlocale() missing corner case
rg3 sarbalap+freshm...@gmail.com added the comment: I don't know if the behavior is considered a bug or just undocumented, but under Python 2.7.3 it's still the same. locale.getpreferredencoding() does return UTF-8, but the second element in the tuple locale.getdefaultlocale() is utf_8_valencia, which is not a valid encoding despite the documentation saying it's supposed to be an encoding name. From my terminal: $ python -V Python 2.7.3 $ LANG=ca_ES.UTF-8@valencia python -c 'import locale; print locale.getpreferredencoding()' UTF-8 $ LANG=ca_ES.UTF-8@valencia python -c 'import locale; print locale.getdefaultlocale()' ('ca_ES', 'utf_8_valencia') $ LANG=ca_ES.UTF-8 python -c 'import locale; print locale.getpreferredencoding()' UTF-8 $ LANG=ca_ES.UTF-8 python -c 'import locale; print locale.getdefaultlocale()' ('ca_ES', 'UTF-8') -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5815 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11199] urllib hangs when closing connection
rg3 sarbalap+freshm...@gmail.com added the comment: I have to correct myself. I applied the patch manually to my Python 2.6 installation. In Python 2.6, the line you moved is number 961, and I did the same change. OK. For information, you can apply it using the Unix patch command, who can most of the time do all the work for you. Yes, thanks, I already knew about patch but decided to apply the change manually just in case, as it belonged to a different Python branch. That's expected, it's a consequence of this point I raised earlier: Note that I'm not sure why we need to wait for a further message on the control channel (maybe it's part of an RFC or something...). There's no doubt that not hanging is an improvement, but the current behavior somewhat defeats the purpose of an early call to close. To get a broader view, the test case I provided is actually part of a much larger program. In that program, I read lines from the Slackware change log, stopping when I read a line that the program already knows about (because it caches the change log contents). This prevents the program from reading more than a single line if no new entries are present in the change log, but having to wait for the full file defeats the purpose, specially on slow dial-up connections. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11199 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11199] urllib hangs when closing connection
rg3 sarbalap+freshm...@gmail.com added the comment: Charles-Francois Natali, Tuesday, February 22, 2011 20:57: Attached are two new versions which don't wait for the end of transfer. I tested the one for Python 2.7 applied to Python 2.6 and it appears to work perfectly. Thanks for the quick fix! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11199 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11199] urllib hangs when closing connection
rg3 sarbalap+freshm...@gmail.com added the comment: That makes sense and explains why the problem could not be reproduced over the loopback (the transfer would be too fast). I have not tested the patch, but I can reproduce the problem with a local connection if I compile pure-ftpd with the --with-throttling switch and limit the bandwidth to 1 KB/sec, using the -t option. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11199 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11199] urllib hangs when closing connection
rg3 sarbalap+freshm...@gmail.com added the comment: I just tested the patch under Python 2.6. It doesn't seem to solve the problem. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11199 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11199] urllib hangs when closing connection
rg3 sarbalap+freshm...@gmail.com added the comment: I have to correct myself. I applied the patch manually to my Python 2.6 installation. In Python 2.6, the line you moved is number 961, and I did the same change. With your change, the connection can be closed, but you have to wait for the file to be completely transferred. As I was throttling to 1 KB/sec initially, I thought it was still hanging because it takes more than 1 minute for the test file to be sent. Still, the connection isn't immediately closed when you request to close it. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11199 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11199] urllib hangs when closing connection
New submission from rg3 sarbalap+freshm...@gmail.com: If you run the attached program, you can see the program hangs in the connection close stage. Uncommenting the sleep line makes the program work, so I suspect some kind of race condition. The URL used belongs to a Slackware Linux mirror. I have not been able to reproduce this problem when using a different FTP mirror or using HTTP mirrors. The remote server seems to be using pure-ftpd. I have built the software and tested on localhost, but I could not reproduce the problem either. -- components: Extension Modules files: test.py messages: 128444 nosy: rg3 priority: normal severity: normal status: open title: urllib hangs when closing connection type: behavior versions: Python 2.6 Added file: http://bugs.python.org/file20750/test.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11199 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5815] locale.getdefaultlocale() missing corner case
New submission from rg3 sarbalap+freshm...@gmail.com: A recent issue with one of my programs has shown that locale.getdefaultlocale() does not handle correctly a corner case. The issue URL is this one: http://bitbucket.org/rg3/youtube-dl/issue/7/ Essentially, some users have LANG set to something like es_ca.ut...@valencia. In that case, locale.getdefaultlocale() returns, as the encoding, the string utf_8_valencia, which cannot be used as an argument to the string encode() function. The obvious correct encoding in this case is UTF-8. I have traced the problem and it seems that it could be fixed by the attached patch. It checks if the encoding, at that point, contains the '@' symbol and, in that case, removes everything starting at that point, leaving only UTF-8. I am not sure if this patch or a similar one should be applied to other Python versions. My system has Python 2.5.2 and that's what I have patched. Explanation as to why I put the code there: * The simple case, es_CA.UTF-8 goes through that point too and enters the if. * I wanted to remove what goes after the '@' symbol at that point, so it either needed to be removed before the call to the normalizing function or inside the normalization. * As this is not what I would consider a normalization, I put the code before the function call. Thanks for your hard work. I hope my patch is valid. Regards. -- components: Library (Lib) files: locale.diff keywords: patch messages: 86312 nosy: rg3 severity: normal status: open title: locale.getdefaultlocale() missing corner case type: behavior versions: Python 2.5 Added file: http://bugs.python.org/file13737/locale.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5815 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5815] locale.getdefaultlocale() missing corner case
rg3 sarbalap+freshm...@gmail.com added the comment: I just realized that the if I introduced is not really needed. encoding = encoding.split('@')[0] works whether the '@' symbol is present or not. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5815 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5815] locale.getdefaultlocale() missing corner case
rg3 sarbalap+freshm...@gmail.com added the comment: You are right. The issue is not reproduced with es_ca.ut...@valencia but with ca_es.ut...@valencia. The fact that the first case works makes me think maybe there's another way to solve the problem. Can you check that? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5815 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5815] locale.getdefaultlocale() missing corner case
rg3 sarbalap+freshm...@gmail.com added the comment: Further investigation: The guy who had this issue may be from Valencia, Spain. According to the manpage for setlocale(3) in my system, the form is usually language[_territory][.codese...@modifier]. So, in this case, it would make sense for the language to be ca (Catalan) and territory ES (Spain). My patch may be fine after all. Because, if at that point the @modifier is still present (I have seen code that removes it before that point), you'd still want to remove it and keep only the codeset, which is the interesting part. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5815 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5815] locale.getdefaultlocale() missing corner case
rg3 sarbalap+freshm...@gmail.com added the comment: Excellent. Thanks for the tip. I'll now proceed to modify my code to use getpreferredencoding. Still, I think getdefaultlocale should work because it could be used in other situations, I suppose. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5815 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com