From fd6cb1458e8106c3ef20686d961f95042a1e08ca Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 3 Jan 2009 23:47:58 +0000 Subject: [PATCH] Merged revisions 67950,67962,67968-67969,68027,68075,68091,68093 via svnmerge from svn+ssh://svn.python.org/python/branches/py3k ........ r67950 | benjamin.peterson | 2008-12-27 18:00:44 +0100 (Sat, 27 Dec 2008) | 1 line fix 2.x isms in distutils test ........ r67962 | georg.brandl | 2008-12-27 20:08:11 +0100 (Sat, 27 Dec 2008) | 2 lines #4697: clarify that the functions are Unix-only. ........ r67968 | georg.brandl | 2008-12-28 00:12:09 +0100 (Sun, 28 Dec 2008) | 2 lines Remove confusing error message in bytes.translate. ........ r67969 | georg.brandl | 2008-12-28 00:33:20 +0100 (Sun, 28 Dec 2008) | 5 lines Document bytes.translate(). BTW, having str.maketrans() as a static method and string.maketrans() as a function that creates translation tables for bytes objects is not very consistent :) ........ r68027 | benjamin.peterson | 2008-12-29 21:52:09 +0100 (Mon, 29 Dec 2008) | 1 line hexdigest() doesn't return bytes #4771 ........ r68075 | benjamin.peterson | 2008-12-30 19:05:46 +0100 (Tue, 30 Dec 2008) | 2 lines use $(RUNSHARED) to run plat-mac/regen ........ r68091 | benjamin.peterson | 2008-12-31 04:43:28 +0100 (Wed, 31 Dec 2008) | 1 line #4788 qualify remove a bare except ........ r68093 | benjamin.peterson | 2008-12-31 05:10:35 +0100 (Wed, 31 Dec 2008) | 1 line fix name usage ........ --- Doc/library/hashlib.rst | 4 ++-- Doc/library/stdtypes.rst | 33 ++++++++++++++++----------------- Doc/library/subprocess.rst | 4 ++++ Lib/ssl.py | 2 +- Objects/bytesobject.c | 5 ----- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst index 2741265d1c35..ad2bfa53d32d 100644 --- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -64,7 +64,7 @@ spammish repetition'``:: More condensed: >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest() - b'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' + 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' A generic :func:`new` constructor that takes the string name of the desired algorithm as its first parameter also exists to allow access to the above listed @@ -76,7 +76,7 @@ Using :func:`new` with an algorithm provided by OpenSSL: >>> h = hashlib.new('ripemd160') >>> h.update(b"Nobody inspects the spammish repetition") >>> h.hexdigest() - b'cc4a5ce1b3df48aec5d22d1f16b894a0b894eccc' + 'cc4a5ce1b3df48aec5d22d1f16b894a0b894eccc' The following values are provided as constant attributes of the hash objects returned by the constructors: diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 68e8dbafdb3a..0ce1c15936a3 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1086,13 +1086,12 @@ functions based on regular expressions. .. method:: str.translate(map) Return a copy of the *s* where all characters have been mapped through the - *map* which must be a dictionary of Unicode ordinals(integers) to Unicode + *map* which must be a dictionary of Unicode ordinals (integers) to Unicode ordinals, strings or ``None``. Unmapped characters are left untouched. Characters mapped to ``None`` are deleted. - You can use :meth:`str.maketrans` to create a translation table. For string - objects, set the *table* argument to ``None`` for translations that only - delete characters: + You can use :meth:`str.maketrans` to create a translation map from + character-to-character mappings in different formats. .. note:: @@ -1495,23 +1494,23 @@ The bytes and bytearray types have an additional class method: >>> bytes.fromhex('f0 f1f2 ') b'\xf0\xf1\xf2' -.. XXX verify/document translate() semantics! - - .. method:: bytes.translate(table[, delete]) +The translate method differs in semantics from the version available on strings: + +.. method:: bytes.translate(table[, delete]) - Return a copy of the bytes object where all bytes occurring in the optional - argument *delete* are removed, and the remaining bytes have been mapped - through the given translation table, which must be a bytes object of length - 256. + Return a copy of the bytes or bytearray object where all bytes occurring in + the optional argument *delete* are removed, and the remaining bytes have been + mapped through the given translation table, which must be a bytes object of + length 256. - You can use the :func:`maketrans` helper function in the :mod:`string` module to - create a translation table. + You can use the :func:`string.maketrans` helper function to create a + translation table. - .. XXX a None table doesn't seem to be supported - Set the *table* argument to ``None`` for translations that only delete characters:: + Set the *table* argument to ``None`` for translations that only delete + characters:: - >>> 'read this short text'.translate(None, 'aeiou') - 'rd ths shrt txt' + >>> b'read this short text'.translate(None, b'aeiou') + b'rd ths shrt txt' .. _types-set: diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst index 6aff816d9982..b8523e76d798 100644 --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -173,6 +173,8 @@ This module also defines four shortcut functions: >>> subprocess.getstatusoutput('/bin/junk') (256, 'sh: /bin/junk: not found') + Availability: UNIX. + .. function:: getoutput(cmd) Return output ``(stdout or stderr)`` of executing *cmd* in a shell. @@ -184,6 +186,8 @@ This module also defines four shortcut functions: >>> subprocess.getoutput('ls /bin/ls') '/bin/ls' + Availability: UNIX. + Exceptions ^^^^^^^^^^ diff --git a/Lib/ssl.py b/Lib/ssl.py index cd54437a0c5d..d3c1d32c72a3 100644 --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -114,7 +114,7 @@ class SSLSocket(socket): # see if it's connected try: socket.getpeername(self) - except: + except socket_error: # no, no connection yet self._sslobj = None else: diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 76b7f522005c..c75ebabe501c 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -1884,11 +1884,6 @@ string_translate(PyBytesObject *self, PyObject *args) del_table = PyBytes_AS_STRING(delobj); dellen = PyBytes_GET_SIZE(delobj); } - else if (PyUnicode_Check(delobj)) { - PyErr_SetString(PyExc_TypeError, - "deletions are implemented differently for unicode"); - return NULL; - } else if (PyObject_AsCharBuffer(delobj, &del_table, &dellen)) return NULL; } -- 2.47.3