Package DebTorrent :: Module HTTPCache :: Class HTTPCache
[hide private]
[frames] | no frames]

Class HTTPCache

source code

Manage an HTTP download cache.

Instance Methods [hide private]
 
__init__(self, rawserver, cachedir)
Initialize the instance.
source code
 
download_get(self, path, func)
Create a new download from a site.
source code
 
remove(self, d, server)
Remove a completed download connection.
source code
 
download_complete(self, path, func, r)
Process the returned data from a request.
source code
(int, string, dictionary, string)
cache_get(self, path, uptodate=True, if_modified_time='')
Get the file from the cache.
source code
string
get_filename(self, path)
Get the file name used for this path in the cache.
source code
int
get_file_mtime(self, path)
Get the modification time of the file in the cache.
source code
int
check_mtime(self, http_mtime_string, path=[], file='', server_mtime_string='')
Check the modified time of a file in the cache against a server header string.
source code
Instance Variables [hide private]
string cachedir
the directory to save cache files in
dictionary downloads
the current downloads, keys are the server names, values are the CacheConnection objects used to download from the server
Debtorrent.RawServer.RawServer rawserver
the server
Method Details [hide private]

__init__(self, rawserver, cachedir)
(Constructor)

source code 
Initialize the instance.
Parameters:

download_get(self, path, func)

source code 
Create a new download from a site.
Parameters:
  • path (list of string) - the server and path to download
  • func (method) - the method to call with the data when the download is complete

remove(self, d, server)

source code 
Remove a completed download connection.
Parameters:
  • d (CacheConnection) - the server connection that is no longer needed
  • server (string) - the server the connection was to

download_complete(self, path, func, r)

source code 

Process the returned data from a request.

Once a download has been completed, save the downloaded file in the file system. Then return the data to the callback function.
Parameters:
  • path (list of string) - the server and path that was downloaded
  • func (method) - the method to call with the data
  • r ((int, string, dictionary, string)) - the HTTP status code, status message, headers, and downloaded data

cache_get(self, path, uptodate=True, if_modified_time='')

source code 

Get the file from the cache.

Will respond with the following HTTP status codes:
  • 200: the file was found in the cache and is up to date
  • 304: the file is up to date, but is not needed
  • 404: the file was not found in the cache
  • 405: the file was found, but is stale, and needs to be refreshed
Parameters:
  • path (list of string) - the server and path to download
  • uptodate (boolean) - whether to check the age of the file on the server to see if the cached one is still current (optional, defaults to False)
  • if_modified_time (string) - the if-modified-since header from the request (optional, defaults to not checking the if-modified-time)
Returns: (int, string, dictionary, string)
the HTTP status code, status message, headers, and package data

get_filename(self, path)

source code 
Get the file name used for this path in the cache.
Parameters:
  • path (list of string) - the server and path to download
Returns: string
the file name

get_file_mtime(self, path)

source code 
Get the modification time of the file in the cache.
Parameters:
  • path (list of string) - the server and path to check
Returns: int
the file's modification time, or 0 if the file is not found

check_mtime(self, http_mtime_string, path=[], file='', server_mtime_string='')

source code 
Check the modified time of a file in the cache against a server header string.
Parameters:
  • http_mtime_string (string) - the modified time from an HTTP header
  • path (list of string) - the server and path to download (optional, but one of file/path/server_mtime must be specified)
  • file (string) - the file name in the cache (optional, but one of file/path/server_mtime must be specified)
  • server_mtime_string (string) - the last-modified time from the server's copy (optional, but one of file/path/server_mtime must be specified)
Returns: int
the number of seconds the header's mtime is ahead of the file's mtime (or None if the file isn't in the cache)