Go to the latest version of this document.

# ``twisted`.`web`.`static``

module documentation
(source)

Static resources for `twisted.web`.

Class | `ASISProcessor` | Serve files exactly as responses without generating a status-line or any headers. Inspired by Apache's mod_asis.
Class | `Data` | This is a static, in-memory resource.
Class | `DirectoryLister` | Print the content of a directory.
Class | `File` | File is a resource that represents a plain non-interpreted file (although it can look for an extension like .rpy or .cgi and hand the file to a processor for interpretation if you wish). Its constructor takes a file path.
Class | `MultipleRangeStaticProducer` | A `StaticProducer` that writes several chunks of a file to the request.
Class | `NoRangeStaticProducer` | A `StaticProducer` that writes the entire file to the request.
Class | `Redirect` | Undocumented
Class | `Registry` | I am a Componentized object that will be made available to internal Twisted file-based dynamic web content such as .rpy and .epy scripts.
Class | `SingleRangeStaticProducer` | A `StaticProducer` that writes a single chunk of a file to the request.
Class | `StaticProducer` | Superclass for classes that implement the business of producing.
Function | `addSlash` | Add a trailing slash to `request`'s URI. Deprecated, do not use.
Function | `formatFileSize` | Format the given file size in bytes to human readable format.
Function | `getTypeAndEncoding` | Undocumented
Function | `isDangerous` | Undocumented
Function | `loadMimeTypes` | Produces a mapping of extensions (with leading dot) to MIME types.
Variable | `dangerousPathError` | Undocumented
Function | `_addSlash` | Add a trailing slash to `request`'s URI.

def addSlash(request): (source)

Deprecated since version 16.0.0: `addSlash` was deprecated in Twisted 16.0.0.

Add a trailing slash to `request`'s URI. Deprecated, do not use.

def formatFileSize(size): (source)

Format the given file size in bytes to human readable format.

def getTypeAndEncoding(filename, types, encodings, defaultType): (source)

Undocumented

def isDangerous(path): (source)

Undocumented

def loadMimeTypes(mimetype_locations=None, init=mimetypes.init): (source)

Produces a mapping of extensions (with leading dot) to MIME types.

It does this by calling the `init` function of the `mimetypes` module. This will have the side effect of modifying the global MIME types cache in that module.

Multiple file locations containing mime-types can be passed as a list. The files will be sourced in that order, overriding mime-types from the files sourced beforehand, but only if a new entry explicitly overrides the current entry.

Parameters
mimetype_locations:iterable of paths or `None` | Optional. List of paths to `mime.types` style files that should be used.
init:callable | The init function to call. Defaults to the global `init` function of the `mimetypes` module. For internal use (testing) only.

dangerousPathError = (source)

Undocumented

def _addSlash(request): (source)

Add a trailing slash to `request`'s URI.

Parameters
request:An object conforming to `twisted.web.iweb.IRequest` | The incoming request to add the ending slash to.

Returns
`bytes` | A URI with a trailing slash, with query and fragment preserved.