return None
def _unpack_encoding_and_error_mode(self, pos, args):
- encoding_node = args[1]
- if isinstance(encoding_node, ExprNodes.CoerceToPyTypeNode):
- encoding_node = encoding_node.arg
- if isinstance(encoding_node, (ExprNodes.UnicodeNode, ExprNodes.StringNode,
- ExprNodes.BytesNode)):
- encoding = encoding_node.value
- encoding_node = ExprNodes.BytesNode(encoding_node.pos, value=encoding,
- type=PyrexTypes.c_char_ptr_type)
- elif encoding_node.type.is_string:
- encoding = None
+ null_node = ExprNodes.NullNode(pos)
+
+ if len(args) >= 2:
+ encoding_node = args[1]
+ if isinstance(encoding_node, ExprNodes.CoerceToPyTypeNode):
+ encoding_node = encoding_node.arg
+ if isinstance(encoding_node, (ExprNodes.UnicodeNode, ExprNodes.StringNode,
+ ExprNodes.BytesNode)):
+ encoding = encoding_node.value
+ encoding_node = ExprNodes.BytesNode(encoding_node.pos, value=encoding,
+ type=PyrexTypes.c_char_ptr_type)
+ elif encoding_node.type.is_string:
+ encoding = None
+ else:
+ return None
else:
- return None
+ encoding = None
+ encoding_node = null_node
- null_node = ExprNodes.NullNode(pos)
if len(args) == 3:
error_handling_node = args[2]
if isinstance(error_handling_node, ExprNodes.CoerceToPyTypeNode):
cstring[:3].decode('UTF-8'),
cstring[:9].decode('UTF-8'))
+@cython.test_assert_path_exists("//PythonCapiCallNode")
+@cython.test_fail_if_path_exists("//AttributeNode")
+def slice_charptr_decode_platform_encoding():
+ """
+ >>> print(str(slice_charptr_decode()).replace("u'", "'"))
+ ('a', 'abc', 'abcABCqtp')
+ """
+ cdef bytes s = u'abcABCqtp'.encode()
+ cdef char* cstr = s
+ return (cstr[:1].decode(),
+ cstr[:3].decode(),
+ cstr[:9].decode())
+
@cython.test_assert_path_exists("//PythonCapiCallNode")
@cython.test_fail_if_path_exists("//AttributeNode")
def slice_charptr_decode_unknown_encoding():