Commits

Ben Bangert committed d6450f4 Merge

Comments (0)

Files changed (1)

webhelpers/containers.py

 
         From the Python Cookbook.  Written by Jason Kirtland.
         http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523034
+
         """
         def __init__(self, default_factory=None, *a, **kw):
             if (default_factory is not None and
     """A default value for function args.
 
     Use this when you need to distinguish between ``None`` and no value.
+    
+    Example::
+    
+        >>> def foo(arg=NotGiven):
+        ...     print arg is NotGiven
+        ...
+        >>> foo()
+        True
+        >>> foo(None)
+        False
 
-    >>> def foo(arg=NotGiven):
-    ...     print arg is NotGiven
-    ...
-    >>> foo()
-    True
-    >>> foo(None)
-    False
     """
     pass
 
 class DumbObject(object):
     """A container for arbitrary attributes.
 
-    Usage:
-    >>> do = DumbObject(a=1, b=2)
-    >>> do.b
-    2
+    Usage::
+    
+        >>> do = DumbObject(a=1, b=2)
+        >>> do.b
+        2
     
     Alternatives to this class include ``collections.namedtuple`` in Python
     2.6, and ``formencode.declarative.Declarative`` in Ian Bicking's FormEncode
     package.  Both alternatives offer more featues, but ``DumbObject``
     shines in its simplicity and lack of dependencies.
+
     """
     def __init__(self, **kw):
         self.__dict__.update(kw)
 
     This can be displayed in an HTML table via the following Mako template:
 
-    <table>
-    % for row in table:
-      <tr>
-    % for cell in row:
-        <td>${cell}</td>
-    % endfor   cell
-      </tr>
-    % endfor   row
-    </table>
+    .. code-block:: html+mako
+
+        <table>
+        % for row in table:
+          <tr>
+        % for cell in row:
+            <td>${cell}</td>
+        % endfor   cell
+          </tr>
+        % endfor   row
+        </table>
 
     In a horizontal table, each row is filled before going on to the next row.
     This is the same as dividing the list into chunks.
 
-    >>> distribute([1, 2, 3, 4, 5, 6, 7, 8], 3, "H")
-    [[1, 2, 3], [4, 5, 6], [7, 8, None]]
+    .. code-block:: pycon
+    
+        >>> distribute([1, 2, 3, 4, 5, 6, 7, 8], 3, "H")
+        [[1, 2, 3], [4, 5, 6], [7, 8, None]]
 
     In a vertical table, the first element of each sublist is filled before
     going on to the second element.  This is useful for displaying an
     alphabetical list in columns, or when the entire column will be placed in
     a single <td> with a <br /> between each element.
 
-    >>> food = ["apple", "banana", "carrot", "daikon", "egg", "fish", "gelato", "honey"]
-    >>> table = distribute(food, 3, "V", "")
-    >>> table
-    [['apple', 'daikon', 'gelato'], ['banana', 'egg', 'honey'], ['carrot', 'fish', '']]
-    >>> for row in table:
-    ...    for item in row:
-    ...         print "%-9s" % item,
-    ...    print "."   # To show where the line ends.
-    ...
-    apple     daikon    gelato    .
-    banana    egg       honey     .
-    carrot    fish                .
+    .. code-block:: pycon
+
+        >>> food = ["apple", "banana", "carrot", "daikon", "egg", "fish", "gelato", "honey"]
+        >>> table = distribute(food, 3, "V", "")
+        >>> table
+        [['apple', 'daikon', 'gelato'], ['banana', 'egg', 'honey'], ['carrot', 'fish', '']]
+        >>> for row in table:
+        ...    for item in row:
+        ...         print "%-9s" % item,
+        ...    print "."   # To show where the line ends.
+        ...
+        apple     daikon    gelato    .
+        banana    egg       honey     .
+        carrot    fish                .
 
     Alternatives to this function include a NumPy matrix of objects.
+
     """
     if columns < 1:
         raise ValueError("arg 'columns' must be >= 1")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.