Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
fb651ae7
Commit
fb651ae7
authored
Jul 06, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Py3 fix: make sure byte strings end up in the code as expected (not like >>b'...'<<)
parent
11955ff6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
Cython/Compiler/StringEncoding.py
Cython/Compiler/StringEncoding.py
+8
-4
No files found.
Cython/Compiler/StringEncoding.py
View file @
fb651ae7
...
...
@@ -145,12 +145,16 @@ def escape_character(c):
return
c
def
escape_byte_string
(
s
):
"""Escape a byte string so that it can be written into C code.
Note that this returns a Unicode string instead which, when
encoded as ISO-8859-1, will result in the correct byte sequence
being written.
"""
if
_has_specials
(
s
):
for
special
,
replacement
in
_c_special_replacements
:
s
=
s
.
replace
(
special
,
replacement
)
try
:
s
.
decode
(
"ASCII"
)
# trial decoding: plain ASCII => done
return
s
return
s
.
decode
(
"ASCII"
)
# trial decoding: plain ASCII => done
except
UnicodeDecodeError
:
pass
if
sys
.
version_info
[
0
]
>=
3
:
...
...
@@ -161,7 +165,7 @@ def escape_byte_string(s):
extend
((
'
\
\
%3o'
%
b
).
encode
(
'ASCII'
))
else
:
append
(
b
)
return
bytes
(
s_new
)
return
s_new
.
decode
(
'ISO-8859-1'
)
else
:
l
=
[]
append
=
l
.
append
...
...
@@ -171,7 +175,7 @@ def escape_byte_string(s):
append
(
'
\
\
%3o'
%
o
)
else
:
append
(
c
)
return
join_bytes
(
l
)
return
join_bytes
(
l
)
.
decode
(
'ISO-8859-1'
)
def
split_docstring
(
s
):
if
len
(
s
)
<
2047
:
...
...
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