l.s.l.utils : module documentation

Part of lp.services.librarian

No module docstring
Function filechunks Return an iterator which reads chunks of the given file.
Function copy_and_close Copy from_file to to_file and close both.
Function sha1_from_path Return the hexdigest SHA1 for the contents of the path.
Function guess_librarian_encoding Return the appropriate encoding for the given filename and mimetype.
def filechunks(file, chunk_size=4 * MEGABYTE):
Return an iterator which reads chunks of the given file.
def copy_and_close(from_file, to_file):
Copy from_file to to_file and close both.

It requires both arguments to be opened file-like objects. 'filechunks' trick is used reduce the buffers memory demanded when handling large files. It's suitable to copy contents from ILibraryFileAlias instances to the local filesystem. Both file_descriptors are closed before return.

def sha1_from_path(path):
Return the hexdigest SHA1 for the contents of the path.
def guess_librarian_encoding(filename, mimetype):

Return the appropriate encoding for the given filename and mimetype.

Files with the following extensions will be served as 'Content-Encoding: gzip' and 'Content-Type: text/plain', which indicates to browsers that, after being unzipped, their contents can be rendered inline.

  • 'txt.gz': gzipped sources buildlogs;
  • 'diff.gz': gzipped sources diffs;
Parametersfilenamestring containing the filename to be guessed;
mimetypestring containing the stored mimetype;
Returnsa tuple containing the appropriate 'encoding' and 'mimetype' that should be used to serve the file.
API Documentation for Launchpad, generated by pydoctor at 2018-05-27 00:00:04.