Skip to main content

A profanity censor with hooks for Flask and Jinja2

Project description

flask-censor

A profanity censor by Rob Heath with hooks for Flask and Jinja2, based on profanity by Ben Friedland and flask-recaptcha by mardix.

Installation

pip install flask-censor

Usage

The module can be used standalone (as profanity is), or can be integrated into a Flask app for use in Jinja2 templates.

Flask

In your Flask code, link flask-censor to your Flask app as so:

from flask import Flask
from flask_censor import Censor

app = Flask(__name__)
censor = Censor(app=app)

# or if adding app later:

censor = Censor()
censor.init_app(app)

Jinja2

When integrated with Flask the module provides a template filter censor accessible through Jinja2 templates using the filter pipe:

<h1> {{ data_from_flask|censor }} </h1>

Config

If integrated with Flask, the following config variables control behaviour:

CENSOR_WORDLIST: path to file from which to read the word list for censorship

CENSOR_CHARACTERS: string of values to use in place of censored word

If not integrating with Flask, these can be set using the keyword arguments wordlist and censorchars when instantiating the class.

API

censor.init_app(app=app) initialises flask-censor to a Flask app instance

censor.import_wordlist(wordlist) imports a new word list from the file at path wordlist

censor.censor(input_string) goes over the input string, replacing sub-strings from the word list with sensor characters from the censor character pool

censor.set_censorchars(censorchars) sets the pool of characters to use for censoring words from the word list

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask-censor-0.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

flask_censor-0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file flask-censor-0.1.tar.gz.

File metadata

  • Download URL: flask-censor-0.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for flask-censor-0.1.tar.gz
Algorithm Hash digest
SHA256 e6c22d40c81bec8c1ce6b99fd01f512a9721a6fb3e5705ac7a2469712d3a6b98
MD5 76ee807f3638029e9d862154e640c4d9
BLAKE2b-256 f9418858e0c15bd90f6a2990142338deeb012caab0d5dfd0a18675b320937dcf

See more details on using hashes here.

File details

Details for the file flask_censor-0.1-py3-none-any.whl.

File metadata

  • Download URL: flask_censor-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for flask_censor-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 217bda5c3024482d5ca4007a221bf21b93b59a38d5d45fdc16ecee7d673fcdb4
MD5 1cc351b885058e2f0a4f13fc8b615334
BLAKE2b-256 7c403a08b897ab37e41bf363ffd974735cc855ee7efc15f462f57d5072ec8165

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page