How to use the fbtftp.netascii.NetasciiReader function in fbtftp

To help you get started, we’ve selected a few fbtftp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / fbtftp / fbtftp / base_handler.py View on Github external
"""
        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":