Metadata-Version: 2.1
Name: renum
Version: 0.0.1b0
Summary: Easily build Enum-like regular expression patterns
Author: Zephyrkul
License: MIT License
        
        Copyright (c) 2024 - 2024
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/Zephyrkul/renum
Project-URL: repository, https://github.com/Zephyrkul/renum.git
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: <4.0,>=3.7.0
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: regex
Requires-Dist: importlib_metadata>=1.4.0; python_version < "3.8"
Provides-Extra: docs
Requires-Dist: Sphinx~=5.3; extra == "docs"

# renum

[![pypi](https://img.shields.io/pypi/v/renum.svg)](https://pypi.org/project/renum/)
[![Licensed under the MIT License](https://img.shields.io/pypi/l/renum.svg)](https://choosealicense.com/licenses/mit/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Zephyrkul/sans/master.svg)](https://results.pre-commit.ci/latest/github/Zephyrkul/sans/master)

**Re**gex E**num**

A utility class for generating [Enum](https://docs.python.org/3/library/enum.html#enum.Enum)-like regular expression patterns.

## Installing

```sh
python3 -m pip install -U renum
```

Development version:

```sh
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](https://github.com/Zephyrkul/sans/issues/new/choose).

## Examples

Scanning through happenings from an XML file:

```py
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

- [Python 3.7+](https://www.python.org/)
- [regex](https://pypi.org/project/regex/)
