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
>>> 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:
.. 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::
>>> 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:
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;
}