# Path: oppy/cell/exceptions.py
# class NotEnoughBytes(Exception):
#     pass
# 
# class UnknownCellCommand(Exception):
#     pass


import abc
import struct
import oppy.cell.definitions as DEF
from oppy.cell.exceptions import NotEnoughBytes, UnknownCellCommand
            from oppy.cell.varlen import VarLenCell
            from oppy.cell.relay import RelayCell
            from oppy.cell.fixedlen import FixedLenCell
    @staticmethod
    def parse(data, link_version=3, encrypted=False):
        '''Return an instance of a cell constructed from the str data.

        If encrypted is True and the type if cell is RELAY or RELAY_EARLY,
        don't try to parse the payload and just return a
        :class:`~oppy.cell.fixedlen.EncryptedCell`.
        Otherwise, instantiate and return the appropriate cell type.

        .. note:: *data* str is not modified.

        :param str data: raw bytes to parse and extract a cell from
        :param int link_version: Link Protocol version in use. For fixed-
            length cells, this parameter dictates whether we expect 512
            bytes (Link Protocol <= 3) or 514 bytes.
        :param bool encrypted: whether or not we think this cell is
            encrypted. If True and we see a RELAY or RELAY_EARLY command
            do not attempt to parse payload.

        :returns: instantiated cell type as dictated by the command byte,
            parsed and extracted from data.
        '''
        if not 1 <= link_version <= 4:
            msg = "link_version must be leq 4, but found {} instead"
            raise ValueError(msg.format(link_version))

        fmt = "!HB" if link_version <= 3 else "!IB"
        header_len = struct.calcsize(fmt)

        if len(data) < header_len:

# Path: oppy/cell/exceptions.py
# class NotEnoughBytes(Exception):
#     pass
# 
# class UnknownCellCommand(Exception):
#     pass


# Path: oppy/cell/cell.py
import abc
import struct
import oppy.cell.definitions as DEF
from oppy.cell.exceptions import NotEnoughBytes, UnknownCellCommand
            from oppy.cell.varlen import VarLenCell
            from oppy.cell.relay import RelayCell
            from oppy.cell.fixedlen import FixedLenCell

    @staticmethod
    def parse(data, link_version=3, encrypted=False):
        '''Return an instance of a cell constructed from the str data.

        If encrypted is True and the type if cell is RELAY or RELAY_EARLY,
        don't try to parse the payload and just return a
        :class:`~oppy.cell.fixedlen.EncryptedCell`.
        Otherwise, instantiate and return the appropriate cell type.

        .. note:: *data* str is not modified.

        :param str data: raw bytes to parse and extract a cell from
        :param int link_version: Link Protocol version in use. For fixed-
            length cells, this parameter dictates whether we expect 512
            bytes (Link Protocol <= 3) or 514 bytes.
        :param bool encrypted: whether or not we think this cell is
            encrypted. If True and we see a RELAY or RELAY_EARLY command
            do not attempt to parse payload.

        :returns: instantiated cell type as dictated by the command byte,
            parsed and extracted from data.
        '''
        if not 1 <= link_version <= 4:
            msg = "link_version must be leq 4, but found {} instead"
            raise ValueError(msg.format(link_version))

        fmt = "!HB" if link_version <= 3 else "!IB"
        header_len = struct.calcsize(fmt)

        if len(data) < header_len:

            raise NotEnoughBytes()