cffi_utils/py2to3.py
def chr(x):
    '''
    x-->int / byte
    Returns-->BYTE (not str in python3)
        Behaves like PY2 chr() in PY2 or PY3
    if x is str of length > 1 or int > 256
        raises ValueError/TypeError is not SUPPRESS_ERRORS
    '''
    global _chr
    if isinstance(x, int):
        if x > 256:
            if SUPPRESS_ERRORS:
                x = x % 256
        return toBytes(_chr(x))
    elif isinstance(x, bytes):
        x = fromBytes(x)
        if len(x) > 1:
            if not SUPPRESS_ERRORS:
                raise TypeError('chr() found string of length > 2')
            x = x[0]
        return toBytes(x)
    elif isinstance(x, str):
        if len(x) > 1:
            if not SUPPRESS_ERRORS:
                raise TypeError('chr() found string of length > 2')
            x = x[0]
        return toBytes(x)
    else:
        raise TypeError('Unknown type passed to chr: %s', str(type(x)))
def chr(x):
    '''
    x-->int / byte
    Returns-->BYTE (not str in python3)
        Behaves like PY2 chr() in PY2 or PY3
    if x is str of length > 1 or int > 256
        raises ValueError/TypeError is not SUPPRESS_ERRORS
    '''
    global _chr
    if isinstance(x, int):
        if x > 256:
            if SUPPRESS_ERRORS:
                x = x % 256
        return toBytes(_chr(x))
    elif isinstance(x, bytes):
        x = fromBytes(x)
        if len(x) > 1:
            if not SUPPRESS_ERRORS:
                raise TypeError('chr() found string of length > 2')
            x = x[0]
        return toBytes(x)
    elif isinstance(x, str):
        if len(x) > 1:
            if not SUPPRESS_ERRORS:
                raise TypeError('chr() found string of length > 2')
            x = x[0]
        return toBytes(x)
    else:
        raise TypeError('Unknown type passed to chr: %s', str(type(x)))
x-->int / byte
    Returns-->BYTE (not str in python3)
        Behaves like PY2 chr() in PY2 or PY3
    if x is str of length > 1 or int > 256
        raises ValueError/TypeError is not SUPPRESS_ERRORS