当前位置: 首页>>代码示例>>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;未经允许,请勿转载。