Standard-chunk

3.13.0 · active · verified Fri Apr 10

Standard-chunk is a Python library that redistributes modules, often referred to as 'dead batteries,' that have been removed from the Python standard library as per PEP 594 and PEP 632. It allows projects to continue using these modules (such as `aifc`, `asynchat`, `chunk`, `cgi`, etc.) by making them installable via pip. The library focuses on providing minimal compatibility support for these removed modules, rather than active development of new features, with releases typically aligning with Python's major version cycles.

Warnings

Install

Imports

Quickstart

After installing `standard-chunk`, modules like `chunk` can be imported and used as if they were still part of the Python standard library. This example demonstrates basic usage of the `chunk` module to read simulated IFF-like data.

import io
import chunk

# Simulate a file-like object with some IFF-like data
# (simplified for demonstration, actual IFF files are more complex)
iff_data = b'FORM\x00\x00\x00\x18TESTCHANKS\x00\x00\x00\x08DATA\x00\x00\x00\x04abcd'
f = io.BytesIO(iff_data)

try:
    # Create a Chunk object from a file-like object
    ck = chunk.Chunk(f)

    print(f"Chunk ID: {ck.getname().decode('ascii')}")
    print(f"Chunk Size: {ck.getsize()}")

    # Read some data from the chunk
    data_read = ck.read(4)
    print(f"Data read: {data_read}")

    # Seek within the chunk
    ck.seek(0)
    data_read_again = ck.read(4)
    print(f"Data read again after seek: {data_read_again}")

    ck.close()

except Exception as e:
    print(f"An error occurred: {e}")

# Example for another 'dead battery' module, asyncore
# try:
#     import asyncore
#     print("asyncore imported successfully.")
# except ImportError:
#     print("asyncore not found, install standard-asyncore if needed.")

view raw JSON →