MiscUtils.DictForArgs | index /usr/local/share/webware/MiscUtils/DictForArgs.py

`DictForArgs.py
See the doc string for the DictForArgs() function.
Also, there is a test suite in Tests/TestDictForArgs.py`

Modules

``

re |  |  |

Classes

``

exceptions.Exception(exceptions.BaseException)
  DictForArgsError

class DictForArgsError(exceptions.Exception)

``

Method resolution order:
  DictForArgsError
  exceptions.Exception
  exceptions.BaseException
  __builtin__.object

Data descriptors defined here:

__weakref__
  `list of weak references to the object (if defined)`

Methods inherited from exceptions.Exception:

__init__(...)
  `x.__init__(...) initializes x; see x.__class__.__doc__ for signature`

Data and other attributes inherited from exceptions.Exception:

__new__ = <built-in method __new__ of type object>
  `T.__new__(S, ...) -> a new object with type S, a subtype of T`

Methods inherited from exceptions.BaseException:

__delattr__(...)
  `x.__delattr__('name') <==> del x.name`

__getattribute__(...)
  `x.__getattribute__('name') <==> x.name`

__getitem__(...)
  `x.__getitem__(y) <==> x[y]`

__getslice__(...)
  `x.__getslice__(i, j) <==> x[i:j]
  Use of negative indices is not supported.`

__reduce__(...)

__repr__(...)
  `x.__repr__() <==> repr(x)`

__setattr__(...)
  `x.__setattr__('name', value) <==> x.name = value`

__setstate__(...)

__str__(...)
  `x.__str__() <==> str(x)`

__unicode__(...)

Data descriptors inherited from exceptions.BaseException:

__dict__

args

message

Functions

``

DictForArgs(s)
  `Build dictionary from arguments.
  Takes an input such as:
  x=3
  name="foo"
  first='john' last='doe'
  required border=3
  And returns a dictionary representing the same. For keys that aren't
  given an explicit value (such as 'required' above), the value is '1'.
  All values are interpreted as strings. If you want ints and floats,
  you'll have to convert them yourself.
  This syntax is equivalent to what you find in HTML and close to other
  ML languages such as XML.
  Returns {} for an empty string.
  The informal grammar is:
  (NAME [=NAME|STRING])*
  Will raise DictForArgsError if the string is invalid.
  See also: PyDictForArgs() and ExpandDictWithExtras() in this module.`

ExpandDictWithExtras(dict, key='Extras', delKey=1, dictForArgs=<function DictForArgs>)
  `Return a dictionary with the 'Extras' column expanded by DictForArgs().
  For example, given:
  { 'Name': 'foo', 'Extras': 'x=1 y=2' }
  The return value is:
  { 'Name': 'foo', 'x': '1', 'y': '2' }
  The key argument controls what key in the dictionary is used to hold
  the extra arguments. The delKey argument controls whether that key and
  its corresponding value are retained.
  The same dictionary may be returned if there is no extras key.
  The most typical use of this function is to pass a row from a DataTable
  that was initialized from a CSV file (e.g., a spreadsheet or tabular file).
  FormKit and MiddleKit both use CSV files and allow for an Extras column
  to specify attributes that occur infrequently.`

PyDictForArgs(s)
  `Build dictionary from arguments.
  Takes an input such as:
  x=3
  name="foo"
  first='john'; last='doe'
  list=[1, 2, 3]; name='foo'
  And returns a dictionary representing the same.
  All values are interpreted as Python expressions. Any error in these
  expressions will raise the appropriate Python exception. This syntax
  allows much more power than DictForArgs() since you can include
  lists, dictionaries, actual ints and floats, etc.
  This could also open the door to hacking your software if the input
  comes from a tainted source such as an HTML form or an unprotected
  configuration file.
  Returns {} for an empty string.
  See also: DictForArgs() and ExpandDictWithExtras() in this module.`

Data
`` |  | letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'