| module: uu |
| module: base64 |
| module: binhex |
| |
| The :mod:`binascii` module contains a number of methods to convert between |
| binary and various ASCII-encoded binary representations. Normally, you will not |
| use these functions directly but use wrapper modules like :mod:`uu`, |
| :mod:`base64`, or :mod:`binhex` instead. The :mod:`binascii` module contains |
n | low-level functions written in C for greater speed that are used by the higher- |
n | low-level functions written in C for greater speed that are used by the |
| level modules. |
| higher-level modules. |
| |
| The :mod:`binascii` module defines the following functions: |
| |
| |
| .. function:: a2b_uu(string) |
| |
| Convert a single line of uuencoded data back to binary and return the binary |
| data. Lines normally contain 45 (binary) bytes, except for the last line. Line |
| Compute CRC-32, the 32-bit checksum of data, starting with an initial crc. This |
| is consistent with the ZIP file checksum. Since the algorithm is designed for |
| use as a checksum algorithm, it is not suitable for use as a general hash |
| algorithm. Use as follows:: |
| |
| print binascii.crc32("hello world") |
| # Or, in two pieces: |
| crc = binascii.crc32("hello") |
t | crc = binascii.crc32(" world", crc) |
t | crc = binascii.crc32(" world", crc) & 0xffffffff |
| print crc |
| print 'crc32 = 0x%08x' % crc |
| |
| .. note:: |
| To generate the same numeric value across all Python versions and |
| platforms use crc32(data) & 0xffffffff. If you are only using |
| the checksum in packed binary format this is not necessary as the |
| return value is the correct 32bit binary representation |
| regardless of sign. |
| |
| .. versionchanged:: 2.6 |
| The return value is in the range [-2**31, 2**31-1] |
| regardless of platform. In the past the value would be signed on |
| some platforms and unsigned on others. Use & 0xffffffff on the |
| value if you want it to match 3.0 behavior. |
| |
| .. versionchanged:: 3.0 |
| The return value is unsigned and in the range [0, 2**32-1] |
| regardless of platform. |
| |
| |
| .. function:: b2a_hex(data) |
| hexlify(data) |
| |
| Return the hexadecimal representation of the binary *data*. Every byte of |
| *data* is converted into the corresponding 2-digit hex representation. The |
| resulting string is therefore twice as long as the length of *data*. |