Skip to main content

Easily build Enum-like regular expression patterns

Reason this release was yanked:

Incorrect lower bound for python-version

Project description

renum

pypi Licensed under the MIT License Ruff pre-commit.ci status

Regex Enum

A utility class for generating Enum-like regular expression patterns.

Installing

python3 -m pip install -U renum

Development version:

python3 -m pip install -U https://github.com/Zephyrkul/renum/archive/master.zip#egg=renum

Support

If you need help with using renum, find a bug, or have a feature request, feel free to file an issue.

Examples

Scanning through happenings from an XML file:

import xml.etree.ElementTree as ET

from renum import renum


class HappeningsRenum(renum):
    ADMITTED = r"@@(?P<nation>[^@]+)@@ was admitted to the World Assembly\."
    MOVED = r"@@(?P<nation>[^@]+)@@ relocated from %%(?P<from>[^%]+)%% to %%(?P<to>[^%]+)%%\."
    ENDORSED = r"@@(?P<endorser>[^@]+)@@ endorsed @@(?P<endorsee>[^@]+)@@\."
    WITHDREW_ENDORSEMENT = r"@@(?P<endorser>[^@]+)@@ withdrew its endorsement from @@(?P<endorsee>[^@]+)@@\."


def main():
    root = ET.parse("happenings.xml")
    for element in root.iterfind("HAPPENINGS/EVENT/TEXT"):
        event = HappeningsRenum.fullmatch(element.text)
        if event is HappeningsRenum.ADMITTED:
            print("Welcome to the WA, %s!" % event.last_match.group("nation"))
        elif (
            event is HappeningsRenum.MOVED
            and event.last_match.group("to") == "the_rejected_realms"
        ):
            print("Welcome to TRR, %s!" % event.last_match.group("nation"))
        elif (
            event is HappeningsRenum.ENDORSED
            and event.last_match.group("endorsee") == "zephyrkul"
        ):
            print(
                "Thanks for the endorsement, %s!" % event.last_match.group("endorser")
            )
        elif (
            event is HappeningsRenum.WITHDREW_ENDORSEMENT
            and event.last_match.group("endorsee") == "zephyrkul"
        ):
            print("But why, %s? \N{PENSIVE FACE}" % event.last_match.group("endorser"))


if __name__ == "__main__":
    main()

Requirements

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

renum-0.0.1b0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

renum-0.0.1b0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file renum-0.0.1b0.tar.gz.

File metadata

  • Download URL: renum-0.0.1b0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for renum-0.0.1b0.tar.gz
Algorithm Hash digest
SHA256 ae474b60114b90257f6813129be54db31eb9a31fdad84fb9ba736adc81a6aa11
MD5 7e9389bdb6fa0d8c10a903f65d4a3171
BLAKE2b-256 9ac548bea13fef48571c3c247a5476836067eaf18d52ddd12fde22d69f854c78

See more details on using hashes here.

File details

Details for the file renum-0.0.1b0-py3-none-any.whl.

File metadata

  • Download URL: renum-0.0.1b0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for renum-0.0.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 235d874b1cf35aa8184b40cdb247cd9d59fc00b311a5604c348505cb43bf65ac
MD5 cab2c8945591d6701c22bd9c5f26015d
BLAKE2b-256 2eb8fad38da9528b4348623c6b4eca57f85907851c3a2e7717313345231516ea

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