Gelatin.util module¶
-
Gelatin.util.
compile
(syntax_file, encoding='utf8')[source]¶ Like compile_string(), but reads the syntax from the file with the given name.
Parameters: - syntax_file (str) – Name of a file containing Gelatin syntax.
- encoding (str) – Character encoding of the syntax file.
Return type: compiler.Context
Returns: The compiled converter.
-
Gelatin.util.
compile_string
(syntax)[source]¶ Builds a converter from the given syntax and returns it.
Parameters: syntax (str) – A Gelatin syntax. Return type: compiler.Context Returns: The compiled converter.
-
Gelatin.util.
generate
(converter, input_file, format='xml', encoding='utf8')[source]¶ Given a converter (as returned by compile()), this function reads the given input file and converts it to the requested output format.
Supported output formats are ‘xml’, ‘yaml’, ‘json’, or ‘none’.
Parameters: - converter (compiler.Context) – The compiled converter.
- input_file (str) – Name of a file to convert.
- format (str) – The output format.
- encoding (str) – Character encoding of the input file.
Return type: str
Returns: The resulting output.
-
Gelatin.util.
generate_string
(converter, input, format='xml')[source]¶ Like generate(), but reads the input from a string instead of from a file.
Parameters: - converter (compiler.Context) – The compiled converter.
- input (str) – The string to convert.
- format (str) – The output format.
Return type: str
Returns: The resulting output.
-
Gelatin.util.
generate_string_to_file
(converter, input, output_file, format='xml', out_encoding='utf8')[source]¶ Like generate(), but reads the input from a string instead of from a file, and writes the output to the given output file.
Parameters: - converter (compiler.Context) – The compiled converter.
- input (str) – The string to convert.
- output_file (str) – The output filename.
- format (str) – The output format.
- out_encoding (str) – Character encoding of the output file.
Return type: str
Returns: The resulting output.
-
Gelatin.util.
generate_to_file
(converter, input_file, output_file, format='xml', in_encoding='utf8', out_encoding='utf8')[source]¶ Like generate(), but writes the output to the given output file instead.
Parameters: - converter (compiler.Context) – The compiled converter.
- input_file (str) – Name of a file to convert.
- output_file (str) – The output filename.
- format (str) – The output format.
- in_encoding (str) – Character encoding of the input file.
- out_encoding (str) – Character encoding of the output file.
Return type: str
Returns: The resulting output.