The parsing module

Tools for parsing strings and extracting certain types of information.

Functions

src.tools.parsing.findClosingParenthesis(expression, start=0)[source]

Find a matching parenthesis in an expression.

Parameters :

expression : str

The expression in which the closing parenthesis is sought.

start : int

The position of the first character after the opening parenthesis in the expression.

Returns :

int :

The position of the closing parenthesis, or -1 if no closing parenthesis is found.

Examples

>>> findClosingParenthesis("3 + @(cat) + @(dog)", 6)
9
src.tools.parsing.extractNamesOfType(expression, marker)[source]

Extract the names of bins which begin with a given character.

Parameters :

expression : str

The expression from which to extract the names of the bins of the desired type.

marker : str

The character or string which indicates the beginning of a bin name of the desired type.

Returns :

list of str :

A list of strings indicating the names of the bins of the relevant type.

Examples

>>> extractNamesOfType("3 + @(cat)*$(fish) + @(dog)/#(mouse)", "@")
['cat', 'dog']
src.tools.parsing.extractNames(expression)[source]

Extract the names of all data bins in some expression.

Parameters :

expression : str

The expression from which to extract the names of data bins.

Returns :

tuple of list of str :

A tuple of lists of strings. The first list contains the names of all constants used in the expression. The second contains the names of columns, and the third contains the names of parameters.

Examples

>>> extractNames("3 + @(cat) + @(dog)")
(['cat', 'dog'], [], [])
>>> extractNames("3 + @(cat)*$(fish) + @(dog)/#(mouse)")
(['cat', 'dog'], ['mouse'], ['fish'])
src.tools.parsing.tokenize(string, delimiter=', ')[source]

Split the string at the specified delimiter.

This function works similar to the built-in string function split except that it takes into account the possibility that the delimiter occurs inside some grouping construction (for example, quotation marks or list brackets) which should prevent splitting.

Parameters :

string : str

The string to split. If this string begins with a character which marks the start of a group, the matching closing character will end the tokenized list.

delimiter : str

The mark at which to split.

Returns :

list of str :

The list of tokens in the string.

str :

The contents of the string following the group-closing character which matches the character with which the input string started.

src.tools.parsing.escapeXML(string)[source]

Return an XML compliant string.

Parameters :

string : str

A string which may or may not contain characters which would be invalid in an XML document.

Returns :

str :

The input string with all improper characters replaced with appropriate escape sequences.

Table Of Contents

Previous topic

The htmlhelper module

Next topic

The stability module

This Page