[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-08 Thread Peter
Peter added the comment: OK, thanks. Given this is regarded as an enhancement rather than a bug fix, I understand the choice not to change this in Python 2.7. -- ___ Python tracker

[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-07 Thread Martin Panter
Martin Panter added the comment: I agree this is not a bug. It is just one of the unfortunate compatibility breaks between Py 2 and 3. Mode="rt" is not one of the values that are supported according to the documentation; adding support would be a new feature. I understand the file mode

[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-07 Thread Peter
Peter added the comment: A workaround for my use case is even simpler, something like this: try: handle = gzip.open(filename, "rt") except ValueError: # Workaround for Python 2.7 under Windows handle = gzip.open(filename, "r") However, even this is troublesome for use in

[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-07 Thread Eryk Sun
Eryk Sun added the comment: You want to hack a fake text mode, which won't do new-line translation or treat ^Z (0x1a) as EOF like a normal 2.x text mode on Windows. Can't you just use io.TextIOWrapper(gzip.open(filename))? This reads Unicode. --

[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-07 Thread Peter
Peter added the comment: I want a simple cross platform (Linux/Mac/Windows) and cross version (Python 2/3) way to be able to open a gzipped file and get a string handle (default encoding TextIOWrapper under Python 3 is fine). My use-case is specifically for documentation examples. Previously

[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-07 Thread Eryk Sun
Eryk Sun added the comment: In Python 3, gzip.open(filename, "rt") returns a TextIOWrapper using the system's default encoding. The decoded output is potentially very different from the byte string returned by 'text mode' in Python 2, even if using "rt" mode didn't result in the nonsensical

[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-07 Thread R. David Murray
R. David Murray added the comment: I don't think this is really a bug, I think it's a consequence of the different byte/string models of python2 and python3 coupled with the different binary/text models of posix and windows. -- nosy: +r.david.murray

[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

2017-04-07 Thread Peter
New submission from Peter: Under Python 2, gzip.open defaults to giving (non-unicode) strings. Under Python 3, gzip.open defaults to giving bytes. Therefore it was fixed to allow text mode be specified, see http://bugs.python.org/issue13989 In order to write Python 2 and 3 compatible code to