当前位置: 首页>>代码示例>>Python>>正文


Python dump.dump_all方法代码示例

本文整理汇总了Python中requests_toolbelt.utils.dump.dump_all方法的典型用法代码示例。如果您正苦于以下问题:Python dump.dump_all方法的具体用法?Python dump.dump_all怎么用?Python dump.dump_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在requests_toolbelt.utils.dump的用法示例。


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

示例1: request

# 需要导入模块: from requests_toolbelt.utils import dump [as 别名]
# 或者: from requests_toolbelt.utils.dump import dump_all [as 别名]
def request(self, method, url, *args, **kwargs):

        response = None
        use_cache = not self.no_cache and self._cache_responses
        if use_cache:
            logger.debug("getting cached response fsesor %s" %(url))
            self.cursor.execute(
                "SELECT response, last_seen "
                "FROM response_cache "
                "WHERE url = ?",
                (url,)
            )
            try:
                (pickled_response, last_seen) = self.cursor.fetchone()
                td = datetime.now() - last_seen
                if td.seconds >= self._cache_responses:
                    logger.debug("cache expired for %s" %(url))
                else:
                    response = pickle.loads(pickled_response)
                    logger.debug("using cached response for %s" %(url))
            except TypeError:
                logger.debug("no cached response for %s" %(url))

        # if not response:
        #     response = method(url, *args, **kwargs)
        #     logger.trace(dump.dump_all(response).decode("utf-8"))
        if use_cache:
            pickled_response = pickle.dumps(response)
            sql="""INSERT OR REPLACE
            INTO response_cache (url, response, last_seen)
            VALUES (?, ?, ?)"""
            self.cursor.execute(
                sql,
                (url, pickled_response, datetime.now())
            )
            self.conn.commit()

        return response 
开发者ID:tonycpsu,项目名称:mlbstreamer,代码行数:40,代码来源:session.py

示例2: debugRequest

# 需要导入模块: from requests_toolbelt.utils import dump [as 别名]
# 或者: from requests_toolbelt.utils.dump import dump_all [as 别名]
def debugRequest(req):
        try:
            print(dump.dump_all(req).decode('utf-8'))
        except ValueError as e:
            print("Debug Error: {}".format(getattr(e, 'message', e)))

    # ------------------------------------------------------------------------------- #
    # Unescape / decode html entities
    # ------------------------------------------------------------------------------- # 
开发者ID:alfa-addon,项目名称:addon,代码行数:11,代码来源:__init__.py

示例3: dump_all

# 需要导入模块: from requests_toolbelt.utils import dump [as 别名]
# 或者: from requests_toolbelt.utils.dump import dump_all [as 别名]
def dump_all(response, request_prefix=b'< ', response_prefix=b'> '):
    """Dump all requests and responses including redirects.

    This takes the response returned by requests and will dump all
    request-response pairs in the redirect history in order followed by the
    final request-response.

    Example::

        import requests
        from requests_toolbelt.utils import dump

        resp = requests.get('https://httpbin.org/redirect/5')
        data = dump.dump_all(resp)
        print(data.decode('utf-8'))

    :param response:
        The response to format
    :type response: :class:`requests.Response`
    :param request_prefix: (*optional*)
        Bytes to prefix each line of the request data
    :type request_prefix: :class:`bytes`
    :param response_prefix: (*optional*)
        Bytes to prefix each line of the response data
    :type response_prefix: :class:`bytes`
    :returns: Formatted bytes of request and response information.
    :rtype: :class:`bytearray`
    """
    data = bytearray()

    history = list(response.history[:])
    history.append(response)

    for response in history:
        dump_response(response, request_prefix, response_prefix, data)

    return data 
开发者ID:alfa-addon,项目名称:addon,代码行数:39,代码来源:dump.py

示例4: _dump_request

# 需要导入模块: from requests_toolbelt.utils import dump [as 别名]
# 或者: from requests_toolbelt.utils.dump import dump_all [as 别名]
def _dump_request(response):
    data = dump.dump_all(response)
    try:
        logger.trace(data.decode())
    except Exception:
        data = str(data).replace('\\r\\n', '\r\n')
        logger.trace(data) 
开发者ID:abertschi,项目名称:postcard_creator_wrapper,代码行数:9,代码来源:postcard_creator.py

示例5: log_request_response

# 需要导入模块: from requests_toolbelt.utils import dump [as 别名]
# 或者: from requests_toolbelt.utils.dump import dump_all [as 别名]
def log_request_response(resp, *args, **kwargs):
    if resp.url.startswith(config.api_server):
        return  # k8s library already does its own dumping, we don't need to do it here
    log = logging.getLogger(__name__)
    data = dump_all(resp, "<<<", ">>>")
    log.debug("Request/Response\n" + data) 
开发者ID:fiaas,项目名称:fiaas-deploy-daemon,代码行数:8,代码来源:tools.py

示例6: _log_response

# 需要导入模块: from requests_toolbelt.utils import dump [as 别名]
# 或者: from requests_toolbelt.utils.dump import dump_all [as 别名]
def _log_response(self, response, message):
        try:
            msg = "[{}] {} | {} {}".format(response.request.method, message, response.status_code, response.reason)
            if response.status_code == requests.codes.ok or response.status_code >= requests.codes.server_error:
                self.log(msg)
            else:
                self.log("{} ({})".format(msg, response.json()["errors"]), level=logging.ERROR)
            self._logger.debug("DUMP:\n{}".format(dump.dump_all(response).decode("utf-8")))
        except (UnicodeDecodeError, JSONDecodeError) as e:
            self._logger.debug("DUMP:\nImpossible to decode.") 
开发者ID:cytomine,项目名称:Cytomine-python-client,代码行数:12,代码来源:cytomine.py

示例7: debugRequest

# 需要导入模块: from requests_toolbelt.utils import dump [as 别名]
# 或者: from requests_toolbelt.utils.dump import dump_all [as 别名]
def debugRequest(req):
        try:
            print(dump.dump_all(req).decode('utf-8'))
        except:  # noqa
            pass

    ########################################################################################################################################################## 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:9,代码来源:__init__.py

示例8: dump_response

# 需要导入模块: from requests_toolbelt.utils import dump [as 别名]
# 或者: from requests_toolbelt.utils.dump import dump_all [as 别名]
def dump_response(self, response):
        data = dump.dump_all(response)
        return str(data.decode('utf-8')) 
开发者ID:domoinc,项目名称:domo-python-sdk,代码行数:5,代码来源:Transport.py


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