xsendfile API

class xsendfile.XSendfileApplication(root_directory, file_sender=None)

WSGI application which serves files in a given root directory by using the X-Sendfile feature in Web servers.

Parameters:
  • root_directory (basestring) – The absolute path to the root directory.
  • file_sender (a string of standard, nginx or serve, or a WSGI application.) – The application to use to send the requested file; defaults to the standard X-Sendfile.
Raises:
  • BadRootError – If the root directory is not an existing directory or is contained in a symbolic link
  • BadSenderError – If the file_sender is not valid.

File Senders

class xsendfile.XSendfile

File sender for the standard X-Sendfile.

class xsendfile.NginxSendfile(redirect_location='/-internal-')

File sender for the Nginx’ X-Sendfile equivalent.

Parameters:redirect_location – The prefix of the path to the internal location of the file, with SCRIPT_NAME preppended (if present).

Authorization tokens

class xsendfile.AuthTokenApplication(root_directory, token_config, file_sender=None)

Bases: xsendfile.XSendfileApplication

WSGI application that serves static files at URL paths that are valid for a determined time.

Parameters:
  • root_directory (basestring) – The absolute path to the root directory.
  • token_config (TokenConfig) – The token configuration object.
  • file_sender (a string of standard, nginx or serve, or a WSGI application.) – The application to use to send the requested file; defaults to the standard X-Sendfile.
class xsendfile.TokenConfig(secret, hash_algo='md5', timeout=120)

Configuration object for a protected directory.

Parameters:
  • secret (basestring) – The secret string shared by the application that generates the links and the WSGI application that serves the files.
  • hash_algo (basestring or callable) – The name of the built-in hashing algorithm to use or a callable that returns the required (hexadecimal) digest.
  • timeout (int) – The time during which a token is valid (in seconds)

Changed in version 1.0rc1: Removed ability to use a custom character encoding.

get_url_path(file_name)

Get the protected URL path for file_name.

Parameters:file_name (basestring) – The file to be served.
Return type:basestring

Exceptions

exception xsendfile.XSendfileException

Base class for exceptions raised by wsgi-xsendfile.

exception xsendfile.BadRootError

Exception raised when given a bad root directory to be served.

exception xsendfile.XSendfileException

Base class for exceptions raised by wsgi-xsendfile.