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


Python models.PreparedRequest類代碼示例

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


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

示例1: deserialize_prepared_request

def deserialize_prepared_request(serialized):
    p = PreparedRequest()
    p.body = serialized['body']
    p.headers = CaseInsensitiveDict(serialized['headers'])
    p.method = serialized['method']
    p.url = serialized['uri']
    return p
開發者ID:pombredanne,項目名稱:betamax,代碼行數:7,代碼來源:cassette.py

示例2: test_prepared_copy

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,代碼行數:7,代碼來源:test_requests.py

示例3: check_url

def check_url(url):
    prepared_request = PreparedRequest()
    try:
        prepared_request.prepare_url(url, None)
        return True
    except requests.exceptions.MissingSchema:
        return False
開發者ID:tehnotcpu,項目名稱:CirnoBot,代碼行數:7,代碼來源:utils.py

示例4: test_no_keep_alive_by_default

 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,代碼行數:8,代碼來源:test_requests.py

示例5: test_data_argument_accepts_tuples

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,代碼行數:9,代碼來源:test_requests.py

示例6: test_prepared_request_no_cookies_copy

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,代碼行數:9,代碼來源:test_requests.py

示例7: test_data_argument_accepts_tuples

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,代碼行數:12,代碼來源:test_requests.py

示例8: oauth_access_token_url

    def oauth_access_token_url(self):
        """Generate the OAuth access token url."""

        url = self._access_token_url.format(base_url=self.base_url)

        params = [
            ('client_id', self.credentials.api_key),
            ('client_secret', self.credentials.secret),
            ('code', self.credentials.code)
        ]

        parser = PreparedRequest()
        parser.prepare_url(url=url, params=params)

        return parser.url
開發者ID:RafaAguilar,項目名稱:shopify-trois,代碼行數:15,代碼來源:oauth_engine.py

示例9: _format_args

    def _format_args(self):
        """將params/data的數據拚接在url裏 """
        if not self.record_params:
            return ''

        args_text = ""
        try:
            sign = "&" if '?' in self.url else "?"
            if self.params:
                args_text = sign + PreparedRequest._encode_params(self.params)
            elif self.data:
                args_text = sign + PreparedRequest._encode_params(self.data)
        except:
            pass

        return args_text
開發者ID:a1401358759,項目名稱:my_site,代碼行數:16,代碼來源:client.py

示例10: oauth_authorize_url

    def oauth_authorize_url(self, redirect_to=None):
        """Generates the oauth authorize url.

        :param redirect_to: URL shopify will redirect to once authorized.
        """

        url = self._authorize_url.format(base_url=self.base_url)

        params = [
            ('client_id', self.credentials.api_key),
            ('scope', ",".join(self.credentials.scope)),
            ('redirect_uri', redirect_to)
        ]

        request = PreparedRequest()
        request.prepare_url(url=url, params=params)

        return request.url
開發者ID:RafaAguilar,項目名稱:shopify-trois,代碼行數:18,代碼來源:oauth_engine.py

示例11: prepare_request

    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,代碼行數:40,代碼來源:sessions.py

示例12: copy_request

def copy_request(request):
    """Copy a Requests PreparedRequest."""
    new_request = PreparedRequest()

    new_request.method = request.method
    new_request.url = request.url
    new_request.body = request.body
    new_request.hooks = request.hooks
    new_request.headers = request.headers.copy()

    return new_request
開發者ID:mdengler,項目名稱:requests-ntlm,代碼行數:11,代碼來源:requests_ntlm.py

示例13: deserialize_prepared_request

def deserialize_prepared_request(serialized):
    p = PreparedRequest()
    p._cookies = RequestsCookieJar()
    body = serialized['body']
    if isinstance(body, dict):
        original_body = body.get('string')
        p.body = original_body or base64.b64decode(
            body.get('base64_string', '').encode())
    else:
        p.body = body
    h = [(k, from_list(v)) for k, v in serialized['headers'].items()]
    p.headers = CaseInsensitiveDict(h)
    p.method = serialized['method']
    p.url = serialized['uri']
    return p
開發者ID:bboe,項目名稱:betamax,代碼行數:15,代碼來源:util.py

示例14: load_resource

    def load_resource(self, cdx, params):
        load_url = cdx.get('load_url')
        if not load_url:
            return None

        if params.get('content_type') == VideoLoader.CONTENT_TYPE:
            return None

        input_req = params['_input_req']

        req_headers = input_req.get_req_headers()

        dt = timestamp_to_datetime(cdx['timestamp'])

        if cdx.get('memento_url'):
            req_headers['Accept-Datetime'] = datetime_to_http_date(dt)

        method = input_req.get_req_method()
        data = input_req.get_req_body()

        p = PreparedRequest()
        p.prepare_url(load_url, None)
        p.prepare_headers(None)
        p.prepare_auth(None, load_url)

        auth = p.headers.get('Authorization')
        if auth:
            req_headers['Authorization'] = auth

        load_url = p.url

        try:
            upstream_res = self.pool.urlopen(method=method,
                                             url=load_url,
                                             body=data,
                                             headers=req_headers,
                                             redirect=False,
                                             assert_same_host=False,
                                             preload_content=False,
                                             decode_content=False,
                                             retries=self.num_retries,
                                             timeout=params.get('_timeout'))

        except Exception as e:
            raise LiveResourceException(load_url)

        memento_dt = upstream_res.headers.get('Memento-Datetime')
        if memento_dt:
            dt = http_date_to_datetime(memento_dt)
            cdx['timestamp'] = datetime_to_timestamp(dt)
        elif cdx.get('memento_url'):
        # if 'memento_url' set and no Memento-Datetime header present
        # then its an error
            return None

        agg_type = upstream_res.headers.get('WebAgg-Type')
        if agg_type == 'warc':
            cdx['source'] = unquote(upstream_res.headers.get('WebAgg-Source-Coll'))
            return None, upstream_res.headers, upstream_res

        self.raise_on_self_redirect(params, cdx,
                                    str(upstream_res.status),
                                    upstream_res.headers.get('Location'))


        if upstream_res.version == 11:
            version = '1.1'
        else:
            version = '1.0'

        status = 'HTTP/{version} {status} {reason}\r\n'
        status = status.format(version=version,
                               status=upstream_res.status,
                               reason=upstream_res.reason)

        http_headers_buff = status

        orig_resp = upstream_res._original_response

        try:  #pragma: no cover
        #PY 3
            resp_headers = orig_resp.headers._headers
            for n, v in resp_headers:
                if n.lower() in self.SKIP_HEADERS:
                    continue

                http_headers_buff += n + ': ' + v + '\r\n'
        except:  #pragma: no cover
        #PY 2
            resp_headers = orig_resp.msg.headers
            for n, v in zip(orig_resp.getheaders(), resp_headers):
                if n in self.SKIP_HEADERS:
                    continue

                http_headers_buff += v

        http_headers_buff += '\r\n'
        http_headers_buff = http_headers_buff.encode('latin-1')

        try:
#.........這裏部分代碼省略.........
開發者ID:ikreymer,項目名稱:webrec-platform,代碼行數:101,代碼來源:responseloader.py

示例15: _request_url

 def _request_url(cls, url, params):
     pre = PreparedRequest()
     pre.prepare_url(url, params)
     return pre.url
開發者ID:qq40660,項目名稱:ChinaAPI,代碼行數:4,代碼來源:api.py


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