Skip to main content

Text Parsing Function Dispatcher

Project description

https://travis-ci.org/erinxocon/tpfd.svg?branch=master https://img.shields.io/pypi/v/tpfd.svg?maxAge=2592000:target: https://img.shields.io/pypi/l/tpfd.svg?maxAge=2592000:target:

TPFD is an easy way to parse strings and execute functions depending on their contents.

Inspired by Flask and using Parse under the hood, this allows you to decorate functions with grammar rules and if a pattern that matches one of your grammar rules is found, the function will be run with a set of keyword arguments you’ve specified passed to it! Great for parsing logs and executing macros on what it finds!

Examples

Aniamls.txt
Turtles are cool
Sloths are cool
Mosquitos are dumb

>>> p  = tpfd.Parser()

>>> @p.on_parse('{Animal} are cool')
    def main(animal):
        print('I like {0}.'.format(animal))

>>> p.parse_file('animals.txt')
'I like turtles.'
'I like sloths.'

>>> p.parse(['Turtles are cool', 'Sloths are cool', 'Mosquitos are dumb'])
'I like turtles.'
'I like sloths.'

>>> p.parse('Sloths are cool')
'I like sloths.'

>>> p.parse('Mosquitos are dumb')
None

>>> @p.on_find('>{}<')
    def find_example(words):
    print (words)

>>> p.find_string('<p>the <b>bold</b> text</p>')
'the bold text'

To Install

$ pip install tpfd

Notes

Any format spec supported by parse is supported by this library since it’s all parse under the hood. Example: {[field name]:[format spec]}

Current Features

  • Support for parsing text files

  • Support for accepting generators that output text or ints

  • Support for parsing unicode strings

  • Supports parsing strings, ints and interator/generator’s automagically with new parse method.

TODO

  • Expose custom types functionality that Parse already offers

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tpfd-0.2.1.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file tpfd-0.2.1.tar.gz.

File metadata

  • Download URL: tpfd-0.2.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tpfd-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7412e1daf070d69eb44840232291ee2c6b5f45a99d8ba3e86ba74e1d16a8ca4e
MD5 130e29c2e3cd30f754d34b641992c933
BLAKE2b-256 918bcdccafd8d178b7e86e8ef78ff2a0e7fdcdd53f77afd20e326c7e56b0d0c0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page