requests.packages.urllib3.fields.RequestField

Here are the examples of the python api requests.packages.urllib3.fields.RequestField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

Example 1

Project: server-client-python Source File: request_factory.py
def _add_multipart(parts):
    mime_multipart_parts = list()
    for name, (filename, data, content_type) in parts.items():
        multipart_part = RequestField(name=name, data=data, filename=filename)
        multipart_part.make_multipart(content_type=content_type)
        mime_multipart_parts.append(multipart_part)
    xml_request, content_type = encode_multipart_formdata(mime_multipart_parts)
    content_type = ''.join(('multipart/mixed',) + content_type.partition(';')[1:])
    return xml_request, content_type

Example 2

Project: python_api Source File: bulkloader.py
    def add(self, docuement):
        """Add a docuement to the list of bulk uploads"""
        if not isinstance(docuement, Docuements):
            raise InvalidAPIRequest("You can only pass docuements to bulkloader")

        if docuement.content() is None:
            raise InvalidAPIRequest("You must specify the docuement content")

        target = docuement.uris()
        if len(target) != 1:
            raise InvalidAPIRequest("You must specify a single URI")
        else:
            target = target[0]

        self.field_count += 1
        metaname = "meta{}".format(self.field_count)
        dataname = "data{}".format(self.field_count)

        self.logger.debug("Bulk[{}] = {}".format(self.field_count, target))

        rf = RequestField(name=metaname, data=docuement.metadata(), filename=target)
        rf.make_multipart(content_disposition='attachment; category=metadata', \
                              content_type=docuement.metadata_content_type())
        self.fields.append(rf)

        rf = RequestField(name=dataname, data=docuement.content(), filename=target)
        rf.make_multipart(content_disposition='attachment', \
                              content_type=docuement.content_type())
        self.fields.append(rf)

Example 3

Project: python_api Source File: documents.py
    def _put_mixed(self, data, target, connection):
        """
        Put the docuement using the bulk interface (because it has
        arbitrary metadata).
        """

        params = []
        for key in ['database', 'transform', 'txid', \
                        'temporal-collection', 'system-time']:
            if key in self._config:
                params.append("{}={}".format(key, self._config[key]))

        for pair in self.transparams:
            params.append("trans:{}={}".format(pair[0], pair[1]))

        meta = self.metadata()
        if self.metadata_content_type() is None:
            metact = "application/xml"
        else:
            metact = self.metadata_content_type()

        uri = connection.client_uri("docuements")
        if params:
            uri = uri + "?" + "&".join(params)

        datact = self._config['content-type']

        fields = []
        rf = RequestField(name="meta1", data=meta, filename=target)
        rf.make_multipart(content_disposition='attachment; category=metadata', \
                              content_type=metact)
        fields.append(rf)

        rf = RequestField(name="data1", data=data, filename=target)
        rf.make_multipart(content_disposition='attachment', \
                              content_type=datact)
        fields.append(rf)

        post_body, content_type = encode_multipart_formdata(fields)

        post_ct = ''.join(('multipart/mixed',) \
                              + content_type.partition(';')[1:])

        response = connection.post(uri, payload=post_body, content_type=post_ct)

        return response