compat Subpackage

Subpackage Description

Provides a compatibility layer among the different implementations and versions of Python. This is achieved by providing access to modules, classes, and functions via a uniform naming convention.

The following modules are available:

  • A command-line argument parser module, which provides a uniform implementation across Pythons, regardless of whether they have one in their standard library.
  • A built-ins module, which shadows the appropriate Python one and provides missing pieces.
  • A shadow of the Python collections module, which provides missing pieces.
  • A configuration file parser module, which shadows the appropriate Python one.

General Compatibility Functions

utilia.compat.iter_dict_keys(the_dict)

Returns an iterator which generates keys from the given dictionary.

In Python 2, attempts a call to the iterkeys method of an object.

Parameters:the_dict – an object conforming to the dictionary interface
Return type:a Python 2 dictionary iterator

In Python 3, attempts a call to the keys method of an object and wraps the resulting view in an iterator.

Parameters:the_dict – an object conforming to the dictionary interface
Return type:a Python 3 dictionary iterator
utilia.compat.iter_dict_values(the_dict)

Returns an iterator which generates values from the given dictionary.

In Python 2, attempts a call to the itervalues method of an object.

Parameters:the_dict – an object conforming to the dictionary interface
Return type:a Python 2 dictionary iterator

In Python 3, attempts a call to the values method of an object and wraps the resulting view in an iterator.

Parameters:the_dict – an object conforming to the dictionary interface
Return type:a Python 3 dictionary iterator
utilia.compat.iter_dict_items(the_dict)

Returns an iterator which generates key-value pairs from the given dictionary.

In Python 2, attempts a call to the iteritems method of an object.

Parameters:the_dict – an object conforming to the dictionary interface
Return type:a Python 2 dictionary iterator

In Python 3, attempts a call to the items method of an object and wraps the resulting view in an iterator.

Parameters:the_dict – an object conforming to the dictionary interface
Return type:a Python 3 dictionary iterator

General Compatibility Classes

class utilia.compat.AbstractBase_BASE

Generalized abstract class, which has abc.ABCMeta as its metaclass.

Subclass this in any implementation of Python supported by the library to create abstract methods and properties and use the __subclasshook__ override and the subclass registration machinery from abc.ABCMeta.