Skip to content

Commit 1c47b63

Browse files
committed
Fix some misc issues in _io/_codecs
1 parent 8a85fee commit 1c47b63

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

vm/Lib/python_builtins/_codecs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,11 +1528,11 @@ def charmapencode_output(c, mapping):
15281528
rep = mapping[c]
15291529
if isinstance(rep, int) or isinstance(rep, int):
15301530
if rep < 256:
1531-
return chr(rep)
1531+
return rep
15321532
else:
15331533
raise TypeError("character mapping must be in range(256)")
15341534
elif isinstance(rep, str):
1535-
return rep
1535+
return ord(rep)
15361536
elif rep == None:
15371537
raise KeyError("character maps to <undefined>")
15381538
else:
@@ -1582,7 +1582,7 @@ def PyUnicode_DecodeCharmap(s, size, mapping, errors):
15821582
#/* Get mapping (char ordinal -> integer, Unicode char or None) */
15831583
ch = s[inpos]
15841584
try:
1585-
x = mapping[ord(ch)]
1585+
x = mapping[ch]
15861586
if isinstance(x, int):
15871587
if x < 65536:
15881588
p += chr(x)

vm/Lib/python_builtins/_io.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,19 +1507,24 @@ def __init__(self, file, mode='r', closefd=True, opener=None):
15071507
os.set_inheritable(fd, False)
15081508

15091509
self._closefd = closefd
1510-
fdfstat = os.fstat(fd)
15111510
try:
1512-
if stat.S_ISDIR(fdfstat.st_mode):
1513-
raise IsADirectoryError(errno.EISDIR,
1514-
os.strerror(errno.EISDIR), file)
1515-
except AttributeError:
1516-
# Ignore the AttribueError if stat.S_ISDIR or errno.EISDIR
1517-
# don't exist.
1518-
pass
1519-
self._blksize = getattr(fdfstat, 'st_blksize', 0)
1520-
if self._blksize <= 1:
1521-
self._blksize = DEFAULT_BUFFER_SIZE
1511+
fdfstat = os.fstat(fd)
1512+
except OSError:
1513+
fdfstat = None
1514+
else:
1515+
try:
1516+
if stat.S_ISDIR(fdfstat.st_mode):
1517+
raise IsADirectoryError(errno.EISDIR,
1518+
os.strerror(errno.EISDIR), file)
1519+
except AttributeError:
1520+
# Ignore the AttribueError if stat.S_ISDIR or errno.EISDIR
1521+
# don't exist.
1522+
pass
1523+
self._blksize = getattr(fdfstat, 'st_blksize', 0)
1524+
if self._blksize <= 1:
1525+
self._blksize = DEFAULT_BUFFER_SIZE
15221526

1527+
# XXX RustPython TODO: fix _setmode here
15231528
if _setmode and False:
15241529
# don't translate newlines (\r\n <=> \n)
15251530
_setmode(fd, os.O_BINARY)

0 commit comments

Comments
 (0)