Middleware and other components that can be used with other WSGI components.
Default Resolution set used, when no other was given in config.
Bases: object
A WSGI middleware to shrink images on-the-fly.
It works as a filter-wrapper that examines images delivered by other WSGI components and might reduce the image sizes on-the-fly.
The content types considered as handable. Only HTTP responses providing one of these types are handled by the middleware.
Create a resized version of current content image.
Get the client screen resolution from request.
Determine a desired resolution from client screen resolution and avaiilable resolutions.
Is the device that sent request a mobile?
Should we adapt the response from the wrapped app?
Should the given request be ignored?
A factory that returns ImageAdaptingMiddleware instances.
Regular expressions from http://detectmobilebrowsers.com/ (public domain)
Minor helper functions.
Get length of file denoted by a file descriptor.
As we cannot get a stat of files of which we only have a file descriptor (and no path or similar), we have to do some tricks to get the file-length anyway.
fd should be the descriptor of a file already open for reading.
Returns the length of file as an integer.
Get the desired resolution based on the input parameters.
Resize image to have width resolution.
image can be a path or some open file descriptor.
resolution gives the desired maximum width in pixels.
Returns None or a tuple
(<FORMAT>, <RESULT_FILE_FD>)
with <FORMAT> being an image type as determined by PIL and <RESULT_FILE_FD> being an opened temporary file.
If the image is already narrower than resolution, None is returned.
The same applies if the image cannot be read or the resizing operation fails.
Try to turn a string into a list of integers.
Turns strings like ‘1, 2, 3’ into regular lists like [1, 2, 3]. The number have to be comma-separated. Also lists with only one entry are handled correctly.