python类unquote()的实例源码

adapters.py 文件源码 项目:deb-python-requests-unixsocket 作者: openstack 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def connect(self):
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        sock.settimeout(self.timeout)
        socket_path = unquote(urlparse(self.unix_socket_url).netloc)
        sock.connect(socket_path)
        self.sock = sock
unixadapter.py 文件源码 项目:commissaire 作者: projectatomic 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def connect(self):
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        sock.settimeout(self.timeout)
        socket_path = unquote(urlparse(self.unix_socket_url).netloc)
        sock.connect(socket_path)
        self.sock = sock
api.py 文件源码 项目:bonsai-cli 作者: BonsaiAI 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _get_multipart(self, url):
        """
        Issues a GET request for a multipart/mixed response
        and returns a dictionary of filename/data from the response.
        :param url: The URL being GET from.
        """
        log.debug('GET from %s...', url)
        headers = {
            'Authorization': self._access_key,
            "Accept": "multipart/mixed",
            'Accept-Encoding': 'base64'
        }
        response = requests.get(url=url,
                                headers=headers)
        try:
            response.raise_for_status()
            log.debug('GET %s results:\n%s', url, response.text)

            # combine response's headers/response so its parsable together
            header_list = ["{}: {}".format(key, response.headers[key])
                           for key in response.headers]
            header_string = "\r\n".join(header_list)
            message = "\r\n\r\n".join([header_string, response.text])

            # email is kind of a misnomer for the package,
            # it includes a lot of utilities and we're using
            # it here to parse the multipart response,
            # which the requests lib doesn't help with very much
            parsed_message = email.message_from_string(message)

            # create a filename/data dictionary
            response = {}
            for part in parsed_message.walk():
                # make sure this part is a file
                file_header = part.get_filename(failobj=None)
                if file_header:
                    filename = unquote(file_header)
                    response[filename] = part.get_payload(decode=True)

            return response
        except requests.exceptions.HTTPError as e:
            _handle_and_raise(response, e)


问题


面经


文章

微信
公众号

扫码关注公众号