Module brine.barrel

Provides a way to wrap multiple interrelated functions, while preserving uniqueness.

author:Christopher O’Brien <obriencj@gmail.com>
license:LGPL v.3

Barrel

class brine.barrel.Barrel(*pairs, **values)[source]

Mapping supporting automatic brining of contained values when pickled. Provides the dict interface special methods.

__init__(*pairs, **values)[source]

Accepts a single optional positional argument, which must be a dict or an iterable of key,value pairs. Also accepts an arbutrary number of named parameters which will be used to create further mappings.

clear()[source]

Remove all key and value pairs in this Barrel, and clear the cache.

reset()[source]

Clears the internal cache. Any future sets or gets from this Barrel will cause full brining or unbrining rather than returning an already computed value.

If you retrieved a value from this barrel and want to load a new copy (possibly with different globals), calling reset() is a way to achieve such.

use_globals(glbls=None)[source]

Provide a different set of globals when rebuilding functions from their brined wrappers.

Wrapper Classes

class brine.barrel.BarreledObject(barrel, value)[source]

Abstract base class for barrel wrappers. Defines the interface required for a barrel to brine a value.

  • When created, should accept a parent barrel and a value to wrap
  • The get method should return a new copy of the wrapped value
  • Must define the __getstate__ and __setstate__ methods for pickle support.

Utility method for implementations to request that the parent barrel brine an internal value. This allows the barrel to act as a cache of the brining process.

Utility method for implementations to request that the parent barrel unbrine an internal value. This allows the barrel to act as a cache of the unbrining process.

get(with_globals)

Recreate a copy of the initial brined value

Parameters:

with_globals : globals() or dict-like

The global namespace to be used when recreating the value.

Returns:

value : object

A copy of the value originally passed to __init__

class brine.barrel.BarreledFunction(barrel, value)[source]

Bases: brine.barrel.BarreledObject, brine.BrinedFunction

A brined function in a barrel. This wrapper is created automatically around function instances in a Barrel when it is pickled.

class brine.barrel.BarreledMethod(barrel, value)[source]

Bases: brine.barrel.BarreledObject, brine.BrinedMethod

A brined bound method in a barrel. This wrapper is created automatically around instancemethod instances in a Barrel when it is pickled.

class brine.barrel.BarreledPartial(barrel, part)[source]

Bases: brine.barrel.BarreledObject, brine.BrinedPartial

A brined partial in a barrel. This wrapper is created automatically around partial instances in a Barrel when it is pickled.

Table Of Contents

Previous topic

Module brine

Next topic

Module brine.queues

This Page