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
6ffbee77
Commit
6ffbee77
authored
Oct 17, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libpython: implementation of os.fsencode() with surrogateescape error handler
parent
e0f32687
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
Tools/gdb/libpython.py
Tools/gdb/libpython.py
+20
-2
No files found.
Tools/gdb/libpython.py
View file @
6ffbee77
...
@@ -96,6 +96,23 @@ def write_unicode(file, text):
...
@@ -96,6 +96,23 @@ def write_unicode(file, text):
text
=
text
.
encode
(
ENCODING
,
'backslashreplace'
)
text
=
text
.
encode
(
ENCODING
,
'backslashreplace'
)
file
.
write
(
text
)
file
.
write
(
text
)
def
os_fsencode
(
filename
):
if
not
isinstance
(
filename
,
unicode
):
return
filename
encoding
=
sys
.
getfilesystemencoding
()
if
encoding
==
'mbcs'
:
# mbcs doesn't support surrogateescape
return
filename
.
encode
(
encoding
)
encoded
=
[]
for
char
in
filename
:
# surrogateescape error handler
if
0xDC80
<=
ord
(
char
)
<=
0xDCFF
:
byte
=
chr
(
ord
(
char
)
-
0xDC00
)
else
:
byte
=
char
.
encode
(
encoding
)
encoded
.
append
(
byte
)
return
''
.
join
(
encoded
)
class
StringTruncated
(
RuntimeError
):
class
StringTruncated
(
RuntimeError
):
pass
pass
...
@@ -887,7 +904,8 @@ class PyFrameObjectPtr(PyObjectPtr):
...
@@ -887,7 +904,8 @@ class PyFrameObjectPtr(PyObjectPtr):
newline character'''
newline character'''
if
self
.
is_optimized_out
():
if
self
.
is_optimized_out
():
return
'(frame information optimized out)'
return
'(frame information optimized out)'
with
open
(
self
.
filename
(),
'r'
)
as
f
:
filename
=
self
.
filename
()
with
open
(
os_fsencode
(
filename
),
'r'
)
as
f
:
all_lines
=
f
.
readlines
()
all_lines
=
f
.
readlines
()
# Convert from 1-based current_line_num to 0-based list offset:
# Convert from 1-based current_line_num to 0-based list offset:
return
all_lines
[
self
.
current_line_num
()
-
1
]
return
all_lines
[
self
.
current_line_num
()
-
1
]
...
@@ -1463,7 +1481,7 @@ class PyList(gdb.Command):
...
@@ -1463,7 +1481,7 @@ class PyList(gdb.Command):
if start<1:
if start<1:
start = 1
start = 1
with open(
filename
, 'r') as f:
with open(
os_fsencode(filename)
, 'r') as f:
all_lines = f.readlines()
all_lines = f.readlines()
# start and end are 1-based, all_lines is 0-based;
# start and end are 1-based, all_lines is 0-based;
# so [start-1:end] as a python slice gives us [start, end] as a
# so [start-1:end] as a python slice gives us [start, end] as a
...
...
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