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
7930fe41
Commit
7930fe41
authored
Nov 02, 2011
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce PyObject* API for raising encode errors.
parent
b73fc0da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
3 deletions
+49
-3
Objects/unicodeobject.c
Objects/unicodeobject.c
+49
-3
No files found.
Objects/unicodeobject.c
View file @
7930fe41
...
@@ -257,6 +257,12 @@ raise_encode_exception(PyObject **exceptionObject,
...
@@ -257,6 +257,12 @@ raise_encode_exception(PyObject **exceptionObject,
const
Py_UNICODE
*
unicode
,
Py_ssize_t
size
,
const
Py_UNICODE
*
unicode
,
Py_ssize_t
size
,
Py_ssize_t
startpos
,
Py_ssize_t
endpos
,
Py_ssize_t
startpos
,
Py_ssize_t
endpos
,
const
char
*
reason
);
const
char
*
reason
);
static
void
raise_encode_exception_obj
(
PyObject
**
exceptionObject
,
const
char
*
encoding
,
PyObject
*
unicode
,
Py_ssize_t
startpos
,
Py_ssize_t
endpos
,
const
char
*
reason
);
/* Same for linebreaks */
/* Same for linebreaks */
static
unsigned
char
ascii_linebreak
[]
=
{
static
unsigned
char
ascii_linebreak
[]
=
{
...
@@ -4786,9 +4792,9 @@ _PyUnicode_AsUTF8String(PyObject *obj, const char *errors)
...
@@ -4786,9 +4792,9 @@ _PyUnicode_AsUTF8String(PyObject *obj, const char *errors)
for
(
k
=
0
;
k
<
repsize
;
k
++
)
{
for
(
k
=
0
;
k
<
repsize
;
k
++
)
{
c
=
prep
[
k
];
c
=
prep
[
k
];
if
(
0x80
<=
c
)
{
if
(
0x80
<=
c
)
{
raise_encode_exception
(
&
exc
,
"utf-8"
,
raise_encode_exception
_obj
(
&
exc
,
"utf-8"
,
PyUnicode_AS_UNICODE
(
unicode
)
,
(
PyObject
*
)
unicode
,
size
,
i
-
1
,
i
,
i
-
1
,
i
,
"surrogates not allowed"
);
"surrogates not allowed"
);
goto
error
;
goto
error
;
}
}
...
@@ -6434,6 +6440,33 @@ make_encode_exception(PyObject **exceptionObject,
...
@@ -6434,6 +6440,33 @@ make_encode_exception(PyObject **exceptionObject,
}
}
}
}
/* This is ultimately going t replace above function. */
static
void
make_encode_exception_obj
(
PyObject
**
exceptionObject
,
const
char
*
encoding
,
PyObject
*
unicode
,
Py_ssize_t
startpos
,
Py_ssize_t
endpos
,
const
char
*
reason
)
{
if
(
*
exceptionObject
==
NULL
)
{
*
exceptionObject
=
PyObject_CallFunction
(
PyExc_UnicodeEncodeError
,
"sUnns"
,
encoding
,
unicode
,
startpos
,
endpos
,
reason
);
}
else
{
if
(
PyUnicodeEncodeError_SetStart
(
*
exceptionObject
,
startpos
))
goto
onError
;
if
(
PyUnicodeEncodeError_SetEnd
(
*
exceptionObject
,
endpos
))
goto
onError
;
if
(
PyUnicodeEncodeError_SetReason
(
*
exceptionObject
,
reason
))
goto
onError
;
return
;
onError:
Py_DECREF
(
*
exceptionObject
);
*
exceptionObject
=
NULL
;
}
}
/* raises a UnicodeEncodeError */
/* raises a UnicodeEncodeError */
static
void
static
void
raise_encode_exception
(
PyObject
**
exceptionObject
,
raise_encode_exception
(
PyObject
**
exceptionObject
,
...
@@ -6447,6 +6480,19 @@ raise_encode_exception(PyObject **exceptionObject,
...
@@ -6447,6 +6480,19 @@ raise_encode_exception(PyObject **exceptionObject,
if
(
*
exceptionObject
!=
NULL
)
if
(
*
exceptionObject
!=
NULL
)
PyCodec_StrictErrors
(
*
exceptionObject
);
PyCodec_StrictErrors
(
*
exceptionObject
);
}
}
/* This is ultimately going to replace above function. */
static
void
raise_encode_exception_obj
(
PyObject
**
exceptionObject
,
const
char
*
encoding
,
PyObject
*
unicode
,
Py_ssize_t
startpos
,
Py_ssize_t
endpos
,
const
char
*
reason
)
{
make_encode_exception_obj
(
exceptionObject
,
encoding
,
unicode
,
startpos
,
endpos
,
reason
);
if
(
*
exceptionObject
!=
NULL
)
PyCodec_StrictErrors
(
*
exceptionObject
);
}
/* error handling callback helper:
/* error handling callback helper:
build arguments, call the callback and check the arguments,
build arguments, call the callback and check the arguments,
...
...
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