Easily build Enum-like regular expression patterns
Reason this release was yanked:
Incorrect lower bound for python-version
Project description
renum
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
Release history Release notifications | RSS feed
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 hashes)