def _import_next_layer(self, proto, length=None): """Import next layer extractor. Arguments: proto (str): next layer protocol name length (int): valid (*non-padding*) length Returns: pcapkit.protocols.protocol.Protocol: instance of next layer """ if self._exproto == 'null' and self._exlayer == 'None': from pcapkit.protocols.raw import \ Raw as protocol # pylint: disable=import-outside-toplevel else: from pcapkit.foundation.analysis import \ analyse as protocol # pylint: disable=import-outside-toplevel if length == 0: next_ = NoPayload() elif self._onerror: next_ = beholder_ng(protocol)(self._file, length, termination=self._sigterm) else: next_ = protocol(self._file, length, termination=self._sigterm) return next_
def _import_next_layer(self, proto, length, error=False): # pylint: disable=arguments-differ """Import next layer extractor. This method currently supports following protocols as registered in :data:`~pcapkit.const.reg.linktype.LinkType`: .. list-table:: :header-rows: 1 * - ``proto`` - Protocol * - 1 - :class:`~pcapkit.protocols.link.ethernet.Ethernet` * - 228 - :class:`~pcapkit.protocols.internet.ipv4.IPv4` * - 229 - :class:`~pcapkit.protocols.internet.ipv6.IPv6` Arguments: proto (pcapkit.const.reg.linktype.LinkType): next layer protocol index length (int): valid (*non-padding*) length Keyword arguments: error (bool): if function called on error Returns: pcapkit.protocols.protocol.Protocol: instance of next layer """ module, name = self.__proto__[int(proto)] try: protocol = getattr(importlib.import_module(module), name) except (ImportError, AttributeError): from pcapkit.protocols.raw import \ Raw as protocol # pylint: disable=import-outside-toplevel next_ = protocol(self._file, length, error=error, layer=self._exlayer, protocol=self._exproto) return next_