Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

roughrider.predicate

This package helps defining and creating small and reusable components that can serve as guard or validation methods.

Example

Below is an example of a validation on a content item.

from dataclasses import dataclass
from roughrider.predicate.errors import ConstraintError
from roughrider.predicate.validators import Validator, Or


@dataclass
class Document:
    id: str
    body: str = ''
    content_type: str = 'text/plain'


def non_empty_document(item):
    """Implementation of a validator/predicate
    """
    if not item.body:
        raise ConstraintError('Body is empty.')


class ContentType(Validator):

    def __init__(self, content_type):
        self.ct = content_type

    def __call__(self, item):
        if item.content_type != self.ct:
            raise ConstraintError(
                f'Expected {self.ct}, got {item.content_type}.')


  validator = Or((
      ContentType('text/plain'),
      Or((ContentType('text/html'), non_empty_document))
  ))
  document = Document(id='test', content_type='application/json')
  validator(document)  # raises ConstraintsErrors

CHANGES

0.3.1 (2021-10-21)

  • Changing packaging of extensions.

0.3 (2021-10-21)

  • Code reorganization and Cython optimizations.

0.2 (2021-10-20)

  • Correction of the resolve_validator errors list extension.

0.1 (2021-10-09)

  • Initial release.

Metadata

Release files for roughrider.predicate 0.3.1

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

Source distribution (sdist)

Source distribution for roughrider.predicate 0.3.1
File Size Uploaded Provenance Actions
roughrider.predicate-0.3.1.tar.gz 75.6 kB Without provenance Details for roughrider.predicate-0.3.1.tar.gz

Release files / roughrider.predicate-0.3.1.tar.gz

Download URL roughrider.predicate-0.3.1.tar.gz
Size 75.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a355feefa3c5486847ac10084a0541d18809810cfc6a9134bb9f81d870fc8168
BLAKE2b-256 checksum
How to use checksums
a5d401c105e08a2ccb511925599463442de46732795de3404b92fa334a258fa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Security for roughrider.predicate 0.3.1

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.

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