pyopenapi / pyswagger

An OpenAPI (fka Swagger) client & converter in python, which is type-safe, dynamic, spec-compliant.
MIT License
384 stars 88 forks source link

Change from pop to get when patching requests #182

Open fredrikstormo opened 5 years ago

fredrikstormo commented 5 years ago

pyswagger.io.Request

    def _patch(self, opt={}):
        """ private function to patch this request. This function
        could be called before/after preparation.

        :param dict opt: options, used options would be popped. Refer to Request.opt_* for details.
        """
        opt_netloc = opt.pop(Request.opt_url_netloc, None)
        opt_scheme = opt.pop(Request.opt_url_scheme, None)
        if opt_netloc or opt_scheme:
            scheme, netloc, path, params, query, fragment = six.moves.urllib.parse.urlparse(self.__url)
            self.__url = six.moves.urllib.parse.urlunparse((
                opt_scheme or scheme,
                opt_netloc or netloc,
                path,
                params,
                query,
                fragment
            ))

            logger.info('patching url: [{0}]'.format(self.__url))

the pops should be changed to

        opt_netloc = opt.get(Request.opt_url_netloc, None)
        opt_scheme = opt.get(Request.opt_url_scheme, None)

Currently it modifies the original dictionary making subsequent requests with the same opts impossible (without copying the opt dict).