def construct_chunk(cls, chunk_type, payload, encoding='utf-8'):
    """Construct and return a single chunk."""
    if isinstance(payload, str):
      payload = payload.encode(encoding)
    elif not isinstance(payload, bytes):
      raise TypeError('cannot encode type: {}'.format(type(payload)))

    header = struct.pack(cls.HEADER_FMT, len(payload), chunk_type)
    return header + payload
def construct_chunk ( cls , chunk_type , payload , encoding = 'utf-8' ) : if isinstance ( payload , str ) : payload = payload . encode ( encoding ) elif not isinstance ( payload , bytes ) : raise TypeError ( 'cannot encode type: {}' . format ( type ( payload ) ) ) header = struct . pack ( cls . HEADER_FMT , len ( payload ) , chunk_type ) return header + payload
Construct and return a single chunk.