当前位置: 首页>>代码示例>>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;未经允许,请勿转载。