def encode(self, encoding):
        netloc = self._host
        if self._port:
            netloc += (b(':') + bytes(self._port))

        result = urlunparse((
            self._scheme, netloc, self._path,
            self._params, self._query, self._fragment
        ))
        return result.decode('utf-8').encode(encoding)
snippet from python cookbook, for parsing large xml file
dataset/ETHPy150Open circuits/circuits/circuits/web/url.py/URL.encode--crossover with--dataset/ETHPy150Open zhongbiaodev/py-mysql-elasticsearch-sync/es_sync/__init__.py/ElasticSync._parse_and_remove