How to use the treq.multipart._Header function in treq

To help you get started, we’ve selected a few treq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ClusterHQ / powerstrip-flocker / treq / multipart.py View on Github external
def _writeFile(self, name, filename, content_type, producer, consumer):
        cdisp = _Header("Content-Disposition", "form-data")
        cdisp.add_param("name", name)
        if filename:
            cdisp.add_param("filename", filename)

        consumer.write(str(cdisp) + CRLF)
        consumer.write(str(_Header("Content-Type", content_type)) + CRLF)
        if producer.length != UNKNOWN_LENGTH:
            consumer.write(
                str(_Header("Content-Length", producer.length)) + CRLF)
        consumer.write(CRLF)

        if isinstance(consumer, _LengthConsumer):
            consumer.write(producer.length)
        else:
            self._currentProducer = producer

            def unset(val):
                self._currentProducer = None
                return val

            d = producer.startProducing(consumer)
            d.addCallback(unset)
            return d
github ClusterHQ / powerstrip-flocker / treq / multipart.py View on Github external
def _writeFile(self, name, filename, content_type, producer, consumer):
        cdisp = _Header("Content-Disposition", "form-data")
        cdisp.add_param("name", name)
        if filename:
            cdisp.add_param("filename", filename)

        consumer.write(str(cdisp) + CRLF)
        consumer.write(str(_Header("Content-Type", content_type)) + CRLF)
        if producer.length != UNKNOWN_LENGTH:
            consumer.write(
                str(_Header("Content-Length", producer.length)) + CRLF)
        consumer.write(CRLF)

        if isinstance(consumer, _LengthConsumer):
            consumer.write(producer.length)
        else:
            self._currentProducer = producer

            def unset(val):
                self._currentProducer = None
                return val

            d = producer.startProducing(consumer)
            d.addCallback(unset)
github ClusterHQ / powerstrip-flocker / treq / multipart.py View on Github external
def _writeFile(self, name, filename, content_type, producer, consumer):
        cdisp = _Header("Content-Disposition", "form-data")
        cdisp.add_param("name", name)
        if filename:
            cdisp.add_param("filename", filename)

        consumer.write(str(cdisp) + CRLF)
        consumer.write(str(_Header("Content-Type", content_type)) + CRLF)
        if producer.length != UNKNOWN_LENGTH:
            consumer.write(
                str(_Header("Content-Length", producer.length)) + CRLF)
        consumer.write(CRLF)

        if isinstance(consumer, _LengthConsumer):
            consumer.write(producer.length)
        else:
            self._currentProducer = producer
github ClusterHQ / powerstrip-flocker / treq / multipart.py View on Github external
def _writeString(self, name, value, consumer):
        cdisp = _Header("Content-Disposition", "form-data")
        cdisp.add_param("name", name)
        consumer.write(str(cdisp) + CRLF + CRLF)

        encoded = value.encode("utf-8")
        consumer.write(encoded)
        self._currentProducer = None