# Path: IoTPy/errors.py
# class IoTPy_APIError(Exception):
#     pass


from IoTPy.errors import IoTPy_APIError
from six import binary_type, integer_types
from struct import pack, unpack
#from builtins import chr


def _encode_int(intarg):
    if intarg < 64:
        return chr(intarg).encode('latin-1')
    packedint = pack('>I', intarg).lstrip(b'\x00')
    return chr(0xc0 | (len(packedint) - 1)).encode('latin-1') + packedint


def _encode_bytes(byte_string):
    if len(byte_string) < 64:
        return chr(0x40 | len(byte_string)).encode('latin-1') + byte_string
    packedlen = pack('>I', len(byte_string)).lstrip(b'\x00')
    if len(packedlen) == 1:
        return b'\xc4' + packedlen + byte_string
    elif len(packedlen) == 2:
        return b'\xc5' + packedlen + byte_string
    else:

# Path: IoTPy/errors.py
# class IoTPy_APIError(Exception):
#     pass


# Path: IoTPy/sfp.py
from IoTPy.errors import IoTPy_APIError
from six import binary_type, integer_types
from struct import pack, unpack

#from builtins import chr


def _encode_int(intarg):
    if intarg < 64:
        return chr(intarg).encode('latin-1')
    packedint = pack('>I', intarg).lstrip(b'\x00')
    return chr(0xc0 | (len(packedint) - 1)).encode('latin-1') + packedint


def _encode_bytes(byte_string):
    if len(byte_string) < 64:
        return chr(0x40 | len(byte_string)).encode('latin-1') + byte_string
    packedlen = pack('>I', len(byte_string)).lstrip(b'\x00')
    if len(packedlen) == 1:
        return b'\xc4' + packedlen + byte_string
    elif len(packedlen) == 2:
        return b'\xc5' + packedlen + byte_string
    else:

        raise IoTPy_APIError("UPER API: - too long string passed to UPER, encode_bytes can't handle it.")