• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python swob.HeaderKeyDict类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中swift.common.swob.HeaderKeyDict的典型用法代码示例。如果您正苦于以下问题:Python HeaderKeyDict类的具体用法?Python HeaderKeyDict怎么用?Python HeaderKeyDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了HeaderKeyDict类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: generate_request_headers

    def generate_request_headers(self, orig_req=None, additional=None,
                                 transfer=False):
        """
        Create a list of headers to be used in backend requets

        :param orig_req: the original request sent by the client to the proxy
        :param additional: additional headers to send to the backend
        :param transfer: If True, transfer headers from original client request
        :returns: a dictionary of headers
        """
        # Use the additional headers first so they don't overwrite the headers
        # we require.
        headers = HeaderKeyDict(additional) if additional else HeaderKeyDict()
        if transfer:
            self.transfer_headers(orig_req.headers, headers)
        headers.setdefault('x-timestamp', normalize_timestamp(time.time()))
        if orig_req:
            referer = orig_req.as_referer()
        else:
            referer = ''
        headers['x-trans-id'] = self.trans_id
        headers['connection'] = 'close'
        headers['user-agent'] = 'proxy-server %s' % os.getpid()
        headers['referer'] = referer
        return headers
开发者ID:sa4250mnpo70,项目名称:swift,代码行数:25,代码来源:base.py


示例2: _clean_outgoing_headers

    def _clean_outgoing_headers(self, headers):
        """
        Removes any headers as per the middleware configuration for
        outgoing responses.

        :param headers: A WSGI start_response style list of headers,
                        [('header1', 'value), ('header2', 'value),
                         ...]
        :returns: The same headers list, but with some headers
                  removed as per the middlware configuration for
                  outgoing responses.
        """
        headers = HeaderKeyDict(headers)
        for h in headers.keys():
            remove = h in self.outgoing_remove_headers
            if not remove:
                for p in self.outgoing_remove_headers_startswith:
                    if h.startswith(p):
                        remove = True
                        break
            if remove:
                if h in self.outgoing_allow_headers:
                    remove = False
            if remove:
                for p in self.outgoing_allow_headers_startswith:
                    if h.startswith(p):
                        remove = False
                        break
            if remove:
                del headers[h]
        return headers.items()
开发者ID:lielongxingkong,项目名称:windchimes,代码行数:31,代码来源:tempurl.py


示例3: generate_request_headers

    def generate_request_headers(self, orig_req=None, additional=None, transfer=False):
        """
        Create a list of headers to be used in backend requets

        :param orig_req: the original request sent by the client to the proxy
        :param additional: additional headers to send to the backend
        :param transfer: If True, transfer headers from original client request
        :returns: a dictionary of headers
        """
        # Use the additional headers first so they don't overwrite the headers
        # we require.
        headers = HeaderKeyDict(additional) if additional else HeaderKeyDict()
        if transfer:
            self.transfer_headers(orig_req.headers, headers)
        if "x-timestamp" not in headers:
            headers["x-timestamp"] = normalize_timestamp(time.time())
        if orig_req:
            referer = orig_req.as_referer()
        else:
            referer = ""
        headers.update(
            {
                "x-trans-id": self.trans_id,
                "connection": "close",
                "user-agent": "proxy-server %s" % os.getpid(),
                "referer": referer,
            }
        )
        return headers
开发者ID:zaitcev,项目名称:swift-lfs,代码行数:29,代码来源:base.py


示例4: publish_search

    def publish_search(self, path, req):
        """ Publish a verify request on the queue to gate engine """

        headers = HeaderKeyDict(req.headers)
        #self.logger.debug("SWIFTSEARCH avaiable headers: %s" % (headers.items()))

        # TODO(mlopezc1) is this actually faster than a regular regex with match?
        #   swift code loves this pattern (ex tempurl middleware) but not sure how
        #   will this actually perform in high use. Perf comparison later?
        for k, v in headers.items():
            # if header not in the whitelist of allowed full header names or *
            if k not in self.index_headers:
                #self.logger.debug("SWIFTSEARCH k=%s not in %s" % (k, self.index_headers))
                for h in self.index_headers_startwith:
                    if not k.startswith(h):
                        #self.logger.debug("SWIFTSEARCH k=%s not allowed" % (k))
                        del headers[k]

        self.logger.debug("SWIFTSEARCH sending metadata for indexing: %s" % (headers.items()))

        # TODO(mlopez1) what about renaming keys to something more human ? the X- and title format is kinda weird
        exchange = kombu.Exchange(self.exc_str, self.exc_type, durable=self.exc_durable)
        queue = kombu.Queue('search', exchange=exchange, routing_key='search')

        with kombu.Connection(self.conn_str) as connection:
            with connection.Producer(serializer='json') as producer:
                producer.publish({'id': b64encode(path), 'path': path, 'metadata': headers},
                                 exchange=exchange, routing_key='search', declare=[queue])

        return True
开发者ID:manuelfelipe,项目名称:searchswift,代码行数:30,代码来源:middleware.py


示例5: test_206_multiple_ranges

    def test_206_multiple_ranges(self):
        fr = FakeResponse(
            206,
            {'Content-Type': 'multipart/byteranges; boundary=asdfasdfasdf'},
            ("--asdfasdfasdf\r\n"
             "Content-Type: application/lunch\r\n"
             "Content-Range: bytes 0-3/10\r\n"
             "\r\n"
             "sand\r\n"
             "--asdfasdfasdf\r\n"
             "Content-Type: application/lunch\r\n"
             "Content-Range: bytes 6-9/10\r\n"
             "\r\n"
             "ches\r\n"
             "--asdfasdfasdf--"))

        doc_iters = http_response_to_document_iters(fr)

        first_byte, last_byte, length, headers, body = next(doc_iters)
        self.assertEqual(first_byte, 0)
        self.assertEqual(last_byte, 3)
        self.assertEqual(length, 10)
        header_dict = HeaderKeyDict(headers)
        self.assertEqual(header_dict.get('Content-Type'), 'application/lunch')
        self.assertEqual(body.read(), 'sand')

        first_byte, last_byte, length, headers, body = next(doc_iters)
        self.assertEqual(first_byte, 6)
        self.assertEqual(last_byte, 9)
        self.assertEqual(length, 10)
        header_dict = HeaderKeyDict(headers)
        self.assertEqual(header_dict.get('Content-Type'), 'application/lunch')
        self.assertEqual(body.read(), 'ches')

        self.assertRaises(StopIteration, next, doc_iters)
开发者ID:Ahiknsr,项目名称:swift,代码行数:35,代码来源:test_request_helpers.py


示例6: cookie_resp

 def cookie_resp(status, response_headers, exc_info=None):
     resp_headers = HeaderKeyDict(response_headers)
     if 'x-auth-token' in resp_headers:
         auth_token = resp_headers['x-auth-token']
         expires_in = int(resp_headers.get('x-auth-token-expires', 0))
         storage_url = resp_headers.get('x-storage-url', '')
         path_parts = urlparse(storage_url)
         domain = path_parts.hostname
         secure = False
         if path_parts.scheme == 'https':
             secure = True
         if auth_token and domain:
             new_cookie = create_auth_cookie('session',
                                             domain,
                                             token=auth_token,
                                             expires_in=expires_in,
                                             secure=secure,
                                             httponly=True)
             response_headers.append(('Set-Cookie', new_cookie))
             new_cookie = create_auth_cookie('storage',
                                             domain,
                                             token=quote(storage_url,
                                                         safe=''),
                                             expires_in=expires_in,
                                             secure=secure)
             response_headers.append(('Set-Cookie', new_cookie))
     return start_response(status, response_headers, exc_info)
开发者ID:pkit,项目名称:liteauth,代码行数:27,代码来源:liteauth_token.py


示例7: test_clean_outgoing_headers

    def test_clean_outgoing_headers(self):
        orh = ''
        oah = ''
        hdrs = {'test-header': 'value'}
        hdrs = HeaderKeyDict(tempurl.TempURL(
            None,
            {'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
        )._clean_outgoing_headers(hdrs.items()))
        self.assertTrue('test-header' in hdrs)

        orh = 'test-header'
        oah = ''
        hdrs = {'test-header': 'value'}
        hdrs = HeaderKeyDict(tempurl.TempURL(
            None,
            {'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
        )._clean_outgoing_headers(hdrs.items()))
        self.assertTrue('test-header' not in hdrs)

        orh = 'test-header-*'
        oah = ''
        hdrs = {'test-header-one': 'value',
                'test-header-two': 'value'}
        hdrs = HeaderKeyDict(tempurl.TempURL(
            None,
            {'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
        )._clean_outgoing_headers(hdrs.items()))
        self.assertTrue('test-header-one' not in hdrs)
        self.assertTrue('test-header-two' not in hdrs)

        orh = 'test-header-*'
        oah = 'test-header-two'
        hdrs = {'test-header-one': 'value',
                'test-header-two': 'value'}
        hdrs = HeaderKeyDict(tempurl.TempURL(
            None,
            {'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
        )._clean_outgoing_headers(hdrs.items()))
        self.assertTrue('test-header-one' not in hdrs)
        self.assertTrue('test-header-two' in hdrs)

        orh = 'test-header-* test-other-header'
        oah = 'test-header-two test-header-yes-*'
        hdrs = {'test-header-one': 'value',
                'test-header-two': 'value',
                'test-other-header': 'value',
                'test-header-yes': 'value',
                'test-header-yes-this': 'value'}
        hdrs = HeaderKeyDict(tempurl.TempURL(
            None,
            {'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
        )._clean_outgoing_headers(hdrs.items()))
        self.assertTrue('test-header-one' not in hdrs)
        self.assertTrue('test-header-two' in hdrs)
        self.assertTrue('test-other-header' not in hdrs)
        self.assertTrue('test-header-yes' not in hdrs)
        self.assertTrue('test-header-yes-this' in hdrs)
开发者ID:heemanshu,项目名称:swift_liberty,代码行数:57,代码来源:test_tempurl.py


示例8: test_get_response_headers_with_legacy_data

    def test_get_response_headers_with_legacy_data(self):
        broker = backend.AccountBroker(':memory:', account='a')
        now = time.time()
        with mock.patch('time.time', new=lambda: now):
            broker.initialize(Timestamp(now).internal)
        # add some container data
        ts = (Timestamp(t).internal for t in itertools.count(int(now)))
        total_containers = 0
        total_objects = 0
        total_bytes = 0
        for policy in POLICIES:
            delete_timestamp = ts.next()
            put_timestamp = ts.next()
            object_count = int(policy)
            bytes_used = int(policy) * 10
            broker.put_container('c-%s' % policy.name, put_timestamp,
                                 delete_timestamp, object_count, bytes_used,
                                 int(policy))
            total_containers += 1
            total_objects += object_count
            total_bytes += bytes_used
        expected = HeaderKeyDict({
            'X-Account-Container-Count': total_containers,
            'X-Account-Object-Count': total_objects,
            'X-Account-Bytes-Used': total_bytes,
            'X-Timestamp': Timestamp(now).normal,
            'X-PUT-Timestamp': Timestamp(now).normal,
        })
        for policy in POLICIES:
            prefix = 'X-Account-Storage-Policy-%s-' % policy.name
            expected[prefix + 'Object-Count'] = int(policy)
            expected[prefix + 'Bytes-Used'] = int(policy) * 10
        orig_policy_stats = broker.get_policy_stats

        def stub_policy_stats(*args, **kwargs):
            policy_stats = orig_policy_stats(*args, **kwargs)
            for stats in policy_stats.values():
                # legacy db's won't return container_count
                del stats['container_count']
            return policy_stats
        broker.get_policy_stats = stub_policy_stats
        resp_headers = utils.get_response_headers(broker)
        per_policy_container_headers = [
            h for h in resp_headers if
            h.lower().startswith('x-account-storage-policy-') and
            h.lower().endswith('-container-count')]
        self.assertFalse(per_policy_container_headers)
        for key, value in resp_headers.items():
            expected_value = expected.pop(key)
            self.assertEqual(expected_value, str(value),
                             'value for %r was %r not %r' % (
                                 key, value, expected_value))
        self.assertFalse(expected)
开发者ID:2015-ucsc-hp,项目名称:swift,代码行数:53,代码来源:test_utils.py


示例9: test_fake_swift_sysmeta

    def test_fake_swift_sysmeta(self):
        swift = FakeSwift()
        orig_headers = HeaderKeyDict()
        orig_headers.update({sysmeta_header('container', 'acl'): 'test',
                             'x-container-meta-foo': 'bar'})

        swift.register(self.method, self.path, MagicMock(), orig_headers, None)

        self._check_headers(swift, self.method, self.path, orig_headers)

        new_headers = orig_headers.copy()
        del new_headers[sysmeta_header('container', 'acl').title()]
        swift.register(self.method, self.path, MagicMock(), new_headers, None)

        self._check_headers(swift, self.method, self.path, orig_headers)
开发者ID:notmyname,项目名称:swift3,代码行数:15,代码来源:test_helpers.py


示例10: FakeConn

class FakeConn(object):

    def __init__(self, status, headers=None, body='', **kwargs):
        self.status = status
        try:
            self.reason = RESPONSE_REASONS[self.status][0]
        except Exception:
            self.reason = 'Fake'
        self.body = body
        self.resp_headers = HeaderKeyDict()
        if headers:
            self.resp_headers.update(headers)
        self.with_exc = False
        self.etag = None

    def _update_raw_call_args(self, *args, **kwargs):
        capture_attrs = ('host', 'port', 'method', 'path', 'req_headers',
                         'query_string')
        for attr, value in zip(capture_attrs, args[:len(capture_attrs)]):
            setattr(self, attr, value)
        return self

    def getresponse(self):
        if self.etag:
            self.resp_headers['etag'] = str(self.etag.hexdigest())
        if self.with_exc:
            raise Exception('test')
        return self

    def getheader(self, header, default=None):
        return self.resp_headers.get(header, default)

    def getheaders(self):
        return self.resp_headers.items()

    def read(self, amt=None):
        if amt is None:
            return self.body
        elif isinstance(self.body, six.StringIO):
            return self.body.read(amt)
        else:
            return Exception('Not a StringIO entry')

    def send(self, data):
        if not self.etag:
            self.etag = md5()
        self.etag.update(data)
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:47,代码来源:test_direct_client.py


示例11: generate_request_headers

 def generate_request_headers(self, orig_req=None, additional=None,
                              transfer=False):
     # Use the additional headers first so they don't overwrite the headers
     # we require.
     headers = HeaderKeyDict(additional) if additional else HeaderKeyDict()
     if transfer:
         self.transfer_headers(orig_req.headers, headers)
     if 'x-timestamp' not in headers:
         headers['x-timestamp'] = normalize_timestamp(time.time())
     if orig_req:
         referer = orig_req.as_referer()
     else:
         referer = ''
     headers.update({'x-trans-id': self.trans_id,
                     'connection': 'close',
                     'user-agent': 'proxy-server %s' % os.getpid(),
                     'referer': referer})
     return headers
开发者ID:DrLeonard,项目名称:swift,代码行数:18,代码来源:base.py


示例12: handle_request

 def handle_request(self, env, start_response):
     account_id = env.get('REMOTE_USER', None)
     resp = self._app_call(env)
     headers = HeaderKeyDict(self._response_headers)
     if 'x-nexe-cdr-line' in headers and account_id:
         try:
             total_time, line = headers['x-nexe-cdr-line'].split(', ', 1)
             node_lines = re.split(r'\s*,\s*', line)
             total = []
             for rtime, line in zip(*[iter(node_lines)]*2):
                 accounting_info = line.split(' ')
                 total = self.liteacc.cache_accounting_info(account_id, rtime, accounting_info)
                 self.liteacc.queue.put(account_id)
             headers['x-nexe-cdr-total'] = ' '.join([str(t) for t in total])
             self._response_headers = [(k, v) for k, v in headers.iteritems()]
         except ValueError:
             self.logger.warning('Accounting cannot parse CDR entry: %s' % headers['x-nexe-cdr-line'])
     start_response(self._response_status, self._response_headers,
                    self._response_exc_info)
     return resp
开发者ID:mgeisler,项目名称:liteauth,代码行数:20,代码来源:liteaccounting.py


示例13: __init__

 def __init__(self, status, headers=None, body='', **kwargs):
     self.status = status
     try:
         self.reason = RESPONSE_REASONS[self.status][0]
     except Exception:
         self.reason = 'Fake'
     self.body = body
     self.resp_headers = HeaderKeyDict()
     if headers:
         self.resp_headers.update(headers)
     self.with_exc = False
     self.etag = None
开发者ID:bkolli,项目名称:swift,代码行数:12,代码来源:test_direct_client.py


示例14: test_200

    def test_200(self):
        fr = FakeResponse(
            200,
            {'Content-Length': '10', 'Content-Type': 'application/lunch'},
            'sandwiches')

        doc_iters = http_response_to_document_iters(fr)
        first_byte, last_byte, length, headers, body = next(doc_iters)
        self.assertEqual(first_byte, 0)
        self.assertEqual(last_byte, 9)
        self.assertEqual(length, 10)
        header_dict = HeaderKeyDict(headers)
        self.assertEqual(header_dict.get('Content-Length'), '10')
        self.assertEqual(header_dict.get('Content-Type'), 'application/lunch')
        self.assertEqual(body.read(), 'sandwiches')

        self.assertRaises(StopIteration, next, doc_iters)

        fr = FakeResponse(
            200,
            {'Transfer-Encoding': 'chunked',
             'Content-Type': 'application/lunch'},
            'sandwiches')

        doc_iters = http_response_to_document_iters(fr)
        first_byte, last_byte, length, headers, body = next(doc_iters)
        self.assertEqual(first_byte, 0)
        self.assertIsNone(last_byte)
        self.assertIsNone(length)
        header_dict = HeaderKeyDict(headers)
        self.assertEqual(header_dict.get('Transfer-Encoding'), 'chunked')
        self.assertEqual(header_dict.get('Content-Type'), 'application/lunch')
        self.assertEqual(body.read(), 'sandwiches')

        self.assertRaises(StopIteration, next, doc_iters)
开发者ID:Ahiknsr,项目名称:swift,代码行数:35,代码来源:test_request_helpers.py


示例15: test_get_response_headers_with_data

 def test_get_response_headers_with_data(self):
     broker = backend.AccountBroker(':memory:', account='a')
     now = time.time()
     with mock.patch('time.time', new=lambda: now):
         broker.initialize(Timestamp(now).internal)
     # add some container data
     ts = (Timestamp(t).internal for t in itertools.count(int(now)))
     total_containers = 0
     total_objects = 0
     total_bytes = 0
     for policy in POLICIES:
         delete_timestamp = ts.next()
         put_timestamp = ts.next()
         object_count = int(policy)
         bytes_used = int(policy) * 10
         broker.put_container('c-%s' % policy.name, put_timestamp,
                              delete_timestamp, object_count, bytes_used,
                              int(policy))
         total_containers += 1
         total_objects += object_count
         total_bytes += bytes_used
     expected = HeaderKeyDict({
         'X-Account-Container-Count': total_containers,
         'X-Account-Object-Count': total_objects,
         'X-Account-Bytes-Used': total_bytes,
         'X-Timestamp': Timestamp(now).normal,
         'X-PUT-Timestamp': Timestamp(now).normal,
     })
     for policy in POLICIES:
         prefix = 'X-Account-Storage-Policy-%s-' % policy.name
         expected[prefix + 'Object-Count'] = int(policy)
         expected[prefix + 'Bytes-Used'] = int(policy) * 10
     resp_headers = utils.get_response_headers(broker)
     for key, value in resp_headers.items():
         expected_value = expected.pop(key)
         self.assertEqual(expected_value, str(value),
                          'value for %r was %r not %r' % (
                              key, value, expected_value))
     self.assertFalse(expected)
开发者ID:701,项目名称:swift,代码行数:39,代码来源:test_utils.py


示例16: test_206_single_range

    def test_206_single_range(self):
        fr = FakeResponse(
            206,
            {'Content-Length': '8', 'Content-Type': 'application/lunch',
             'Content-Range': 'bytes 1-8/10'},
            'andwiche')

        doc_iters = http_response_to_document_iters(fr)
        first_byte, last_byte, length, headers, body = next(doc_iters)
        self.assertEqual(first_byte, 1)
        self.assertEqual(last_byte, 8)
        self.assertEqual(length, 10)
        header_dict = HeaderKeyDict(headers)
        self.assertEqual(header_dict.get('Content-Length'), '8')
        self.assertEqual(header_dict.get('Content-Type'), 'application/lunch')
        self.assertEqual(body.read(), 'andwiche')

        self.assertRaises(StopIteration, next, doc_iters)

        # Chunked response should be treated in the same way as non-chunked one
        fr = FakeResponse(
            206,
            {'Transfer-Encoding': 'chunked',
             'Content-Type': 'application/lunch',
             'Content-Range': 'bytes 1-8/10'},
            'andwiche')

        doc_iters = http_response_to_document_iters(fr)
        first_byte, last_byte, length, headers, body = next(doc_iters)
        self.assertEqual(first_byte, 1)
        self.assertEqual(last_byte, 8)
        self.assertEqual(length, 10)
        header_dict = HeaderKeyDict(headers)
        self.assertEqual(header_dict.get('Content-Type'), 'application/lunch')
        self.assertEqual(body.read(), 'andwiche')

        self.assertRaises(StopIteration, next, doc_iters)
开发者ID:Ahiknsr,项目名称:swift,代码行数:37,代码来源:test_request_helpers.py


示例17: test_extract_metadata

    def test_extract_metadata(self):
        self.app.register('HEAD', '/v1/a/c?extract-archive=tar',
                          HTTPNoContent, {}, None)
        self.app.register('PUT', '/v1/a/c/obj1?extract-archive=tar',
                          HTTPCreated, {}, None)
        self.app.register('PUT', '/v1/a/c/obj2?extract-archive=tar',
                          HTTPCreated, {}, None)

        # It's a real pain to instantiate TarInfo objects directly; they
        # really want to come from a file on disk or a tarball. So, we write
        # out some files and add pax headers to them as they get placed into
        # the tarball.
        with open(os.path.join(self.testdir, "obj1"), "w") as fh1:
            fh1.write("obj1 contents\n")
        with open(os.path.join(self.testdir, "obj2"), "w") as fh2:
            fh2.write("obj2 contents\n")

        tar_ball = StringIO()
        tar_file = tarfile.TarFile.open(fileobj=tar_ball, mode="w",
                                        format=tarfile.PAX_FORMAT)

        # With GNU tar 1.27.1 or later (possibly 1.27 as well), a file with
        # extended attribute user.thingy = dingy gets put into the tarfile
        # with pax_headers containing key/value pair
        # (SCHILY.xattr.user.thingy, dingy), both unicode strings (py2: type
        # unicode, not type str).
        #
        # With BSD tar (libarchive), you get key/value pair
        # (LIBARCHIVE.xattr.user.thingy, dingy), which strikes me as
        # gratuitous incompatibility.
        #
        # Still, we'll support uploads with both. Just heap more code on the
        # problem until you can forget it's under there.
        with open(os.path.join(self.testdir, "obj1")) as fh1:
            tar_info1 = tar_file.gettarinfo(fileobj=fh1,
                                            arcname="obj1")
            tar_info1.pax_headers[u'SCHILY.xattr.user.mime_type'] = \
                u'application/food-diary'
            tar_info1.pax_headers[u'SCHILY.xattr.user.meta.lunch'] = \
                u'sopa de albóndigas'
            tar_info1.pax_headers[
                u'SCHILY.xattr.user.meta.afternoon-snack'] = \
                u'gigantic bucket of coffee'
            tar_file.addfile(tar_info1, fh1)

        with open(os.path.join(self.testdir, "obj2")) as fh2:
            tar_info2 = tar_file.gettarinfo(fileobj=fh2,
                                            arcname="obj2")
            tar_info2.pax_headers[
                u'LIBARCHIVE.xattr.user.meta.muppet'] = u'bert'
            tar_info2.pax_headers[
                u'LIBARCHIVE.xattr.user.meta.cat'] = u'fluffy'
            tar_info2.pax_headers[
                u'LIBARCHIVE.xattr.user.notmeta'] = u'skipped'
            tar_file.addfile(tar_info2, fh2)

        tar_ball.seek(0)

        req = Request.blank('/v1/a/c?extract-archive=tar')
        req.environ['REQUEST_METHOD'] = 'PUT'
        req.environ['wsgi.input'] = tar_ball
        req.headers['transfer-encoding'] = 'chunked'
        req.headers['accept'] = 'application/json;q=1.0'

        resp = req.get_response(self.bulk)
        self.assertEqual(resp.status_int, 200)

        # sanity check to make sure the upload worked
        upload_status = utils.json.loads(resp.body)
        self.assertEqual(upload_status['Number Files Created'], 2)

        put1_headers = HeaderKeyDict(self.app.calls_with_headers[1][2])
        self.assertEqual(
            put1_headers.get('Content-Type'),
            'application/food-diary')
        self.assertEqual(
            put1_headers.get('X-Object-Meta-Lunch'),
            'sopa de alb\xc3\xb3ndigas')
        self.assertEqual(
            put1_headers.get('X-Object-Meta-Afternoon-Snack'),
            'gigantic bucket of coffee')

        put2_headers = HeaderKeyDict(self.app.calls_with_headers[2][2])
        self.assertEqual(put2_headers.get('X-Object-Meta-Muppet'), 'bert')
        self.assertEqual(put2_headers.get('X-Object-Meta-Cat'), 'fluffy')
        self.assertEqual(put2_headers.get('Content-Type'), None)
        self.assertEqual(put2_headers.get('X-Object-Meta-Blah'), None)
开发者ID:LSBDOpenstackDev,项目名称:swift,代码行数:87,代码来源:test_bulk.py


示例18: test_clean_outgoing_headers

    def test_clean_outgoing_headers(self):
        orh = ""
        oah = ""
        hdrs = {"test-header": "value"}
        hdrs = HeaderKeyDict(
            tempurl.TempURL(
                None, {"outgoing_remove_headers": orh, "outgoing_allow_headers": oah}
            )._clean_outgoing_headers(hdrs.items())
        )
        self.assertTrue("test-header" in hdrs)

        orh = "test-header"
        oah = ""
        hdrs = {"test-header": "value"}
        hdrs = HeaderKeyDict(
            tempurl.TempURL(
                None, {"outgoing_remove_headers": orh, "outgoing_allow_headers": oah}
            )._clean_outgoing_headers(hdrs.items())
        )
        self.assertTrue("test-header" not in hdrs)

        orh = "test-header-*"
        oah = ""
        hdrs = {"test-header-one": "value", "test-header-two": "value"}
        hdrs = HeaderKeyDict(
            tempurl.TempURL(
                None, {"outgoing_remove_headers": orh, "outgoing_allow_headers": oah}
            )._clean_outgoing_headers(hdrs.items())
        )
        self.assertTrue("test-header-one" not in hdrs)
        self.assertTrue("test-header-two" not in hdrs)

        orh = "test-header-*"
        oah = "test-header-two"
        hdrs = {"test-header-one": "value", "test-header-two": "value"}
        hdrs = HeaderKeyDict(
            tempurl.TempURL(
                None, {"outgoing_remove_headers": orh, "outgoing_allow_headers": oah}
            )._clean_outgoing_headers(hdrs.items())
        )
        self.assertTrue("test-header-one" not in hdrs)
        self.assertTrue("test-header-two" in hdrs)

        orh = "test-header-* test-other-header"
        oah = "test-header-two test-header-yes-*"
        hdrs = {
            "test-header-one": "value",
            "test-header-two": "value",
            "test-other-header": "value",
            "test-header-yes": "value",
            "test-header-yes-this": "value",
        }
        hdrs = HeaderKeyDict(
            tempurl.TempURL(
                None, {"outgoing_remove_headers": orh, "outgoing_allow_headers": oah}
            )._clean_outgoing_headers(hdrs.items())
        )
        self.assertTrue("test-header-one" not in hdrs)
        self.assertTrue("test-header-two" in hdrs)
        self.assertTrue("test-other-header" not in hdrs)
        self.assertTrue("test-header-yes" not in hdrs)
        self.assertTrue("test-header-yes-this" in hdrs)
开发者ID:nguyenducnhaty,项目名称:swift,代码行数:62,代码来源:test_tempurl.py



注:本文中的swift.common.swob.HeaderKeyDict类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python swob.Request类代码示例发布时间:2022-05-27
下一篇:
Python swob.HTTPOk类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap