twisted.web.http_headers.Headers - python examples

Here are the examples of the python api twisted.web.http_headers.Headers taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

108 Examples 7

3 View Complete Implementation : benchlib.py
Copyright Apache License 2.0
Author : apple
    def writeData(self, path, data, contentType):
        return self.agent.request(
            'PUT',
            self._makeURL(path),
            Headers({'content-type': [contentType]}),
            StringProducer(data))

3 View Complete Implementation : find_events.py
Copyright Apache License 2.0
Author : apple
def uploadEvents(numEvents, agent, uri, cal):
    def worker():
        for i in range(numEvents):
            event = makeEvent(i, 1, 0)
            yield agent.request(
                'PUT',
                '%s%s%d.ics' % (uri, cal, i),
                Headers({"content-type": ["text/calendar"]}),
                StringProducer(event))
    worker = worker()
    return gatherResults([
        cooperate(worker).whenDone() for _ignore_i in range(3)])

3 View Complete Implementation : httpauth.py
Copyright Apache License 2.0
Author : apple
    def _respondToChallenge(self, challenge, method, uri, headers, bodyProducer):
        if headers is None:
            headers = Headers()
        else:
            headers = Headers(dict(headers.getAllRawHeaders()))
        for k, vs in challenge.response(uri, method, self._authinfo).iteritems():
            for v in vs:
                headers.addRawHeader(k, v)
        return self._agent.request(method, uri, headers, bodyProducer)

3 View Complete Implementation : _event_change.py
Copyright Apache License 2.0
Author : apple
@inlineCallbacks
def _generous_sample(dtrace, replacer, agent, host, port, user, calendar, fieldName, attendeeCount, samples):
    url = 'http://%s:%s/calendars/__uids__/%s/%s/%s-change.ics' % (
        host, port, user, calendar, fieldName)

    headers = Headers({"content-type": ["text/calendar"]})

    # See the makeEvent call above.
    event = makeEvent(0, 1, attendeeCount)

    yield agent.request('PUT', url, headers, StringProducer(event))

    # Sample changing the event according to the replacer.
    samples = yield sample(
        dtrace, samples,
        agent, (('PUT', url, headers, StringProducer(replacer(event, i)))
                for i in count(1)).next,
        NO_CONTENT)
    returnValue(samples)

3 View Complete Implementation : riak.py
Copyright MIT License
Author : ducted
    @defer.inlineCallbacks
    def _get_stats_from_node(self):
        agent = Agent(reactor)

        url = self.config.get('url', 'http://%s:8098/stats' % self.hostname)
        ua = self.config.get('useragent', 'Duct Riak stats checker')

        headers = Headers({'User-Agent': [ua]})
        request = yield agent.request('GET'.encode(), url.encode(), headers)

        if (request.length) and (request.code == 200):
            d = defer.Deferred()
            request.deliverBody(BodyReceiver(d))
            b = yield d
            body = b.read()
        else:
            body = "{}"

        defer.returnValue(json.loads(body))

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume(self):
        name = 'test-create-volume'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": None}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume_size_option(self):
        name = 'test-create-volume'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": {u"size": u"50"}}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
        d.addCallback(self._remove_volume_callback, name)
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume_provisioning_option(self):
        name = 'test-create-volume'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": {u"provisioning": u"full"}}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
        d.addCallback(self._remove_volume_callback, name)
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume_invalid_provisioning_option(self):
        name = 'test-create-volume-fake'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": {u"provisioning": u"fake"}}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({
            u"Err": "Invalid input received: Must specify a valid " +
            "provisioning type ['thin', 'full', " +
            "'dedup'], value 'fake' is invalid."}))
        d.addCallback(self._remove_volume_callback, name)
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume_invalid_option(self):
        name = 'test-create-volume-fake'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": {u"fake": u"fake"}}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({
            u"Err": "create volume failed, error is: fake is not a valid "
            "option. Valid options are: ['size', 'provisioning', "
            "'flash-cache']"}))
        d.addCallback(self._remove_volume_callback, name)
        d.addErrback(self.cbFailed)
        return d