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
825a2cd3
Commit
825a2cd3
authored
May 15, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
byte encode docstrings correctly
parent
39f134d3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
20 deletions
+26
-20
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+3
-19
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+6
-1
Cython/Utils.py
Cython/Utils.py
+17
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
825a2cd3
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
# Pyrex - Types
# Pyrex - Types
#
#
from
Cython
import
Utils
import
Naming
import
Naming
class
BaseType
:
class
BaseType
:
...
@@ -922,23 +923,6 @@ class CEnumType(CType):
...
@@ -922,23 +923,6 @@ class CEnumType(CType):
return
self
.
base_declaration_code
(
public_decl
(
base
,
dll_linkage
),
entity_code
)
return
self
.
base_declaration_code
(
public_decl
(
base
,
dll_linkage
),
entity_code
)
def
_escape_byte_string
(
s
):
s
=
s
.
replace
(
'
\
0
'
,
r'\x00'
)
try
:
s
.
decode
(
"ASCII"
)
return
s
except
UnicodeDecodeError
:
pass
l
=
[]
append
=
l
.
append
for
c
in
s
:
o
=
ord
(
c
)
if
o
>=
128
:
append
(
'
\
\
x%X'
%
o
)
else
:
append
(
c
)
return
''
.
join
(
l
)
class
CStringType
:
class
CStringType
:
# Mixin class for C string types.
# Mixin class for C string types.
...
@@ -951,7 +935,7 @@ class CStringType:
...
@@ -951,7 +935,7 @@ class CStringType:
def
literal_code
(
self
,
value
):
def
literal_code
(
self
,
value
):
assert
isinstance
(
value
,
str
)
assert
isinstance
(
value
,
str
)
return
'"%s"'
%
_
escape_byte_string
(
value
)
return
'"%s"'
%
Utils
.
escape_byte_string
(
value
)
class
CUTF8StringType
:
class
CUTF8StringType
:
...
@@ -965,7 +949,7 @@ class CUTF8StringType:
...
@@ -965,7 +949,7 @@ class CUTF8StringType:
def
literal_code
(
self
,
value
):
def
literal_code
(
self
,
value
):
assert
isinstance
(
value
,
str
)
assert
isinstance
(
value
,
str
)
return
'"%s"'
%
_
escape_byte_string
(
value
)
return
'"%s"'
%
Utils
.
escape_byte_string
(
value
)
class
CCharArrayType
(
CStringType
,
CArrayType
):
class
CCharArrayType
(
CStringType
,
CArrayType
):
...
...
Cython/Compiler/TypeSlots.py
View file @
825a2cd3
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
# and associated know-how.
# and associated know-how.
#
#
from
Cython
import
Utils
import
Naming
import
Naming
import
PyrexTypes
import
PyrexTypes
import
sys
import
sys
...
@@ -298,7 +299,11 @@ class DocStringSlot(SlotDescriptor):
...
@@ -298,7 +299,11 @@ class DocStringSlot(SlotDescriptor):
def
slot_code
(
self
,
scope
):
def
slot_code
(
self
,
scope
):
if
scope
.
doc
is
not
None
:
if
scope
.
doc
is
not
None
:
return
'"%s"'
%
scope
.
doc
if
scope
.
doc
.
is_unicode
:
doc
=
scope
.
doc
.
utf8encode
()
else
:
doc
=
scope
.
doc
.
byteencode
()
return
'"%s"'
%
Utils
.
escape_byte_string
(
doc
)
else
:
else
:
return
"0"
return
"0"
...
...
Cython/Utils.py
View file @
825a2cd3
...
@@ -91,3 +91,20 @@ class EncodedString(unicode):
...
@@ -91,3 +91,20 @@ class EncodedString(unicode):
# def __eq__(self, other):
# def __eq__(self, other):
# return unicode.__eq__(self, other) and \
# return unicode.__eq__(self, other) and \
# getattr(other, 'encoding', '') == self.encoding
# getattr(other, 'encoding', '') == self.encoding
def
escape_byte_string
(
s
):
s
=
s
.
replace
(
'
\
0
'
,
r'\x00'
)
try
:
s
.
decode
(
"ASCII"
)
return
s
except
UnicodeDecodeError
:
pass
l
=
[]
append
=
l
.
append
for
c
in
s
:
o
=
ord
(
c
)
if
o
>=
128
:
append
(
'
\
\
x%X'
%
o
)
else
:
append
(
c
)
return
''
.
join
(
l
)
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