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 details)
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae474b60114b90257f6813129be54db31eb9a31fdad84fb9ba736adc81a6aa11 |
|
MD5 | 7e9389bdb6fa0d8c10a903f65d4a3171 |
|
BLAKE2b-256 | 9ac548bea13fef48571c3c247a5476836067eaf18d52ddd12fde22d69f854c78 |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 235d874b1cf35aa8184b40cdb247cd9d59fc00b311a5604c348505cb43bf65ac |
|
MD5 | cab2c8945591d6701c22bd9c5f26015d |
|
BLAKE2b-256 | 2eb8fad38da9528b4348623c6b4eca57f85907851c3a2e7717313345231516ea |