當前位置: 首頁>>代碼示例>>Python>>正文


Python treq.post方法代碼示例

本文整理匯總了Python中treq.post方法的典型用法代碼示例。如果您正苦於以下問題:Python treq.post方法的具體用法?Python treq.post怎麽用?Python treq.post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在treq的用法示例。


在下文中一共展示了treq.post方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_container

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def create_container(self, properties):
        """
        Create a container with the specified properties.

        :param dict properties: A ``dict`` mapping to the API request fields
            to create a container.

        :returns: A ``Deferred`` which fires with an API response when the
            container with the supplied properties has been persisted to the
            cluster configuration.
        """
        request = self.treq.post(
            self.base_url + b"/configuration/containers",
            data=dumps(properties),
            headers={b"content-type": b"application/json"},
        )

        request.addCallback(check_and_decode_json, CREATED)
        return request 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:21,代碼來源:testtools.py

示例2: move_container

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def move_container(self, name, node_uuid):
        """
        Move a container.

        :param unicode name: The name of the container to move.
        :param unicode node_uuid: The UUID to which the container should
            be moved.
        :returns: A ``Deferred`` which fires with an API response when the
            container move has been persisted to the cluster configuration.
        """
        request = self.treq.post(
            self.base_url + b"/configuration/containers/" +
            name.encode("ascii"),
            data=dumps({u"node_uuid": node_uuid}),
            headers={b"content-type": b"application/json"},
        )

        request.addCallback(check_and_decode_json, OK)
        return request 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:21,代碼來源:testtools.py

示例3: unlink

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def unlink(self, dircap, childname):
        dircap_hash = trunchash(dircap)
        log.debug('Unlinking "%s" from %s...', childname, dircap_hash)
        yield self.await_ready()
        yield self.lock.acquire()
        try:
            resp = yield treq.post(
                "{}uri/{}/?t=unlink&name={}".format(
                    self.nodeurl, dircap, childname
                )
            )
        finally:
            yield self.lock.release()
        if resp.code != 200:
            content = yield treq.content(resp)
            raise TahoeWebError(content.decode("utf-8"))
        log.debug('Done unlinking "%s" from %s', childname, dircap_hash) 
開發者ID:gridsync,項目名稱:gridsync,代碼行數:19,代碼來源:tahoe.py

示例4: submit

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def submit(server_url, result):
    """
    Post the given result to the given server.

    :param str server_url: The server's URL.
    :param dict result: The JSON-compatible result.
    :return: Deferred that fires with an ID of the submitted result on success
        or with SubmitFailure if the result is rejected by the server.

    This function may also return any of the ``treq`` failures.
    """
    req = post(
        server_url + "/v1/benchmark-results",
        json.dumps(result),
        headers=({'Content-Type': ['application/json']}),
    )

    def get_response_content(response):
        d = json_content(response)
        d.addCallback(lambda content: (response, content))
        return d

    req.addCallback(get_response_content)

    def process_response(response_and_content):
        (response, content) = response_and_content
        if response.code != CREATED:
            raise SubmitFailure(response.code, response.phrase,
                                content['message'])
        else:
            return content['id']

    req.addCallback(process_response)
    return req 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:36,代碼來源:submit.py

示例5: post_http_server

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def post_http_server(test, host, port, data, expected_response=b"ok"):
    """
    Make a POST request to an HTTP server on the given host and port
    and assert that the response body matches the expected response.

    :param bytes host: Host to connect to.
    :param int port: Port to connect to.
    :param bytes data: The raw request body data.
    :param bytes expected_response: The HTTP response body expected.
        Defaults to b"ok"
    """
    def make_post(host, port, data):
        request = post(
            "http://{host}:{port}".format(host=host, port=port),
            data=data,
            timeout=SOCKET_TIMEOUT_FOR_POLLING,
            persistent=False,
        )

        def failed(failure):
            Message.new(message_type=u"acceptance:http_query_failed",
                        reason=unicode(failure)).write()
            return False
        request.addCallbacks(content, failed)
        return request
    d = verify_socket(host, port)
    d.addCallback(lambda _: loop_until(reactor, lambda: make_post(
        host, port, data)))
    d.addCallback(test.assertEqual, expected_response)
    return d 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:32,代碼來源:testtools.py

示例6: check_response

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def check_response(self, response):
    return stethoscope.api.utils.check_response(response, service=self.plugin_name, resource='post') 
開發者ID:Netflix-Skunkworks,項目名稱:stethoscope,代碼行數:4,代碼來源:deferred_http.py

示例7: _post

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def _post(self, url, content, **kwargs):
    return txwebretry.ExponentialBackoffRetry(3)(treq.post, url, content, **kwargs) 
開發者ID:Netflix-Skunkworks,項目名稱:stethoscope,代碼行數:4,代碼來源:deferred_http.py

示例8: post

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def post(self, payload, **kwargs):
    """Execute a POST request to the object's URL, returning a deferred with a `treq` Response."""
    url, content, kwargs = self._process_arguments(payload, **kwargs)

    deferred = self._post(url, content, **kwargs)
    deferred.addCallback(self.check_response)
    deferred.addCallback(treq.content)
    deferred.addErrback(self.log_error)

    return deferred 
開發者ID:Netflix-Skunkworks,項目名稱:stethoscope,代碼行數:12,代碼來源:deferred_http.py

示例9: mkdir

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def mkdir(self, parentcap=None, childname=None):
        yield self.await_ready()
        url = self.nodeurl + "uri"
        params = {"t": "mkdir"}
        if parentcap and childname:
            url += "/" + parentcap
            params["name"] = childname
        resp = yield treq.post(url, params=params)
        if resp.code == 200:
            content = yield treq.content(resp)
            return content.decode("utf-8").strip()
        raise TahoeWebError(
            "Error creating Tahoe-LAFS directory: {}".format(resp.code)
        ) 
開發者ID:gridsync,項目名稱:gridsync,代碼行數:16,代碼來源:tahoe.py

示例10: link

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def link(self, dircap, childname, childcap):
        dircap_hash = trunchash(dircap)
        childcap_hash = trunchash(childcap)
        log.debug(
            'Linking "%s" (%s) into %s...',
            childname,
            childcap_hash,
            dircap_hash,
        )
        yield self.await_ready()
        yield self.lock.acquire()
        try:
            resp = yield treq.post(
                "{}uri/{}/?t=uri&name={}&uri={}".format(
                    self.nodeurl, dircap, childname, childcap
                )
            )
        finally:
            yield self.lock.release()
        if resp.code != 200:
            content = yield treq.content(resp)
            raise TahoeWebError(content.decode("utf-8"))
        log.debug(
            'Done linking "%s" (%s) into %s',
            childname,
            childcap_hash,
            dircap_hash,
        ) 
開發者ID:gridsync,項目名稱:gridsync,代碼行數:30,代碼來源:tahoe.py

示例11: get_magic_folder_status

# 需要導入模塊: import treq [as 別名]
# 或者: from treq import post [as 別名]
def get_magic_folder_status(self, name):
        if not self.nodeurl or not self.api_token:
            return None
        try:
            resp = yield treq.post(
                self.nodeurl + "magic_folder",
                {"token": self.api_token, "name": name, "t": "json"},
            )
        except ConnectError:
            return None
        if resp.code == 200:
            content = yield treq.content(resp)
            return json.loads(content.decode("utf-8"))
        return None 
開發者ID:gridsync,項目名稱:gridsync,代碼行數:16,代碼來源:tahoe.py


注:本文中的treq.post方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。