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


Python PreparedRequest.prepare方法代碼示例

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


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

示例1: test_prepared_copy

# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_prepared_copy(kwargs):
    p = PreparedRequest()
    if kwargs:
        p.prepare(**kwargs)
    copy = p.copy()
    for attr in ('method', 'url', 'headers', '_cookies', 'body', 'hooks'):
        assert getattr(p, attr) == getattr(copy, attr)
開發者ID:503945930,項目名稱:requests,代碼行數:9,代碼來源:test_requests.py

示例2: test_no_keep_alive_by_default

# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
 def test_no_keep_alive_by_default(self):
     p = PreparedRequest()
     p.prepare(
         method='GET',
         url='http://www.example.com',
         hooks=default_hooks()
     )
     assert 'Connection' not in p.headers
開發者ID:tychotatitscheff,項目名稱:requests,代碼行數:10,代碼來源:test_requests.py

示例3: test_data_argument_accepts_tuples

# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_data_argument_accepts_tuples(list_of_tuples):
    """
    Ensure that the data argument will accept tuples of strings
    and properly encode them.
    """
    for data in list_of_tuples:
        p = PreparedRequest()
        p.prepare(method="GET", url="http://www.example.com", data=data, hooks=default_hooks())
        assert p.body == urlencode(data)
開發者ID:RRedwards,項目名稱:requests,代碼行數:11,代碼來源:test_requests.py

示例4: test_prepared_request_no_cookies_copy

# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_prepared_request_no_cookies_copy():
    p = PreparedRequest()
    p.prepare(
        method='GET',
        url='http://www.example.com',
        data='foo=bar',
        hooks=default_hooks()
    )
    assert_copy(p, p.copy())
開發者ID:Hammad04,項目名稱:payeezy_direct_API,代碼行數:11,代碼來源:test_requests.py

示例5: test_data_argument_accepts_tuples

# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_data_argument_accepts_tuples(data):
    """Ensure that the data argument will accept tuples of strings
    and properly encode them.
    """
    p = PreparedRequest()
    p.prepare(
        method='GET',
        url='http://www.example.com',
        data=data,
        hooks=default_hooks()
    )
    assert p.body == urlencode(data)
開發者ID:503945930,項目名稱:requests,代碼行數:14,代碼來源:test_requests.py

示例6: prepare_request

# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
    def prepare_request(self, request):
        """Constructs a :class:`PreparedRequest <PreparedRequest>` for
        transmission and returns it. The :class:`PreparedRequest` has settings
        merged from the :class:`Request <Request>` instance and those of the
        :class:`Session`.

        :param request: :class:`Request` instance to prepare with this
                        session's settings.
        """
        cookies = request.cookies or {}

        # Bootstrap CookieJar.
        if not isinstance(cookies, cookielib.CookieJar):
            cookies = cookiejar_from_dict(cookies)

        # Merge with session cookies
        merged_cookies = RequestsCookieJar()
        merged_cookies.update(self.cookies)
        merged_cookies.update(cookies)


        # Set environment's basic authentication if not explicitly set.
        auth = request.auth
        if self.trust_env and not auth and not self.auth:
            auth = get_netrc_auth(request.url)

        p = PreparedRequest()
        p.prepare(
            method=request.method.upper(),
            url=request.url,
            files=request.files,
            data=request.data,
            json=request.json,
            headers=merge_setting(request.headers, self.headers, dict_class=CaseInsensitiveDict),
            params=merge_setting(request.params, self.params),
            auth=merge_setting(auth, self.auth),
            cookies=merged_cookies,
            hooks=merge_hooks(request.hooks, self.hooks),
        )
        return p
開發者ID:P4ncake,項目名稱:weboob,代碼行數:42,代碼來源:sessions.py

示例7: test_prepared_request_complete_copy

# 需要導入模塊: from requests.models import PreparedRequest [as 別名]
# 或者: from requests.models.PreparedRequest import prepare [as 別名]
def test_prepared_request_complete_copy():
    p = PreparedRequest()
    p.prepare(method="GET", url="http://www.example.com", data="foo=bar", hooks=default_hooks(), cookies={"foo": "bar"})
    assert_copy(p, p.copy())
開發者ID:RRedwards,項目名稱:requests,代碼行數:6,代碼來源:test_requests.py


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