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


Python structures.CaseInsensitiveDict方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def __init__(self, url, method='get', data=None, params=None,
                 headers=None, content_type='application/json', **kwargs):
        self.url = url
        self.method = method
        self.params = params or {}
        self.kwargs = kwargs

        if not isinstance(headers, dict):
            headers = {}
        self.headers = CaseInsensitiveDict(headers)
        if content_type:
            self.headers['Content-Type'] = content_type
        if data:
            self.data = json.dumps(data)
        else:
            self.data = {} 
開發者ID:jumpserver,項目名稱:jumpserver-python-sdk,代碼行數:18,代碼來源:request.py

示例2: request

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def request(self, method, url, data=None, files=None, extra_headers=None):
        headers = CaseInsensitiveDict([
            ('Referer', HOME_PAGE),
            ('X-Requested-With', 'XMLHttpRequest'),
            ('Accept', 'application/json'),
            ('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'),
            ('User-Agent', self.user_agent)])
        csrftoken = self.http.cookies.get('csrftoken')
        if csrftoken:
            headers.update([('X-CSRFToken', csrftoken)])

        if extra_headers is not None:
            for h in extra_headers:
                headers.update([(h, extra_headers[h])])

        response = self.http.request(method, url, data=data, headers=headers, files=files, proxies=self.proxies)
        response.raise_for_status()
        self.registry.update(Registry.Key.COOKIES, response.cookies)
        return response 
開發者ID:bstoilov,項目名稱:py3-pinterest,代碼行數:21,代碼來源:Pinterest.py

示例3: __init__

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def __init__(self, method, url,
                 data=None,
                 params=None,
                 headers=None,
                 app_name=''):
        self.method = method
        self.url = url
        self.data = _convert_request_body(data)
        self.params = params or {}

        if not isinstance(headers, CaseInsensitiveDict):
            self.headers = CaseInsensitiveDict(headers)
        else:
            self.headers = headers

        # tell requests not to add 'Accept-Encoding: gzip, deflate' by default
        if 'Accept-Encoding' not in self.headers:
            self.headers['Accept-Encoding'] = None

        if 'User-Agent' not in self.headers:
            if app_name:
                self.headers['User-Agent'] = _USER_AGENT + '/' + app_name
            else:
                self.headers['User-Agent'] = _USER_AGENT 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:26,代碼來源:http.py

示例4: _network_response_received

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def _network_response_received(self, message):
        status = message['params']['response'].get('status')
        if (status == 420 and 'Warcprox-Meta' in CaseInsensitiveDict(
                message['params']['response']['headers'])):
            if not self.reached_limit:
                warcprox_meta = json.loads(CaseInsensitiveDict(
                    message['params']['response']['headers'])['Warcprox-Meta'])
                self.reached_limit = brozzler.ReachedLimit(
                        warcprox_meta=warcprox_meta)
                self.logger.info('reached limit %s', self.reached_limit)
                brozzler.thread_raise(
                        self.calling_thread, brozzler.ReachedLimit)
            else:
                self.logger.info(
                        'reached limit but self.reached_limit is already set, '
                        'assuming the calling thread is already handling this')
        if self.on_response:
            self.on_response(message)

        if status and self.page_status is None:
            self.page_status = status 
開發者ID:internetarchive,項目名稱:brozzler,代碼行數:23,代碼來源:browser.py

示例5: _prepare_request

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def _prepare_request(self, command, json=True, opcode_name='command',
                         fetch_list=False, **kwargs):
        params = CaseInsensitiveDict(**kwargs)
        params.update({
            'apiKey': self.key,
            opcode_name: command,
        })
        if json:
            params['response'] = 'json'
        if 'page' in kwargs or fetch_list:
            params.setdefault('pagesize', PAGE_SIZE)
        if 'expires' not in params and self.expiration.total_seconds() >= 0:
            params['signatureVersion'] = '3'
            tz = pytz.utc
            expires = tz.localize(datetime.utcnow() + self.expiration)
            params['expires'] = expires.astimezone(tz).strftime(EXPIRES_FORMAT)

        kind = 'params' if self.method == 'get' else 'data'
        return kind, dict(params.items()) 
開發者ID:exoscale,項目名稱:cs,代碼行數:21,代碼來源:client.py

示例6: __init__

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def __init__(self):
        self.log = logging.getLogger(__name__)

        self.plugin_parent_classes = [fossor.plugin.Plugin,
                                      fossor.variables.variable.Variable,
                                      fossor.checks.check.Check,
                                      fossor.reports.report.Report]

        # Variables
        self.variables = CaseInsensitiveDict()
        self.add_variable('timeout', 600)  # Default timeout

        # Imported Plugins
        self.variable_plugins = set()
        self.check_plugins = set()
        self.report_plugins = set()

        self.add_plugins()  # Adds all plugins located within the fossor module recursively 
開發者ID:linkedin,項目名稱:fossor,代碼行數:20,代碼來源:engine.py

示例7: build_header_for_upload_part

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def build_header_for_upload_part(self, headers=None):
        if not isinstance(headers, CaseInsensitiveDict):
            headers = CaseInsensitiveDict(headers)

        if 'content-md5' in headers:
            headers[OSS_CLIENT_SIDE_ENCRYPTION_UNENCRYPTED_CONTENT_MD5] = headers['content-md5']
            del headers['content-md5']

        if 'content-length' in headers:
            headers[OSS_CLIENT_SIDE_ENCRYPTION_UNENCRYPTED_CONTENT_LENGTH] = headers['content-length']
            del headers['content-length']

        self.plain_key = None
        self.plain_iv = None

        return headers 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:18,代碼來源:custom_crypto.py

示例8: to_object_meta

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def to_object_meta(self, headers=None, multipart_upload_context=None):
        if not isinstance(headers, CaseInsensitiveDict):
            headers = CaseInsensitiveDict(headers)

        if 'content-md5' in headers:
            headers[OSS_CLIENT_SIDE_ENCRYPTION_UNENCRYPTED_CONTENT_MD5] = headers['content-md5']
            del headers['content-md5']

        if 'content-length' in headers:
            headers[OSS_CLIENT_SIDE_ENCRYPTION_UNENCRYPTED_CONTENT_LENGTH] = headers['content-length']
            del headers['content-length']

        headers[OSS_CLIENT_SIDE_ENCRYPTION_KEY] = b64encode_as_string(self.encrypted_key)
        headers[OSS_CLIENT_SIDE_ENCRYPTION_START] = b64encode_as_string(self.encrypted_iv)
        headers[OSS_CLIENT_SIDE_ENCRYPTION_CEK_ALG] = self.cek_alg
        headers[OSS_CLIENT_SIDE_ENCRYPTION_WRAP_ALG] = self.wrap_alg

        if multipart_upload_context and multipart_upload_context.data_size and multipart_upload_context.part_size:
            headers[OSS_CLIENT_SIDE_ENCRYPTION_DATA_SIZE] = str(multipart_upload_context.data_size)
            headers[OSS_CLIENT_SIDE_ENCRYPTION_PART_SIZE] = str(multipart_upload_context.part_size)

        if self.mat_desc:
            headers[OSS_CLIENT_SIDE_ENCRYTPION_MATDESC] = json.dumps(self.mat_desc)

        return headers 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:27,代碼來源:models.py

示例9: test_api_get

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def test_api_get(self):
        eventbrite = Eventbrite(OAUTH_TOKEN)

        payload = eventbrite.api("get", "/users/me/", {})

        self.assertEqual(
            sorted([u'id', u'image_id', u'first_name', u'last_name', u'emails', u'name']),
            sorted(payload.keys())
        )

        self.assertEqual(
            payload.resource_uri,
            EVENTBRITE_API_URL + 'users/me/'
        )

        self.assertTrue(payload.ok)
        self.assertTrue(isinstance(payload.elapsed, timedelta))
        self.assertTrue(isinstance(payload.headers, CaseInsensitiveDict))

        self.assertFalse(
            'content-type' in payload.request.headers
        ) 
開發者ID:eventbrite,項目名稱:eventbrite-sdk-python,代碼行數:24,代碼來源:test_client.py

示例10: test_create_from_payload

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def test_create_from_payload(self):

        evbobject = self.evbobject

        self.assertEqual(
            sorted([u'id', u'first_name', u'last_name', u'emails', u'name']),
            sorted(evbobject.keys())
        )

        self.assertTrue(evbobject.ok)
        self.assertEqual(
            self.url,
            evbobject.resource_uri
        )
        self.assertTrue(isinstance(evbobject.elapsed, timedelta))
        self.assertTrue(isinstance(evbobject.headers, CaseInsensitiveDict)) 
開發者ID:eventbrite,項目名稱:eventbrite-sdk-python,代碼行數:18,代碼來源:test_models.py

示例11: _mk_response

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def _mk_response(self, status, content=None):
        reasons = {200: 'OK', 204: 'No Content', 401: 'Unauthorized'}
        # Create a Response object, that will serve as a mock return value
        my_response = req_mod.Response()
        my_response.status_code = status
        my_response.reason = reasons[status]
        clen = '0'
        if status == 200 and content:
            clen = str(len(content))
        dict_headers = {
            'content-length': clen, 'x-powered-by': 'Servlet/3.0',
            'set-cookie': ('JSESSIONID=0000a41BnJsGTNQvBGERA3wR1nj:759878cb-4f'
                           '9a-4b05-a09a-3357abfea3b4; Path=/; Secure; HttpOnl'
                           'y, CCFWSESSION=E4C0FFBE9130431DBF1864171ECC6A6E; P'
                           'ath=/; Secure; HttpOnly'),
            'expires': 'Thu, 01 Dec 1994 16:00:00 GMT',
            'x-transaction-id': 'XT10000073',
            'cache-control': 'no-cache="set-cookie, set-cookie2"',
            'date': 'Wed, 23 Jul 2014 21:51:10 GMT',
            'content-type': 'application/vnd.ibm.powervm'}
        my_response.headers = req_struct.CaseInsensitiveDict(dict_headers)
        my_response._content = content
        return my_response 
開發者ID:powervm,項目名稱:pypowervm,代碼行數:25,代碼來源:test_adapter.py

示例12: __deserialize_requests_response

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def __deserialize_requests_response(self, to_deserialize):
        """
        Create and return a Response based on the contents of the given dictionary.
        :param to_deserialize: The dictionary to create the Response from.
        :return: A Response created by the contents of to_deserialize.
        """
        to_return = Response()
        to_return.status_code = to_deserialize["status_code"]
        to_return.headers = CaseInsensitiveDict(to_deserialize["headers"])
        to_return.encoding = to_deserialize["encoding"]
        to_return._content = to_deserialize["content"]
        to_return._content_consumed = True
        to_return.reason = to_deserialize["reason"]
        to_return.url = to_deserialize["url"]
        to_return.request = self.decode(to_deserialize["request"])
        return to_return 
開發者ID:lavalamp-,項目名稱:ws-backend-community,代碼行數:18,代碼來源:serializer.py

示例13: test_prepared_request

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def test_prepared_request():
    request = Request(
        'POST',
        'https://example.com/pages/1',
        json={'a': ['b', 'c', 'd']},
        headers={
            'Content-Type': 'application/json',
        }
    )
    prepped = request.prepare()
    assert pformat(prepped, width=999) == """\
requests.PreparedRequest(
    method='POST',
    url='https://example.com/pages/1',
    headers=requests.structures.CaseInsensitiveDict({
        'Content-Length': '22',
        'Content-Type': 'application/json'
    }),
    body=b'{"a": ["b"'  # ... and 12 more bytes
)""" 
開發者ID:tommikaikkonen,項目名稱:prettyprinter,代碼行數:22,代碼來源:test_requests.py

示例14: choose_reply

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def choose_reply(path, replies, statuses=None, date=None):
    """Choose the right response based on the path and make a mock response."""

    if statuses is None:
        statuses = collections.defaultdict(lambda: iter([200]))

    if date is None:
        date = datetime_in_future(0)

    if path in replies:
        response = mock.Mock(['json', 'raise_for_status', 'headers'])
        response.status_code = next(statuses[path])
        response.json.side_effect = lambda: json.loads(replies[path])
        response.headers = CaseInsensitiveDict({'Date': date.isoformat()})
        def raise_for_status():
            if not 200 <= response.status_code < 300:
                raise HTTPError(response.status_code)
        response.raise_for_status = raise_for_status
        return response
    else:
        raise NotImplementedError(path) 
開發者ID:dwavesystems,項目名稱:dwave-cloud-client,代碼行數:23,代碼來源:test_mock_submission.py

示例15: build_response

# 需要導入模塊: from requests import structures [as 別名]
# 或者: from requests.structures import CaseInsensitiveDict [as 別名]
def build_response(self, req, resp):
        response = CachedResponse()
        response.status_code = getattr(resp, "status", None)
        response.headers = CaseInsensitiveDict(getattr(resp, "headers", {}))
        response.encoding = get_encoding_from_headers(response.headers)
        response.raw = resp
        response.reason = resp.reason

        if isinstance(req.url, bytes):
            response.url = req.url.decode("utf-8")

        else:
            response.url = req.url

        extract_cookies_to_jar(response.cookies, req, resp)
        response.request = req
        response.connection = self
        return response 
開發者ID:limitedeternity,項目名稱:foxford_courses,代碼行數:20,代碼來源:requests_cache.py


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