Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r93471:ed98419ad5e6 Date: 2017-12-18 13:43 +0100 http://bitbucket.org/pypy/pypy/changeset/ed98419ad5e6/
Log: backport b0e0af09b762 diff --git a/rpython/rlib/_rsocket_rffi.py b/rpython/rlib/_rsocket_rffi.py --- a/rpython/rlib/_rsocket_rffi.py +++ b/rpython/rlib/_rsocket_rffi.py @@ -1361,6 +1361,11 @@ def gai_strerror_str(errno): return rwin32.FormatError(errno) + def socket_strerror_unicode(errno): + return rwin32.FormatErrorW(errno) + def gai_strerror_unicode(errno): + return rwin32.FormatErrorW(errno) + # WinSock does not use a bitmask in select, and uses # socket handles greater than FD_SETSIZE MAX_FD_SIZE = None @@ -1372,4 +1377,9 @@ def gai_strerror_str(errno): return rffi.charp2str(gai_strerror(errno)) + def socket_strerror_unicode(errno): + return socket_strerror_str(errno).decode('latin-1') + def gai_strerror_unicode(errno): + return gai_strerror_str(errno).decode('latin-1') + MAX_FD_SIZE = FD_SETSIZE diff --git a/rpython/rlib/rpoll.py b/rpython/rlib/rpoll.py --- a/rpython/rlib/rpoll.py +++ b/rpython/rlib/rpoll.py @@ -28,12 +28,16 @@ self.errno = errno def get_msg(self): return _c.socket_strerror_str(self.errno) + def get_msg_unicode(self): + return _c.socket_strerror_unicode(self.errno) class SelectError(Exception): def __init__(self, errno): self.errno = errno def get_msg(self): return _c.socket_strerror_str(self.errno) + def get_msg_unicode(self): + return _c.socket_strerror_unicode(self.errno) # ____________________________________________________________ # poll() for POSIX systems diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py --- a/rpython/rlib/rsocket.py +++ b/rpython/rlib/rsocket.py @@ -1298,6 +1298,8 @@ pass def get_msg(self): return '' + def get_msg_unicode(self): + return self.get_msg().decode('latin-1') def __str__(self): return self.get_msg() @@ -1314,6 +1316,8 @@ class CSocketError(SocketErrorWithErrno): def get_msg(self): return _c.socket_strerror_str(self.errno) + def get_msg_unicode(self): + return _c.socket_strerror_unicode(self.errno) def last_error(): return CSocketError(_c.geterrno()) @@ -1322,6 +1326,8 @@ applevelerrcls = 'gaierror' def get_msg(self): return _c.gai_strerror_str(self.errno) + def get_msg_unicode(self): + return _c.gai_strerror_unicode(self.errno) class HSocketError(SocketError): applevelerrcls = 'herror' diff --git a/rpython/rlib/test/test_rsocket.py b/rpython/rlib/test/test_rsocket.py --- a/rpython/rlib/test/test_rsocket.py +++ b/rpython/rlib/test/test_rsocket.py @@ -409,6 +409,7 @@ # catch-all address (i.e. opendns). e = py.test.raises(GAIError, getaddrinfo, 'www.very-invalidaddress.com', None) assert isinstance(e.value.get_msg(), str) + assert isinstance(e.value.get_msg_unicode(), unicode) def getaddrinfo_pydotorg(i, result): lst = getaddrinfo('python.org', None) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit