This software provides classes which can be used to create and wrap file-like objects.
Filelike provides a number of useful classes built on top of this functionality. The primary class is FileLikeBase, which implements the entire file-like interface on top of primitive _read(), _write(), _seek() and _tell() methods. The subclass implementation method is used to obtain the related higher-level file behaviors.
In addition to the incredible functionalities, the software provides some neat file-handling functions. It offers an open function that mirrors the standard open() function but is more intelligent. URLs are fetched automatically, .bz2 files are decompressed seamlessly, and so on. It also provides a join function that concatenates multiple file-like objects together so that they can act as a single file. You can also access a section of a file-like object using the slice function, and it will seem like an independent file.
The "wrappers" subpackage contains a collection of useful classes built on top of this framework. These classes include the Translate class that passes file contents through an arbitrary translation function such as compression, encryption, etc. The Decrypt class enables on-the-fly reading and writing encrypted files using PEP272 cipher API. It also provides an UnBZip2 class that offers on-the-fly decompression of bzip'd files, similar to the standard library's bz2 module, but accepts any file-like object.
As an example of the type of thing that this module is designed to achieve, you can use the Decrypt wrapper to access an encrypted file transparently. You can create the decryption key from Crypto.Cipher and open the encrypted file from filelike.wrappers using the Decrypt method.
The "pipeline" subpackage in the software contains facilities for composing these wrappers in the form of a unix pipeline. For example, 'f' will read the first five lines of an encrypted file in the following script: from filelike.pipeline import Decrypt, Head f = file("some_encrypted_file.bin") > Decrypt(cipher) | Head(lines=5)
Finally, two utility functions are provided for when code expects to deal with file-like objects: is_filelike(obj), which checks if an object is file-like and to_filelike(obj), which wraps a wide variety of objects in a file-like interface.
Version 0.3.4: N/A