connection.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:umapi-client.py 作者: adobe-apiplatform 项目源码 文件源码
def query_multiple(self, object_type, page=0, url_params=None, query_params=None):
        # type: (str, int, list, dict) -> tuple
        """
        Query for a page of objects.  Defaults to the (0-based) first page.
        Sadly, the sort order is undetermined.
        :param object_type: string query type (e.g., "users" or "groups")
        :param page: numeric page (0-based) of results to get (up to 200 in a page)
        :param url_params: optional list of strings to provide as additional URL components
        :param query_params: optional dictionary of query options
        :return: tuple (list of returned dictionaries (one for each query result), bool for whether this is last page)
        """
        # Server API convention (v2) is that the pluralized object type goes into the endpoint
        # and is also the key in the response dictionary for the returned objects.
        self.local_status["multiple-query-count"] += 1
        query_type = object_type + "s"  # poor man's plural
        query_path = "/{}/{}/{:d}".format(query_type, self.org_id, page)
        for component in url_params if url_params else []:
            query_path += "/" + urlparse.quote(component)
        if query_params: query_path += "?" + urlparse.urlencode(query_params)
        try:
            result = self.make_call(query_path)
            body = result.json()
        except RequestError as re:
            if re.result.status_code == 404:
                if self.logger: self.logger.debug("Ran %s query: %s %s (0 found)",
                                                  object_type, url_params, query_params)
                return [], True
            else:
                raise re
        if body.get("result") == "success":
            values = body.get(query_type, [])
            last_page = body.get("lastPage", False)
            if self.logger: self.logger.debug("Ran multi-%s query: %s %s (page %d: %d found)",
                                              object_type, url_params, query_params, page, len(values))
            return values, last_page
        else:
            raise ClientError("OK status but no 'success' result", result)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号