Skip to main content

Classes for creating and wrapping file-like objects

Project description

filelike: a python module for creating and handling file-like objects.

This module takes care of the groundwork for implementing and manipulating objects that provide a rich file-like interface, including reading, writing, seeking and iteration. It also provides a number of useful classes built on top of this functionality.

The main class is FileLikeBase, which implements the entire file-like interface on top of primitive _read(), _write(), _seek() and _tell() methods. Subclasses may implement any or all of these methods to obtain the related higher-level file behaviors.

It also provides some nifty file-handling functions:

open:

mirrors the standard open() function but is much cleverer; URLs are automatically fetched, .bz2 files are transparently decompressed, and so-on.

join:

concatenate multiple file-like objects together so that they act like a single file.

slice:

access a section of a file-like object as if it were an independent file.

The “wrappers” subpackage contains a collection of useful classes built on top of this framework. These include:

Translate:

pass file contents through an arbitrary translation function (e.g. compression, encryption, …)

Decrypt:

on-the-fly reading and writing to an encrypted file (using PEP272 cipher API)

UnBZip2:

on-the-fly decompression of bzip’d files (like the standard library’s bz2 module, but accepts any file-like object)

As an example of the type of thing this module is designed to achieve, here’s how the Decrypt wrapper can be used to transparently access an encrypted file:

# Create the decryption key
from Crypto.Cipher import DES
cipher = DES.new('abcdefgh',DES.MODE_ECB)
# Open the encrypted file
from filelike.wrappers import Decrypt
f = Decrypt(file("some_encrypted_file.bin","r"),cipher)

The object in ‘f’ now behaves as a file-like object, transparently decrypting the file on-the-fly as it is read.

The “pipeline” subpackage contains facilities for composing these wrappers in the form of a unix pipeline. In the following example, ‘f’ will read the first five lines of an encrypted file:

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):

checks that an object is file-like

to_filelike(obj):

wraps a variety of objects in a file-like interface

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filelike-0.3.4.tar.gz (37.0 kB view details)

Uploaded Source

Built Distributions

filelike-0.3.4-py2.6.egg (104.6 kB view details)

Uploaded Source

filelike-0.3.4-py2.5.egg (104.7 kB view details)

Uploaded Source

File details

Details for the file filelike-0.3.4.tar.gz.

File metadata

  • Download URL: filelike-0.3.4.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for filelike-0.3.4.tar.gz
Algorithm Hash digest
SHA256 c8882b15ad17c1ee189004db4e23de30152574caa0dd993fb764b275403c646d
MD5 d39046324908a04851645aeea3ae365c
BLAKE2b-256 c7734d6a923b50aa73638f8ad8fd942ecde1ad4be3268d6697831eaadb9eefb5

See more details on using hashes here.

File details

Details for the file filelike-0.3.4-py2.6.egg.

File metadata

  • Download URL: filelike-0.3.4-py2.6.egg
  • Upload date:
  • Size: 104.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for filelike-0.3.4-py2.6.egg
Algorithm Hash digest
SHA256 b07ab57ebe8e25d22ad90d1d59c9e7b971085fdd53b9f162905d13fb931331d3
MD5 1ad21236a8d450c852cce37b1ef0125d
BLAKE2b-256 6d1cb926985744905f5b4ee887f4d92f79e7baa6fbac534add190ed07481ade0

See more details on using hashes here.

File details

Details for the file filelike-0.3.4-py2.5.egg.

File metadata

  • Download URL: filelike-0.3.4-py2.5.egg
  • Upload date:
  • Size: 104.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for filelike-0.3.4-py2.5.egg
Algorithm Hash digest
SHA256 e5002309bf5531098024af70cec9b614cbc93ead5e136d17095876f24cda741b
MD5 fe6e13bddb9941bd40c1126975ab3a20
BLAKE2b-256 5862973abcf7aa8352d0d6e69dc4de0a42032f2cf54f2b6ee0a6d1799a94af3d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page