Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9c17ff91
Commit
9c17ff91
authored
Feb 28, 2014
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Plain Diff
Merge heads
parents
f808df39
78f1e4c8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
2 deletions
+30
-2
.hgeol
.hgeol
+2
-0
Lib/test/coding20731.py
Lib/test/coding20731.py
+4
-0
Lib/test/test_source_encoding.py
Lib/test/test_source_encoding.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
Parser/tokenizer.c
Parser/tokenizer.c
+12
-2
No files found.
.hgeol
View file @
9c17ff91
...
...
@@ -38,6 +38,8 @@ Lib/test/xmltestdata/* = BIN
Lib/venv/scripts/nt/* = BIN
Lib/test/coding20731.py = BIN
# All other files (which presumably are human-editable) are "native".
# This must be the last rule!
...
...
Lib/test/coding20731.py
0 → 100644
View file @
9c17ff91
#coding:latin1
Lib/test/test_source_encoding.py
View file @
9c17ff91
...
...
@@ -5,6 +5,7 @@ from test.support import TESTFN, unlink, unload
import
importlib
import
os
import
sys
import
subprocess
class
SourceEncodingTest
(
unittest
.
TestCase
):
...
...
@@ -58,6 +59,14 @@ class SourceEncodingTest(unittest.TestCase):
# two bytes in common with the UTF-8 BOM
self
.
assertRaises
(
SyntaxError
,
eval
,
b'
\
xef
\
xbb
\
x20
'
)
def
test_20731
(
self
):
sub
=
subprocess
.
Popen
([
sys
.
executable
,
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'coding20731.py'
)],
stderr
=
subprocess
.
PIPE
)
err
=
sub
.
communicate
()[
1
]
self
.
assertEquals
(
err
,
b''
)
def
test_error_message
(
self
):
compile
(
b'# -*- coding: iso-8859-15 -*-
\
n
'
,
'dummy'
,
'exec'
)
compile
(
b'
\
xef
\
xbb
\
xbf
\
n
'
,
'dummy'
,
'exec'
)
...
...
Misc/NEWS
View file @
9c17ff91
...
...
@@ -8,6 +8,9 @@ What's New in Python 3.4.1?
Core and Builtins
-----------------
- Issue #20731: Properly position in source code files even if they
are opened in text mode. Patch by Serhiy Storchaka.
- Issue #20637: Key-sharing now also works for instance dictionaries of
subclasses. Patch by Peter Ingebretson.
...
...
Parser/tokenizer.c
View file @
9c17ff91
...
...
@@ -498,9 +498,13 @@ fp_setreadl(struct tok_state *tok, const char* enc)
fd
=
fileno
(
tok
->
fp
);
/* Due to buffering the file offset for fd can be different from the file
* position of tok->fp. */
* position of tok->fp. If tok->fp was opened in text mode on Windows,
* its file position counts CRLF as one char and can't be directly mapped
* to the file offset for fd. Instead we step back one byte and read to
* the end of line.*/
pos
=
ftell
(
tok
->
fp
);
if
(
pos
==
-
1
||
lseek
(
fd
,
(
off_t
)
pos
,
SEEK_SET
)
==
(
off_t
)
-
1
)
{
if
(
pos
==
-
1
||
lseek
(
fd
,
(
off_t
)(
pos
>
0
?
pos
-
1
:
pos
),
SEEK_SET
)
==
(
off_t
)
-
1
)
{
PyErr_SetFromErrnoWithFilename
(
PyExc_OSError
,
NULL
);
goto
cleanup
;
}
...
...
@@ -513,6 +517,12 @@ fp_setreadl(struct tok_state *tok, const char* enc)
Py_XDECREF
(
tok
->
decoding_readline
);
readline
=
_PyObject_GetAttrId
(
stream
,
&
PyId_readline
);
tok
->
decoding_readline
=
readline
;
if
(
pos
>
0
)
{
if
(
PyObject_CallObject
(
readline
,
NULL
)
==
NULL
)
{
readline
=
NULL
;
goto
cleanup
;
}
}
cleanup:
Py_XDECREF
(
stream
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment