Package csb :: Package core
[frames] | no frames]

Package core

source code

Generic containers, data structures and language extensions.

This module has several functions:

  1. provides a set of reusable, probably encapsulated collection containers and supporting infrastructure: BaseDictionaryContainer, BaseCollectionContainer; also AbstractIndexer
  2. provides some missing generic data structures or data types: OrderedDict, Stack; also the heavily used, type-safe enum class and some generic pattern implementations like singleton or Proxy
  3. serves as a compatibility layer, making it possible to develop CSB as platform- and Python version-independent: string, iterable, metaclass

In order to ensure cross-interpreter compatibility, checking for string instances in CSB must always be implemented like this:

>>> isinstance("s", string)

because "basestring" is not available in Python 3. Also, metaclass definitions other than abstract classes must be implemented as follows:

>>> MyClassBase = metaclass(MetaClass, base=BaseClass)
>>> class MyClass(MyClassBase):
        pass

See also the notes about compatibility in csb.io.

Classes
  AbstractContainer
Defines the behavior of a high-level object, which can hold an array of elements.
  AbstractIndexer
  AbstractNIContainer
Same as the AbstractContainer, but provides access to the child elements through AbstractNativeIndexer._getinternal instead of the standard __getitem__.
  BaseCollectionContainer
Base class which defines the behavior of a read-only collection container.
  BaseDictionaryContainer
Base class which defines the behavior of a read only key-value collection container.
  CollectionContainer
Write-enabled Collection Container.
  CollectionIndexError
  Container
Generic implementation of AbstractContainer.
  DictionaryContainer
Write-enabled Dictionary Container.
  DuplicateKeyError
  Enum
A collection of efficient static methods for working with enum classes.
  EnumBase
  EnumItem
  EnumMemberError
  EnumMeta
Metaclass for enum types.
  EnumValueError
  InterruptibleThread
  InvalidKeyError
  ItemNotFoundError
  OrderedDict
  Proxy
Base class implementing the proxy pattern.
  REMatchProxy
  ReadOnlyCollectionContainer
This is a write-once container, which is filled with items only at object construction.
  ReadOnlyDictionaryContainer
This is a write-once container, which is filled with items only at object construction.
  Stack
  enum
Base class for all enumeration types.
  typedproperty
Property decorator for convenient creation of typed, encapsulated fields.
  validatedproperty
Property decorator with predefined getter/setter and value checking or casting in the setter.
Functions
 
deepcopy(obj, recursion=100000)
Perform a deep copy of obj using cPickle.
source code
bool
iterable(obj)
Return True if obj is a collection or iterator, but not string.
source code
 
metaclass(meta, base=<type 'object'>)
Return a new class with parent class base and metaclass meta.
source code
 
singleton(klass)
Singleton class decorator.
source code
Variables
  __package__ = 'csb.core'
Function Details

deepcopy(obj, recursion=100000)

source code 

Perform a deep copy of obj using cPickle. Faster than copy.deepcopy() for large objects.

Parameters:
  • obj - the object to copy
  • recursion (int) - maximum recursion limit
Returns:
a deep copy of obj

iterable(obj)

source code 

Return True if obj is a collection or iterator, but not string. This is guaranteed to work in both python 2 and 3.

Returns: bool

metaclass(meta, base=<type 'object'>)

source code 

Return a new class with parent class base and metaclass meta. This works in both python 2 and 3.