packages.urllib3.fields

Module Contents

Classes

RequestField(self,name,data,filename=None,headers=None) A data container for request body parameters.

Functions

guess_content_type(filename,default=”application/octet-stream”) Guess the “Content-Type” of a file.
format_header_param(name,value) Helper function to format and quote a single header parameter.
guess_content_type(filename, default="application/octet-stream")

Guess the “Content-Type” of a file.

Parameters:
  • filename – The filename to guess the “Content-Type” of using mimetypes.
  • default – If no “Content-Type” can be guessed, default to default.
format_header_param(name, value)

Helper function to format and quote a single header parameter.

Particularly useful for header parameters which might contain non-ASCII values, like file names. This follows RFC 2231, as suggested by RFC 2388 Section 4.4.

Parameters:
  • name – The name of the parameter, a string expected to be ASCII only.
  • value – The value of the parameter, provided as a unicode string.
class RequestField(name, data, filename=None, headers=None)

A data container for request body parameters.

Parameters:
  • name – The name of this request field.
  • data – The data/value body.
  • filename – An optional filename of the request field.
  • headers – An optional dict-like object of headers to initially use for the field.
__init__(name, data, filename=None, headers=None)
from_tuples(fieldname, value)

A RequestField factory from old-style tuple parameters.

Supports constructing RequestField from parameter of key/value strings AND key/filetuple. A filetuple is a (filename, data, MIME type) tuple where the MIME type is optional. For example:

'foo': 'bar',
'fakefile': ('foofile.txt', 'contents of foofile'),
'realfile': ('barfile.txt', open('realfile').read()),
'typedfile': ('bazfile.bin', open('bazfile').read(), 'image/jpeg'),
'nonamefile': 'contents of nonamefile field',

Field names and filenames must be unicode.

_render_part(name, value)

Overridable helper function to format a single header parameter.

Parameters:
  • name – The name of the parameter, a string expected to be ASCII only.
  • value – The value of the parameter, provided as a unicode string.
_render_parts(header_parts)

Helper function to format and quote a single header.

Useful for single headers that are composed of multiple items. E.g., ‘Content-Disposition’ fields.

Parameters:header_parts – A sequence of (k, v) typles or a dict of (k, v) to format as k1=”v1”; k2=”v2”; ….
render_headers()

Renders the headers for this request field.

make_multipart(content_disposition=None, content_type=None, content_location=None)

Makes this request field into a multipart request field.

This method overrides “Content-Disposition”, “Content-Type” and “Content-Location” headers to the request parameter.

Parameters:
  • content_type – The ‘Content-Type’ of the request body.
  • content_location – The ‘Content-Location’ of the request body.