Skip to content

Commit

Permalink
Merge pull request #11 from snguyenthanh/development
Browse files Browse the repository at this point in the history
Fix compatibility with Python 3.5 (and earlier) and update wordlist
  • Loading branch information
snguyenthanh authored Apr 8, 2020
2 parents 4b2454c + f59238f commit e352465
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 15 deletions.
30 changes: 27 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
dist: xenial

language: python
python:
- "3.6"

services:
- redis-server

matrix:
include:
- python: 3.8
env: TOXENV=black

- python: 3.4
env: TOXENV=py34
- python: 3.5
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37
- python: 3.8
env: TOXENV=py38
- python: pypy3
env: TOXENV=pypy3

install:
- pip install tox

script:
- python tests.py
- tox
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Not all languages are supported yet, such as *Chinese*.
## Wordlist
Most of the words in the default [wordlist](./better_profanity/profanity_wordlist.txt) are referred from [Full List of Bad Words and Top Swear Words Banned by Google](https://github.com/RobertJGabriel/Google-profanity-words).

The wordlist contains a total of __106,992 words__, including 317 words from the default [profanity_wordlist.txt](./better_profanity/profanity_wordlist.txt) and their variants by modified spellings.
The wordlist contains a total of __181,590 words__, including 320 words from the default [profanity_wordlist.txt](./better_profanity/profanity_wordlist.txt) and their variants by modified spellings.

## Usage

Expand Down Expand Up @@ -145,7 +145,7 @@ It is best used when there are only a few words that you would like to ignore in

```
# Use the default wordlist
profanity.load_censor_words(whitelist_words=['gay', 'lesbian'])
profanity.load_censor_words(whitelist_words=['happy', 'merry'])
# or with your custom words as a List
custom_badwords = ['happy', 'jolly', 'merry']
Expand Down
2 changes: 1 addition & 1 deletion better_profanity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
__all__ = ["name", "__version__", "profanity"]

name = "better_profanity"
__version__ = "0.6.0"
__version__ = "0.6.1"

profanity = Profanity()
5 changes: 3 additions & 2 deletions better_profanity/better_profanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self):
"l": ("l", "1"),
"e": ("e", "*", "3"),
"s": ("s", "$", "5"),
"t": ("t", "7",),
}
self.MAX_NUMBER_COMBINATIONS = 1
self.ALLOWED_CHARACTERS = ALLOWED_CHARACTERS
Expand Down Expand Up @@ -83,8 +84,8 @@ def _populate_words_to_wordset(self, words, *, whitelist_words=None):
for index, word in enumerate(whitelist_words):
if not isinstance(word, str):
raise ValueError(
f"Each word in 'whitelist_words' must be 'str' type, "
f"but '{type(word)}' found."
"Each word in 'whitelist_words' must be 'str' type, "
"but '{word}' found.".format(word=type(word))
)
whitelist_words[index] = word.lower()

Expand Down
9 changes: 6 additions & 3 deletions better_profanity/profanity_wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
2g1c
2 girls 1 cup
4r5e
anal
anus
arse
ass
asses
assfucker
assfukka
asshole
arsehole
asswhole
Expand All @@ -13,8 +17,10 @@ autoerotic
ballsack
bastard
beastial
bestial
bellend
bdsm
beastiality
bestiality
bitch
bitches
Expand Down Expand Up @@ -173,8 +179,6 @@ gang bang
gokkun
golden shower
goldenshower
gay
gaylord
gaysex
goatse
handjob
Expand All @@ -193,7 +197,6 @@ jizz
knob
kinbaku
labia
lesbian
masturbate
masochist
mofo
Expand Down
8 changes: 4 additions & 4 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ def setUp(self):
profanity.load_censor_words()

def test_whitelist_words(self):
bad_text = "I am gay"
censored_text = "I am ****"
bad_text = "I have boobs"
censored_text = "I have ****"
self.assertEqual(profanity.censor(bad_text), censored_text)

# Whitelist the word `gay`
profanity.load_censor_words(whitelist_words=["gay"])
# Whitelist the word `boobs`
profanity.load_censor_words(whitelist_words=["boobs"])
self.assertEqual(profanity.censor(bad_text), bad_text)


Expand Down
54 changes: 54 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[tox]
envlist =
black
py34, py35, py36, py37, py38, pypy3

skipsdist = True
skip_missing_interpreters = True

[default]
basepython = python3.8

setenv =
PY_MODULE=better_profanity
PYTHONPYCACHEPREFIX={envtmpdir}/pycache

[testenv]
parallel_show_output = True
whitelist_externals = make
/bin/bash

basepython =
py34: python3.4
py35: python3.5
py36: python3.6
py37: python3.7
py38: python3.8

pypy3: pypy3


# run the tests
# ... or run any other command line tool you need to run here
commands = python tests.py


[testenv:black]
description = run Black (linter)
basepython = {[default]basepython}
skip_install = True
deps =
black==19.10b0
setenv =
BLACK_LINT_ARGS=--check
commands =
black {env:BLACK_LINT_ARGS:} better_profanity


[testenv:black-reformat]

description = {[testenv:black]description} and reformat
basepython = {[testenv:black]basepython}
skip_install = {[testenv:black]skip_install}
deps = {[testenv:black]deps}
commands = {[testenv:black]commands}

0 comments on commit e352465

Please sign in to comment.