Skip to main content
Simple string conditions
================

A small python package which evaluates string based conditions.

As an example let's say you have a class which creates a HTML link
but this link can have some widgets attached to it such as a tooltip,
popover, dropdown, modal etc.

Normally you would declare what widgets are supported by your class in
an array or dict and loop through it to perform the validations
but here comes the tricky part, some widgets don't get
well together. Like the tooltip with the popover or the modal with the
dropdown so you must somehow enforce a condition for each one in part
which takes a lot of time, it's not elegant and not isolated (why should
the tooltip care about the popover?).

As a response to such needs I've created this small library which takes a
string such as `(dropdown modal href) (tooltip popover) title` and evaluates
it so that we can ensure an exception is thrown if we supply both a modal
and a dropdown to the same link for example. The library supports more
trickery so here are a few examples and their 'translations' respectively:

`href&text (dropdown modal) (tooltip popover title)` - `href` and `text` are
required attributes, you can also supply a dropdown or modal and you can also
provide a tooltip, popover or title attribute.

`href&text title|tooltip` - `href` and `text` are required, any or both of
title and tooltip must be provided.

`title|text|href` - any or all must be provided

`title&text` - both are required

`(title&text|tooltip popover)` - one of the group can be provided and it's
either `title + text or tooltip` or `popover`

### To wrap things up ######

`&` (and) binds values and makes them both required
`|` (or) any or all of the values separated by pipe can be supplied
`()` (exclusive) group of exclusive values (only one value from the group can be supplied) .
The group values can also be glued with either `&` or `|` operators and they
will get evaluated accordingly.

... open to suggestions. For more examples you can read the `tests.py` file

P.S. Usage:

from string_conditions.base import validate, StringConditionsException

try:
validate( "title&text", ["title", "foo", "bar"] )
except StringConditionsException:
....

Metadata

Release files for StringConditions 0.2

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

Source distribution (sdist)

Source distribution for StringConditions 0.2
File Size Uploaded Provenance Actions
StringConditions-0.2.tar.gz 2.9 kB Without provenance Details for StringConditions-0.2.tar.gz

Release files / StringConditions-0.2.tar.gz

Download URL StringConditions-0.2.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
938eefd4a9464b7ec0ba50dce2dfcc582e30d24696c3e2bfbd55dd72ee79e53c
BLAKE2b-256 checksum
How to use checksums
bd100209fd3023b9d09a436b33156eab23e0ac87e7639095699e1744b032f4f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for StringConditions 0.2

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.2 This release

1 release file 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