New issue 2557: file.read(1) returns 2 bytes when inappropriate flag is given 
on opening binary file
https://bitbucket.org/pypy/pypy/issues/2557/fileread-1-returns-2-bytes-when

CHANGBEOM YUN:

I'm using CPython 2.7.13 and PyPy 5.7.1 on Windows 10 Professional (64bit).

When I tried to extract each byte to integer with Python script from a PDF 
file, I accidentally forgot to put 'rb' flag on opening. So, I put 'r' for 
reading binary file.

While CPython works without an exception (not sure outputs are correct), PyPy 
throws an exception saying ord() got string of length 2 instead of single 
character.

I attached scripts and binary file i used for testing. Thanks.

Versions:
```
#!plain
C:\Users\nidev\PyPyBugReproduce>pypy --version
Python 2.7.13 (14f400f0498e, Mar 31 2017, 19:58:36)
[PyPy 5.7.1 with MSC v.1500 32 bit]

C:\Users\nidev\PyPyBugReproduce>python --version
Python 2.7.13
```

Executing wrong one with PyPy and CPython:
```
#!text
C:\Users\nidev\PyPyBugReproduce>pypy wrong_byteencoder.py void.pdf > output.txt
Traceback (most recent call last):
  File "wrong_byteencoder.py", line 13, in <module>
    print(ord(c))
TypeError: ord() expected a character, but string of length 2 found

C:\Users\nidev\PyPyBugReproduce>python wrong_byteencoder.py void.pdf > 
output.txt
(exited cleanly)
```

Executing right one with PyPy and CPython:
```
#!text
C:\Users\nidev\PyPyBugReproduce>pypy right_byteencoder.py void.pdf > output.txt
(exited cleanly)
C:\Users\nidev\PyPyBugReproduce>python right_byteencoder.py void.pdf > 
output.txt
(exited cleanly)
```


_______________________________________________
pypy-issue mailing list
pypy-issue@python.org
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to