def _parse_options()

in fbtftp/base_handler.py [0:0]


    def _parse_options(self):
        """
        Method that deals with parsing/validation options provided by the
        client.
        """
        opts_to_ack = OrderedDict()
        # We remove retries and default_timeout from self._options because
        # we don't need to include them in the OACK response to the client.
        # Their value is already hold in self._retries and self._timeout.
        del self._options["retries"]
        del self._options["default_timeout"]
        logging.info(
            "Options requested from peer {}:  {}".format(self._peer, self._options)
        )
        self._stats.options_in = self._options
        if "mode" in self._options and self._options["mode"] == "netascii":
            self._response_data = NetasciiReader(self._response_data)
        elif "mode" in self._options and self._options["mode"] != "octet":
            self._stats.error = {
                "error_code": constants.ERR_ILLEGAL_OPERATION,
                "error_message": "Unknown mode: %r" % self._options["mode"],
            }
            self._transmit_error()
            self._close()
            return  # no way anything else will succeed now
        # Let's ack the options in the same order we got asked for them
        # The RFC mentions that option order is not significant, but it can't
        # hurt. This relies on Python 3.6 dicts to be ordered.
        for k, v in self._options.items():
            if k == "blksize":
                opts_to_ack["blksize"] = v
                self._block_size = int(v)
            if k == "tsize":
                self._tsize = self._response_data.size()
                if self._tsize is not None:
                    opts_to_ack["tsize"] = str(self._tsize)
            if k == "timeout":
                opts_to_ack["timeout"] = v
                self._timeout = int(v)

        self._options = opts_to_ack  # only ACK options we can handle
        logging.info(
            "Options to ack for peer {}:  {}".format(self._peer, self._options)
        )
        self._stats.blksize = self._block_size
        self._stats.options = self._options
        self._stats.options_acked = self._options