psicons.core.impl

Package psicons :: Package core :: Module impl |
[hide private]
[frames] | no frames]

# Source Code for Module psicons.core.impl

     1  #! /usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3  """
     4  Internal implementation utilities and details.
     5
     6  This module contains various odds and ends to make development easier. None of
     7  the code within should be relied upon as it is subject to change at a whim.
     8  """
     9
    10  __docformat__ = 'restructuredtext en'
    11
    12
    13  ### IMPORTS ###
    14
    15  import types
    16
    17  __all__ = [
    18          'make_list',
    19  ]
    20
    21
    22  ### CONSTANTS & DEFINES ###
    23
    24  ### IMPLEMENTATION ###
    25
    26 -def make_list (x):
    27          """
    28          If this isn't a list, make it one.
    29
    30          :Parameters:
    31                  x : list, tuple, other
    32                          a sequence, or a single element to be placed in a sequence
    33
    34          :Returns:
    35                  Either the original a parameter if a sequence, or the parameter placed in
    36                  a list.
    37
    38          Syntactic sugar for allowing method calls to be single elements or lists of
    39          elements.
    40
    41          For example::
    42
    43                  >>> make_list (1)
    44                  [1]
    45                  >>> make_list ('1')
    46                  ['1']
    47                  >>> make_list ([1, 2])
    48                  [1, 2]
    49                  >>> make_list ((1, 2))
    50                  (1, 2)
    51
    52          """
    53          # TODO: should be a more general way of doing this
    54          if (type (x) not in (types.ListType, types.TupleType)):
    55                  x = [x]
    56          return x
    57
    58
    59  ## DEBUG & TEST ###
    60
    61  if __name__ == "__main__":
    62          import doctest
    63          doctest.testmod()
    64
    65
    66
    67  ### END #######################################################################
    68