Source

astoptimizer / astoptimizer / config_struct.py

"""
Optimizations for the struct module.
"""
from astoptimizer.config import Function, VarargFunction, ANY_TYPE
from astoptimizer.compatibility import NATIVE_STR
import struct

def setup_config(config):
    config.add_func('struct.pack', VarargFunction(struct.pack, catch=struct.error))
    config.add_func('struct.unpack', Function(struct.unpack, 2, NATIVE_STR, ANY_TYPE, catch=(struct.error, TypeError)))
    config.add_func('struct.calcsize', Function(struct.calcsize, 1, NATIVE_STR, catch=struct.error))