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
1f33f2b0
Commit
1f33f2b0
authored
Dec 17, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #13560: os.strerror() now uses the current locale encoding instead of UTF-8
parent
f2ea71fc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
20 deletions
+35
-20
Misc/NEWS
Misc/NEWS
+3
-0
Modules/posixmodule.c
Modules/posixmodule.c
+1
-1
Modules/socketmodule.c
Modules/socketmodule.c
+2
-3
Objects/unicodeobject.c
Objects/unicodeobject.c
+20
-8
Python/errors.c
Python/errors.c
+9
-8
No files found.
Misc/NEWS
View file @
1f33f2b0
...
...
@@ -419,6 +419,9 @@ Core and Builtins
Library
-------
-
Issue
#
13560
:
os
.
strerror
()
now
uses
the
current
locale
encoding
instead
of
UTF
-
8.
-
Issue
#
13560
:
Add
PyUnicode_DecodeLocale
(),
PyUnicode_DecodeLocaleAndSize
()
and
PyUnicode_EncodeLocale
()
functions
to
the
C
API
to
decode
/
encode
from
/
to
the
current
locale
encoding
.
...
...
Modules/posixmodule.c
View file @
1f33f2b0
...
...
@@ -7891,7 +7891,7 @@ posix_strerror(PyObject *self, PyObject *args)
"strerror() argument out of range"
);
return
NULL
;
}
return
PyUnicode_
FromString
(
message
);
return
PyUnicode_
DecodeLocale
(
message
,
1
);
}
...
...
Modules/socketmodule.c
View file @
1f33f2b0
...
...
@@ -4032,9 +4032,8 @@ gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af)
if
(
h
->
h_addrtype
!=
af
)
{
/* Let's get real error message to return */
PyErr_SetString
(
PyExc_OSError
,
(
char
*
)
strerror
(
EAFNOSUPPORT
));
errno
=
EAFNOSUPPORT
;
PyErr_SetFromErrno
(
PyExc_OSError
);
return
NULL
;
}
...
...
Objects/unicodeobject.c
View file @
1f33f2b0
...
...
@@ -3132,6 +3132,7 @@ PyUnicode_EncodeLocale(PyObject *unicode, int surrogateescape)
wchar_t
*
wstr
;
PyObject
*
bytes
=
NULL
;
char
*
errmsg
;
PyObject
*
reason
;
PyObject
*
exc
;
size_t
error_pos
;
...
...
@@ -3193,17 +3194,28 @@ PyUnicode_EncodeLocale(PyObject *unicode, int surrogateescape)
encode_error:
errmsg
=
strerror
(
errno
);
assert
(
errmsg
!=
NULL
);
if
(
errmsg
==
NULL
)
errmsg
=
"wcstombs() encountered an unencodable wide character"
;
PyMem_Free
(
wstr
);
Py_XDECREF
(
bytes
);
exc
=
NULL
;
raise_encode_exception
(
&
exc
,
"locale"
,
unicode
,
error_pos
,
error_pos
+
1
,
errmsg
);
Py_XDECREF
(
exc
);
if
(
errmsg
!=
NULL
)
reason
=
PyUnicode_DecodeLocale
(
errmsg
,
1
);
else
reason
=
PyUnicode_FromString
(
"wcstombs() encountered an unencodable "
"wide character"
);
if
(
reason
==
NULL
)
return
NULL
;
exc
=
PyObject_CallFunction
(
PyExc_UnicodeEncodeError
,
"sOnnO"
,
"locale"
,
unicode
,
(
Py_ssize_t
)
error_pos
,
(
Py_ssize_t
)(
error_pos
+
1
),
reason
);
Py_DECREF
(
reason
);
if
(
exc
!=
NULL
)
{
PyCodec_StrictErrors
(
exc
);
Py_XDECREF
(
exc
);
}
return
NULL
;
}
...
...
Python/errors.c
View file @
1f33f2b0
...
...
@@ -343,9 +343,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
PyObject
*
message
;
PyObject
*
v
,
*
args
;
int
i
=
errno
;
#ifndef MS_WINDOWS
char
*
s
;
#else
#ifdef MS_WINDOWS
WCHAR
*
s_buf
=
NULL
;
#endif
/* Unix/Windows */
...
...
@@ -355,11 +353,14 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
#endif
#ifndef MS_WINDOWS
if
(
i
==
0
)
s
=
"Error"
;
/* Sometimes errno didn't get set */
else
s
=
strerror
(
i
);
message
=
PyUnicode_DecodeUTF8
(
s
,
strlen
(
s
),
"ignore"
);
if
(
i
!=
0
)
{
char
*
s
=
strerror
(
i
);
message
=
PyUnicode_DecodeLocale
(
s
,
1
);
}
else
{
/* Sometimes errno didn't get set */
message
=
PyUnicode_FromString
(
"Error"
);
}
#else
if
(
i
==
0
)
message
=
PyUnicode_FromString
(
"Error"
);
/* Sometimes errno didn't get set */
...
...
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