• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python treq.json_content函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中treq.json_content函数的典型用法代码示例。如果您正苦于以下问题:Python json_content函数的具体用法?Python json_content怎么用?Python json_content使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了json_content函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _on_response

 def _on_response(response):
     if response.code == 201:
         json_content(response).addCallback(_construct_message, response)
     elif response.code == 204:
         reactor.callLater(polling_interval, _perform_call)
     else:
         return self._handle_error_response(response)
开发者ID:russellhaering,项目名称:txmarconi,代码行数:7,代码来源:client.py


示例2: setUp

 def setUp(self):
     """
     Create a :obj:`MimicCore` with :obj:`LoadBalancerApi` as the only plugin.
     And create a load balancer and add nodes to the load balancer.
     """
     helper = APIMockHelper(self, [LoadBalancerApi()])
     self.root = helper.root
     self.uri = helper.uri
     create_lb = request(
         self, self.root, "POST", self.uri + '/loadbalancers',
         json.dumps({
             "loadBalancer": {
                 "name": "test_lb",
                 "protocol": "HTTP",
                 "virtualIps": [{"type": "PUBLIC"}]
             }
         })
     )
     create_lb_response = self.successResultOf(create_lb)
     self.create_lb_response_body = self.successResultOf(treq.json_content(
                                                         create_lb_response))
     create_node = request(
         self, self.root, "POST", self.uri + '/loadbalancers/' +
         str(self.create_lb_response_body["loadBalancer"]["id"]) + '/nodes',
         json.dumps({"nodes": [{"address": "127.0.0.1",
                                "port": 80,
                                "condition": "ENABLED",
                                "type": "PRIMARY",
                                "weight": 10}]})
     )
     self.create_node_response = self.successResultOf(create_node)
     self.create_node_response_body = self.successResultOf(treq.json_content(
                                                           self.create_node_response))
     self.node = self.create_node_response_body["nodes"]
开发者ID:lvh,项目名称:mimic,代码行数:34,代码来源:test_loadbalancer.py


示例3: test_server_in_building_state_for_specified_time

 def test_server_in_building_state_for_specified_time(self):
     """
     Test to verify :func:`create_server` creates a server in BUILD
     status for the time specified in the metadata.
     """
     metadata = {"server_building": 1}
     # create server with metadata to keep the server in building state for
     # 3 seconds
     create_server_response = self.create_server(metadata=metadata)
     # verify the create server was successful
     self.assertEquals(create_server_response.code, 202)
     create_server_response_body = self.successResultOf(
         treq.json_content(create_server_response))
     # get server and verify status is BUILD
     get_server = request(self, self.root, "GET", self.uri + '/servers/' +
                          create_server_response_body["server"]["id"])
     get_server_response = self.successResultOf(get_server)
     get_server_response_body = self.successResultOf(
         treq.json_content(get_server_response))
     self.assertEquals(get_server_response_body['server']['status'], "BUILD")
     # Time Passes...
     self.helper.clock.advance(2.0)
     # get server and verify status changed to active
     get_server = request(self, self.root, "GET", self.uri + '/servers/' +
                          create_server_response_body["server"]["id"])
     get_server_response = self.successResultOf(get_server)
     get_server_response_body = self.successResultOf(
         treq.json_content(get_server_response))
     self.assertEquals(get_server_response_body['server']['status'], "ACTIVE")
开发者ID:lvh,项目名称:mimic,代码行数:29,代码来源:test_nova.py


示例4: check

    def check(self):
        # Hax
        try:
            irc = self.master.modules["irc"]
            words = yield self.config.get("words", [])

            response = yield treq.get("http://a.4cdn.org/a/threads.json")
            threads = yield treq.json_content(response)

            nthreads, check = {}, []
            for o in threads:
                for t in o["threads"]:
                    nthreads[t["no"]] = t["last_modified"]
                    if t["no"] not in self.threads:
                        self.threads[t["no"]] = 0
                    if t["last_modified"] > self.threads[t["no"]]:
                        check.append(t["no"])

            if not self.initial:
                threads = []
                for t in check:
                    response = yield treq.get("http://a.4cdn.org/a/res/{:d}.json".format(t))
                    if response.code == 200:
                        data = yield treq.json_content(response)
                        found, posts = set(), []
                        for p in data["posts"]:
                            if p["time"] > self.threads[t] and "com" in p:
                                f = set(filter(lambda x: re.search(r"\b" + x.lower() + r"\b", p["com"].lower()), words))
                                if f:
                                    found.update(f)
                                    posts.append((p["no"], p["com"]))
                        if found and posts:
                            threads.append((t, found, posts))
                if len(threads) < 5:
                    for t, found, posts in threads:
                        p, also = posts[0], (u"(also {} in same thread)".format(", ".join([str(x[0]) for x in posts[1:]])) if posts[1:] else u"")
                        url = "https://archive.foolz.us/a/thread/{:d}/#{:d}".format(t, p[0])
                        #response = yield treq.post("https://www.googleapis.com/urlshortener/v1/url?key="+API_KEY, json.dumps({"longUrl": url}), headers={'Content-Type': ['application/json']})
                        #data = yield treq.json_content(response)
                        #url = data["id"]
                        excerpt = p[1].replace("<br>", "\n")
                        excerpt = BeautifulSoup(excerpt).get_text()
                        excerpt = re.sub("\s+", " ", excerpt)
                        excerpt = excerpt if len(excerpt) <= 100 else excerpt[:97]+"..."
                        irc.msg(u"#commie-subs", u"\u00039>{} mentioned on /a/ at {} [{}] {}".format(u", ".join(found), url, excerpt, also))
                else:
                    t, found = [str(x[0]) for x in threads], reduce(lambda a,b: a|b, [x[1] for x in threads])
                    irc.msg(u"#commie-subs", u"\u00039>{} flooded /a/ in threads {}".format(u", ".join(found), u", ".join(t)))

            self.threads = nthreads
            self.initial = False
        except:
            self.err(u"4chan module broke horribly :(")
开发者ID:Fugiman,项目名称:Servrhe,代码行数:53,代码来源:4chan.py


示例5: lookupCharacters

def lookupCharacters(member, characters):
  response = yield treq.get("http://www.bungie.net/Platform/User/GetBungieAccount/" + member["membershipId"].encode("UTF-8") + "/254/")
  data = yield treq.json_content(response)
  for account in data["Response"]["destinyAccounts"]:
    if account["userInfo"]["membershipType"] == 1:
      platform = "xbox"
    elif account["userInfo"]["membershipType"] == 2:
      platform = "playstation"
    else:
      continue

    for character in account["characters"]:
      character_data = {
        "bungieId": member["membershipId"],
        "accountId": account["userInfo"]["membershipId"],
        "characterId": character["characterId"],
        "name": account["userInfo"]["displayName"],
        "race": character["race"]["raceName"],
        "gender": character["gender"]["genderName"],
        "class": character["characterClass"]["className"],
        "level": character["level"],
        "levelString": "{:,d}".format(character["level"]),
        "icon": "http://bungie.net" + character["emblemPath"],
        "background": "http://bungie.net" + character["backgroundPath"],

        # Default values for extra data (in case it fails)
        "light": 0,
        "lightString": "{:,d}".format(0),
        "grimoire": 0,
        "grimoireString": "{:,d}".format(0),
        "minutesPlayed": 0,
        "minutesPlayedString": "{:,d}".format(0),
        "lastSeen": "",
        "lastSeenString": ""
      }
      character_data["style"] = 'background: url("' + character_data["background"] + '")'

      try:
        response = yield treq.get("http://www.bungie.net/Platform/Destiny/{!s}/Account/{!s}/Character/{!s}/".format(account["userInfo"]["membershipType"], account["userInfo"]["membershipId"], character["characterId"]))
        extra_data = yield treq.json_content(response)
        extra_data = extra_data["Response"]["data"]["characterBase"]
        character_data["light"] = extra_data["stats"]["STAT_LIGHT"]["value"]
        character_data["lightString"] = "{:,d}".format(character_data["light"])
        character_data["grimoire"] = extra_data["grimoireScore"]
        character_data["grimoireString"] = "{:,d}".format(character_data["grimoire"])
        character_data["minutesPlayed"] = int(extra_data["minutesPlayedTotal"])
        character_data["minutesPlayedString"] = "{:,d}".format(character_data["minutesPlayed"])
        character_data["lastSeen"] = extra_data["dateLastPlayed"]
        character_data["lastSeenString"] = datetime.datetime.strptime(extra_data["dateLastPlayed"], "%Y-%m-%dT%H:%M:%SZ").strftime("%B %d, %I:%M%p")
      except:
        pass

      characters[platform].append(character_data)
开发者ID:glacials,项目名称:destiny,代码行数:53,代码来源:app.py


示例6: request_done

        def request_done(response):
            def _raise_error(body):
                exceptions.raise_exceptions(response.code, body)
                return body

            return treq.json_content(response.original).addCallback(
                _raise_error)
开发者ID:aalex,项目名称:txes2,代码行数:7,代码来源:connection_http.py


示例7: _fetch_ticket

 def _fetch_ticket(self, ticket):
     """
     Fetch a ticket representation from CouchDB.
     """
     url = '''%(scheme)s%(host)s:%(port)s/%(db)s/_design/views/_view/get_ticket''' % {
         'scheme': self._scheme,
         'host': self._couch_host,
         'port': self._couch_port,
         'db': self._couch_db}
     url = url.encode('utf-8')
     params = {'key': json.dumps(ticket.encode('utf-8'))}
     self.debug("[DEBUG][CouchDB] _fetch_ticket(), url: %s" % url)
     self.debug("[DEBUG][CouchDB] _fetch_ticket(), params: %s" % str(params))
     httpClient = self.httpClientFactory(self.reactor)
     response = yield httpClient.get(url, 
                 params=params, 
                 headers=Headers({'Accept': ['application/json']}),
                 auth=(self._couch_user, self._couch_passwd))
     response = yield http_status_filter(response, [(200,200)], CouchDBError)
     doc = yield treq.json_content(response)
     rows = doc[u'rows']
     if len(rows) > 0:
         entry = rows[0][u'value']
         entry[u'expires'] = parse_date(entry[u'expires'])
         if u'pgts' in entry:
             entry[u'pgts'] = set(entry[u'pgts'])
         defer.returnValue(entry)
     defer.returnValue(None)
开发者ID:cwaldbieser,项目名称:txcas,代码行数:28,代码来源:couchdb_ticket_store.py


示例8: test_add_load_balancer_with_nodes

 def test_add_load_balancer_with_nodes(self):
     """
     Test to verify :func:`add_load_balancer` on ``POST /v1.0/<tenant_id>/loadbalancers``,
     with nodes
     """
     lb_name = 'mimic_lb'
     create_lb = request(
         self, self.root, "POST", self.uri + '/loadbalancers',
         json.dumps({
             "loadBalancer": {
                 "name": lb_name,
                 "protocol": "HTTP",
                 "virtualIps": [{"type": "PUBLIC"}],
                 "nodes": [{"address": "127.0.0.2",
                            "port": 80,
                            "condition": "ENABLED",
                            "type": "PRIMARY"},
                           {"address": "127.0.0.0",
                            "port": 80,
                            "condition": "ENABLED",
                            "type": "SECONDARY"}]
             }
         })
     )
     create_lb_response = self.successResultOf(create_lb)
     create_lb_response_body = self.successResultOf(treq.json_content(create_lb_response))
     self.assertEqual(create_lb_response.code, 202)
     self.assertEqual(len(create_lb_response_body['loadBalancer']['nodes']), 2)
开发者ID:lvh,项目名称:mimic,代码行数:28,代码来源:test_loadbalancer.py


示例9: test_get_server_ips

 def test_get_server_ips(self):
     """
     Test to verify :func:`get_ips` on ``GET /v2.0/<tenant_id>/servers/<server_id>/ips``
     """
     get_server_ips = request(self, self.root, "GET",
                              self.uri + '/servers/' + self.server_id + '/ips')
     get_server_ips_response = self.successResultOf(get_server_ips)
     get_server_ips_response_body = self.successResultOf(
         treq.json_content(get_server_ips_response))
     self.assertEqual(get_server_ips_response.code, 200)
     list_servers_detail = request(self, self.root, "GET", self.uri + '/servers/detail')
     list_servers_detail_response = self.successResultOf(list_servers_detail)
     list_servers_detail_response_body = self.successResultOf(
         treq.json_content(list_servers_detail_response))
     self.assertEqual(get_server_ips_response_body['addresses'],
                      list_servers_detail_response_body['servers'][0]['addresses'])
开发者ID:proverma,项目名称:mimic,代码行数:16,代码来源:test_nova.py


示例10: setUp

 def setUp(self):
     """
     Create a :obj:`MimicCore` with :obj:`QueueApi` as the only plugin,
     and create a queue
     """
     self.clock = Clock()
     self.core = MimicCore(self.clock, [QueueApi()])
     self.root = MimicRoot(self.core).app.resource()
     self.response = request(
         self, self.root, b"POST", "/identity/v2.0/tokens",
         json.dumps({
             "auth": {
                 "passwordCredentials": {
                     "username": "testQueue",
                     "password": "testQueuePassword",
                 },
             }
         }).encode("utf-8")
     )
     self.auth_response = self.successResultOf(self.response)
     self.json_body = self.successResultOf(
         treq.json_content(self.auth_response))
     self.uri = self.json_body['access']['serviceCatalog'][0]['endpoints'][0]['publicURL']
     self.queue_name = "test_queue"
     self.create_queue = request(
         self, self.root, b"PUT", self.uri + '/queues/' + self.queue_name)
     self.create_queue_response = self.successResultOf(self.create_queue)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:27,代码来源:test_queue.py


示例11: lookup_timezone

def lookup_timezone(loc, api_key=''):
    """
    Determine the timezone of a lat/long pair.

    @param loc: lat/long coordinates of a location
    @type loc: dict
    @type api_key: str

    @rtype: defer.Deferred yielding a second offset representing the timezone
    """
    try:
        res = yield treq.get(("https://maps.googleapis.com/maps/api/timezone/json"),
                             params={'location': str(loc['lat']) + ',' + str(loc['lng']),
                                     'timestamp': str(now_in_utc_secs()), 'sensor': 'false', 'key': api_key})
        if res and res.code == 200:
            data = yield treq.json_content(res)
            if data['status'] == 'OK':
                # API returned timezone info. What we care about: rawOffset
                defer.returnValue(int(data['rawOffset'])+int(data['dstOffset']))
            else:
                log.warn("Bad status response from Google Geocode API: %s" % (data['status']))
        elif res is not None:
            log.warn("Bad HTTP status from Google Timezone API: %s" % (res.code))
    except TypeError:
        log.warn("Bad lat/long parameter passed to lookup_timezone: %s" % (loc), exc_info=True)
开发者ID:goudacoin,项目名称:twobitbot,代码行数:25,代码来源:googleapis.py


示例12: lookup_geocode

def lookup_geocode(location, api_key=''):
    """
    Determine the lat/long coordinates for a location name.

    :param location: location name
    :type location: str
    :type api_key: str

    :return: a dict with keys 'lat', 'lng', 'loc' that contain
     the lat/long coordinates and placename for the location.
    :rtype: defer.Deferred
    """
    try:
        res = yield treq.get("http://maps.googleapis.com/maps/api/geocode/json",
                             params={'address': location, 'sensor': 'false', 'key': api_key})
        if res and res.code == 200:
            data = yield treq.json_content(res)
            if data['status'] == 'OK':
                # API returned at least one geocode
                ret = data['results'][0]['geometry']['location']
                ret['loc'] = data['results'][0]['formatted_address']
                defer.returnValue(ret)
            else:
                log.warn("Bad status response from Google Geocode API: %s" % (data['status']))
        elif res is not None:
            log.warn("Bad HTTP status from Google Geocode API: %s" % (res.code))
    except TypeError:
        log.warn("Bad location passed to lookup_geocode", exc_info=True)
开发者ID:goudacoin,项目名称:twobitbot,代码行数:28,代码来源:googleapis.py


示例13: setUp

 def setUp(self):
     """
     Create a :obj:`MimicCore` with :obj:`LoadBalancerApi` as the only plugin.
     And create a load balancer and add nodes to the load balancer.
     """
     helper = APIMockHelper(self, [LoadBalancerApi()])
     self.root = helper.root
     self.uri = helper.uri
     create_lb = request(
         self, self.root, "POST", self.uri + '/loadbalancers',
         json.dumps({
             "loadBalancer": {
                 "name": "test_lb",
                 "protocol": "HTTP",
                 "virtualIps": [{"type": "PUBLIC"}]
             }
         })
     )
     create_lb_response = self.successResultOf(create_lb)
     self.create_lb_response_body = self.successResultOf(treq.json_content(
                                                         create_lb_response))
     self.lb_id = self.create_lb_response_body["loadBalancer"]["id"]
     create_node = self._create_nodes(["127.0.0.1"])
     [(self.create_node_response, self.create_node_response_body)] = create_node
     self.node = self.create_node_response_body["nodes"]
开发者ID:reaperhulk,项目名称:mimic,代码行数:25,代码来源:test_loadbalancer.py


示例14: got_result

 def got_result(result):
     if result.code == success_code:
         return json_content(result)
     else:
         d = content(result)
         d.addCallback(error, result.code)
         return d
开发者ID:jeromeshi,项目名称:flocker,代码行数:7,代码来源:_client.py


示例15: test_basic_auth

 def test_basic_auth(self):
     response = yield self.get("/basic-auth/treq/treq", auth=("treq", "treq"))
     self.assertEqual(response.code, 200)
     yield print_response(response)
     json = yield treq.json_content(response)
     self.assertTrue(json["authenticated"])
     self.assertEqual(json["user"], "treq")
开发者ID:rakiru,项目名称:treq,代码行数:7,代码来源:test_treq_integration.py


示例16: lookupClan

def lookupClan(name):
  response = yield treq.post("http://www.bungie.net/Platform/Group/Search/", data=json.dumps({
    "contents": {
      "searchValue": name
    },
    "currentPage": 1,
    "itemsPerPage": 1
  }))
  data = yield treq.json_content(response)

  if data["Response"]["results"]:
    clan = data["Response"]["results"][0]["detail"]
    if clan["memberCount"] > 1000:
      returnValue({
        "id": 0,
        "name": '"{}" is too big'.format(clan["name"]),
        "motto": "Clans with over 1,000 members can't be processed",
      })
    else:
      returnValue({
        "id": int(clan["groupId"]),
        "name": clan["name"],
        "motto": HTMLParser.HTMLParser().unescape(clan["about"]),
      })
  else:
    returnValue({
      "id": 0,
      "name": "No Clan Found",
      "motto": "Better luck next time"
    })
开发者ID:Fugiman,项目名称:destiny,代码行数:30,代码来源:app.py


示例17: lookupMembers

def lookupMembers(id):
  page = 1
  hasMore = True if id else False
  members = []
  characters = {
    "playstation": [],
    "xbox": []
  }
  deferreds = []

  while hasMore:
    # No idea what is different between V1, V2, and V3...
    response = yield treq.get("http://www.bungie.net/Platform/Group/{!s}/MembersV3/".format(id), params={
      "itemsPerPage": 50,
      "currentPage": page
    })
    data = yield treq.json_content(response)
    page += 1
    hasMore = data["Response"]["hasMore"]
    members.extend(data["Response"]["results"])

  # Load character data in parallel
  for member in members:
    deferreds.append(lookupCharacters(member, characters))
  yield DeferredList(deferreds, fireOnOneErrback=True, consumeErrors=True)

  for platform_characters in characters.values():
    platform_characters.sort(key=lambda c: (c["level"], c["light"]), reverse=True)

  returnValue(characters)
开发者ID:Fugiman,项目名称:destiny,代码行数:30,代码来源:app.py


示例18: test_delete_server_fails_specified_number_of_times

 def test_delete_server_fails_specified_number_of_times(self):
     """
     Test to verify :func: `delete_server` does not delete the server,
     and returns the given response code, the number of times specified
     in the metadata
     """
     deletefail = {"times": 1, "code": 500}
     metadata = {"delete_server_failure": json.dumps(deletefail)}
     # create server and verify it was successful
     create_server_response = self.create_server(metadata=metadata)
     self.assertEquals(create_server_response.code, 202)
     create_server_response_body = self.successResultOf(
         treq.json_content(create_server_response))
     # delete server and verify the response
     delete_server = request(self, self.root, "DELETE", self.uri + '/servers/'
                             + create_server_response_body["server"]["id"])
     delete_server_response = self.successResultOf(delete_server)
     self.assertEqual(delete_server_response.code, 500)
     # get server and verify the server was not deleted
     get_server = request(self, self.root, "GET", self.uri + '/servers/' +
                          create_server_response_body["server"]["id"])
     get_server_response = self.successResultOf(get_server)
     self.assertEquals(get_server_response.code, 200)
     # delete server again and verify the response
     delete_server = request(self, self.root, "DELETE", self.uri + '/servers/'
                             + create_server_response_body["server"]["id"])
     delete_server_response = self.successResultOf(delete_server)
     self.assertEqual(delete_server_response.code, 204)
     self.assertEqual(self.successResultOf(treq.content(delete_server_response)),
                      b"")
     # get server and verify the server was deleted this time
     get_server = request(self, self.root, "GET", self.uri + '/servers/' +
                          create_server_response_body["server"]["id"])
     get_server_response = self.successResultOf(get_server)
     self.assertEquals(get_server_response.code, 404)
开发者ID:lvh,项目名称:mimic,代码行数:35,代码来源:test_nova.py


示例19: test_delete

 def test_delete(self):
     response = yield self.delete("/delete")
     self.assertEqual(response.code, OK)
     data = yield treq.json_content(response)
     self.assertIsInstance(data, dict)
     self.assertEqual(data["headers"]["User-Agent"], USERAGENT)
     self.assertIsNone(data["json"])
开发者ID:xlhtc007,项目名称:pyfarm-agent,代码行数:7,代码来源:test_http_core_client.py


示例20: test_get_container

 def test_get_container(self):
     """
     Creating a container and immediately retrieving it yields an empty list
     (since there are no objects) and several headers indicating that no
     objects are in the container and they consume no space.
     """
     self.createSwiftService()
     # create a container
     uri = (self.json_body['access']['serviceCatalog'][0]['endpoints'][0]
            ['publicURL'] + '/testcontainer').encode("ascii")
     create_container = request(self, self.root, b"PUT", uri)
     self.successResultOf(create_container)
     container_response = self.successResultOf(
         request(self, self.root, b"GET", uri)
     )
     self.assertEqual(container_response.code, 200)
     container_contents = self.successResultOf(
         treq.json_content(container_response)
     )
     self.assertEqual(container_contents, [])
     self.assertEqual(
         container_response.headers.getRawHeaders(
             b"X-Container-Object-Count")[0], b"0"
     )
     self.assertEqual(
         container_response.headers.getRawHeaders(
             b"X-Container-Bytes-Used")[0], b"0"
     )
开发者ID:derwolfe,项目名称:mimic,代码行数:28,代码来源:test_swift.py



注:本文中的treq.json_content函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python treq.post函数代码示例发布时间:2022-05-27
下一篇:
Python treq.get函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap