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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
b549b785
Commit
b549b785
authored
Aug 21, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Py2 bytes handling fix
parent
b8419151
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
Cython/Compiler/StringEncoding.py
Cython/Compiler/StringEncoding.py
+10
-3
No files found.
Cython/Compiler/StringEncoding.py
View file @
b549b785
...
@@ -7,8 +7,10 @@ import sys
...
@@ -7,8 +7,10 @@ import sys
if
sys
.
version_info
[
0
]
>=
3
:
if
sys
.
version_info
[
0
]
>=
3
:
_str
,
_bytes
=
str
,
bytes
_str
,
_bytes
=
str
,
bytes
IS_PYTHON3
=
True
else
:
else
:
_str
,
_bytes
=
unicode
,
str
_str
,
_bytes
=
unicode
,
str
IS_PYTHON3
=
False
empty_bytes
=
_bytes
()
empty_bytes
=
_bytes
()
empty_str
=
_str
()
empty_str
=
_str
()
...
@@ -84,7 +86,11 @@ class BytesLiteral(_bytes):
...
@@ -84,7 +86,11 @@ class BytesLiteral(_bytes):
encoding
=
None
encoding
=
None
def
byteencode
(
self
):
def
byteencode
(
self
):
return
_bytes
(
self
)
if
IS_PYTHON3
:
return
_bytes
(
self
)
else
:
# fake-recode the string to make it a plain bytes object
return
self
.
decode
(
'ISO-8859-1'
).
encode
(
'ISO-8859-1'
)
def
utf8encode
(
self
):
def
utf8encode
(
self
):
assert
False
,
"this is not a unicode string: %r"
%
self
assert
False
,
"this is not a unicode string: %r"
%
self
...
@@ -133,7 +139,8 @@ def _build_specials_test():
...
@@ -133,7 +139,8 @@ def _build_specials_test():
_has_specials
=
_build_specials_test
()
_has_specials
=
_build_specials_test
()
def
escape_char
(
c
):
def
escape_char
(
c
):
c
=
c
.
decode
(
'ISO-8859-1'
)
if
IS_PYTHON3
:
c
=
c
.
decode
(
'ISO-8859-1'
)
if
c
in
'
\
n
\
r
\
t
\
\
'
:
if
c
in
'
\
n
\
r
\
t
\
\
'
:
return
repr
(
c
)[
1
:
-
1
]
return
repr
(
c
)[
1
:
-
1
]
elif
c
==
"'"
:
elif
c
==
"'"
:
...
@@ -158,7 +165,7 @@ def escape_byte_string(s):
...
@@ -158,7 +165,7 @@ def escape_byte_string(s):
return
s
.
decode
(
"ASCII"
)
# trial decoding: plain ASCII => done
return
s
.
decode
(
"ASCII"
)
# trial decoding: plain ASCII => done
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
pass
pass
if
sys
.
version_info
[
0
]
>=
3
:
if
IS_PYTHON
3
:
s_new
=
bytearray
()
s_new
=
bytearray
()
append
,
extend
=
s_new
.
append
,
s_new
.
extend
append
,
extend
=
s_new
.
append
,
s_new
.
extend
for
b
in
s
:
for
b
in
s
:
...
...
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