Skip to main content

permtab

A simple permission rule parsing library.

Installation

Install permtab via pip:

pip install permtab

Format

Permtab uses a syntax similar to crontab, although it is actually a reversed version. Actually, the shlex is used for parsing.

# *.permtab
<rulename> <filter...>

Here filter has the same meaning with rule and condition.

NOTE: Leading a rule to True only needs one filter that returns True.

Here is an example:

myrule1     owner_1234  operator_8525   operator_8390
myrule2     text_hello  text_world      "text_hello world!"
*           user_any
# The tab rule with name '*' is considered a base rule.
# If not defined, the default rule will pass everything to other rules.

Rule factory

Rule factory is a function which exports a checker function.

This is a generic definition:

import permtab

def factory(*args, **kwargs):
    def _checker(*args, **kwargs):
        return CONDITION
    return _checker

permtab.register_rulefactory(REGEX_FOR_THE_FACTORY, factory)

Exactly, the parameters for rule factory and checker depend on their use.

The parameters for rule factory is decided by groups in provided regex. All groups that matched are unpacked to positional arguments, and all named groups that matched are unpacked to keyword arguments.

Checkers' parameters are decided by where the checker called.

NOTE: Parameters provided by named groups are all in common groups.

NOTE: Dependency injection will not work by default, so you must patch some functions to export new functions that support dependency injection if needed.

Loading and using permtab

This step is quite easy:

import permtab

permtab.load("/path/to/your.permtab")  # load "/path/to/your.permtab"

rule = permtab.find_rule("your_rule_name")  # get rule function, then use it

def f():
    if rule(...):
        ...  # run if the condition is satisfied
    else:
        ...  # otherwise

Editing a permtab

Editing uses a + and - marker on a rule to control changes.

Here is an example:

import permtab

parsed = permtab.parse("test.permtab")
# DO NOT parse and edit the SAME FILE at the same time
# Otherwise your data may be lost

with open("test.permtab", "w") as f:
    f.writelines(
        permtab.edit(
            parsed,
            {
                "myrule1": ("-t_aeiou", "-t_hello world!"),
                # add a `-` to remove an existing rule
                "myrule2": ("+t_hellp",),
                # add a `+` to add a new rule
                "myrule3": ("+t_foo", "+t_bar", "-t_foo")
                # `+` and `-` operation can take effect at the same time
                # duplicate changes will be evaluated
            }
        )
    )

permtab.reset_rule()  # remove rules previously loaded
permtab.load("test.permtab")  # reload new permtab

Metadata

Release files for permtab 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for permtab 0.1.0
File Size Uploaded Provenance Actions
permtab-0.1.0.tar.gz 4.9 kB Without provenance Details for permtab-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for permtab 0.1.0
File Interpreter ABI Platform Actions
permtab-0.1.0-py3-none-any.whl Python 3 none any Details for permtab-0.1.0-py3-none-any.whl

Total release size: 10.8 kB

Release files / permtab-0.1.0.tar.gz

Download URL permtab-0.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e65b62f2cf97b58ac47162df1d167307eb67487d2ed135d7fc4cbabc1c751f76
BLAKE2b-256 checksum
How to use checksums
635149c7bbc495ed60066e653d6ccb68ea76f38c4c00c6b3e2df57ec755c2503
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / permtab-0.1.0-py3-none-any.whl

Download URL permtab-0.1.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
970f0ccd8e18359877e3f49299ef9dc0e6c9d9a0e804533fe8c2f4be84dcca8a
BLAKE2b-256 checksum
How to use checksums
2170064ad37e7bd48e197e3e65e20efd554a6ed2d9358b1b8acf6fd4ee864b1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for permtab 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page