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 Testing/TestDictForArgs.py`

Modules

``

re | string |  |

Classes

``

exceptions.Exception
  DictForArgsError

class DictForArgsError(exceptions.Exception)

``

Methods inherited from exceptions.Exception:

__getitem__(...)

__init__(...)

__str__(...)

Functions

``

DictForArgs(s)
  `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>)
  `Returns 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)
  `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'