ArgProc

A rule-based arguments processor
Download

ArgProc Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Geert Jansen
  • Publisher web site:
  • http://www.boskant.nl/trac/python-ad

ArgProc Tags


ArgProc Description

A rule-based arguments processor ArgProc is a rule-based argument processing module for Python. It transforms between a "left" and a "right" representation of a set of arguments based on rules in a visual, domain-specific language. The following operations are supported. * Checking for completeness: are all mandatory arguments present. * Validation: ensure that the arguments conform to a specific type or format. * Renaming: change names between left and right. * Arbitrary transforms on the value of the arguments. ArgProc has useful applications in web form processing and data format conversion.TutorialThe code below gives an example of an argument "id" that is passed on verbatim between left and right. A second field called "left" is renamed to "right" instead. All arguments start with a dollar sign ('$').from argproc import ArgumentProcessorproc = ArgumentProcessor()proc.rules(""" $id $id $left $right""")proc.process(left) # Converts from "left" to "right"proc.reverse(right) # Converts from "right" to "left"The example below shows you how to make a rule mandatory (add an asterisk '*'). Both left and right hand sides can be mandatory. It also shows how to specify rules that are unidirectional. In this case, the argument "left" would be converted when doing a left to right conversion, but not the other way around.proc.rules(""" $id * $id $left => $right""")The example below adds in validations. A validation is separated from a field name with a colon ':'. The first rule ensures that "id" is a valid integer, the second rule ensures that "left" has either the string value 'value1' or 'value2'.proc.rules(""" $id:int $id $left:('value1', 'value2') => $right""")In the final example we add in transformations and also multiple assignment. The "split" and "concat" functions are Python functions that need to exist in the current global or local namespace. proc.rules(""" int($id) str($id) concat($year, $month, $day) split($date)""")InstallationArgProc is availble from the Python Package Index, so you can use easy_install:easy_install argprocYou can also check out the sources and build them youself:hg clone http://bitbucket.org/geertj/argproccd argprocpython setup.py buildpython setup.py test # optionalpython setup.py install Requirements: · Python


ArgProc Related Software