• Requests 源码阅读笔记


    models.py

    class Request(RequestHooksMixin):
        def __init__(self,
                method=None, url=None, headers=None, files=None, data=None,
                params=None, auth=None, cookies=None, hooks=None, json=None):
    
            # Default empty dicts for dict params.
            data = [] if data is None else data
            files = [] if files is None else files
            headers = {} if headers is None else headers
            params = {} if params is None else params
            hooks = {} if hooks is None else hooks
    
    class Response(object):
        __attrs__ = [
            '_content', 'status_code', 'headers', 'url', 'history',
            'encoding', 'reason', 'cookies', 'elapsed', 'request'
        ]
    
        def __init__(self):
            self._content = False
            self._content_consumed = False
            self._next = None
    
            #: Integer Code of responded HTTP Status, e.g. 404 or 200.
            self.status_code = None
    
            #: Case-insensitive Dictionary of Response Headers.
            #: For example, ``headers['content-encoding']`` will return the
            #: value of a ``'Content-Encoding'`` response header.
            self.headers = CaseInsensitiveDict()
    
            #: File-like object representation of response (for advanced usage).
            #: Use of ``raw`` requires that ``stream=True`` be set on the request.
            # This requirement does not apply for use internally to Requests.
            self.raw = None
    
            #: Final URL location of Response.
            self.url = None
    
            #: Encoding to decode with when accessing r.text.
            self.encoding = None
    
            #: A list of :class:`Response <Response>` objects from
            #: the history of the Request. Any redirect responses will end
            #: up here. The list is sorted from the oldest to the most recent request.
            self.history = []
    
            #: Textual reason of responded HTTP Status, e.g. "Not Found" or "OK".
            self.reason = None
    
            #: A CookieJar of Cookies the server sent back.
            self.cookies = cookiejar_from_dict({})
    
            #: The amount of time elapsed between sending the request
            #: and the arrival of the response (as a timedelta).
            #: This property specifically measures the time taken between sending
            #: the first byte of the request and finishing parsing the headers. It
            #: is therefore unaffected by consuming the response content or the
            #: value of the ``stream`` keyword argument.
            self.elapsed = datetime.timedelta(0)
    
            #: The :class:`PreparedRequest <PreparedRequest>` object to which this
            #: is a response.
            self.request = None
    
    git grep -n requests.get tests/test_requests.py
    

    tests/confest.py

    def prepare_url(value):
        # Issue #1483: Make sure the URL always has a trailing slash
        httpbin_url = value.url.rstrip('/') + '/'
    

    place a debugger in adapters.py

    py.test test_requsts.py::TestRequests::test_DIGEST_HTTP_200_OK_GET
    
  • 相关阅读:
    英语中的合成词
    超声诊断装置的质量评价
    图像处理的数学方法zz
    超声射频信号的产生(RF Signal)
    黄帝内经——春夏秋冬养生之道zz
    超声仿真软件Field II的使用
    水木上关于超声图像增强的讨论
    TWaver HTML5 + Node.js + express + socket.io + redis(五)
    如何用Swing去绘制电力系统图
    TWaver在FTTX设备网管系统中的应用
  • 原文地址:https://www.cnblogs.com/michael-xiang/p/10468022.html
Copyright © 2020-2023  润新知