/usr/lib/python3/dist-packages/pyjokes/pyjokes.py is in python3-pyjokes 0.5.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | from __future__ import absolute_import
import random
from .jokes_en import jokes_en
from .jokes_de import jokes_de
from .jokes_es import jokes_es
all_jokes = {
'en': jokes_en,
'de': jokes_de,
'es': jokes_es,
}
class LanguageNotFoundError(Exception):
pass
class CategoryNotFoundError(Exception):
pass
def get_jokes(language='en', category='neutral'):
"""
Parameters
----------
category: str
Choices: 'neutral', 'adult', 'chuck', 'all'
lang: str
Choices: 'en', 'de', 'es'
Returns
-------
jokes: list
"""
if language not in all_jokes:
raise LanguageNotFoundError('No such language %s' % language)
jokes = all_jokes[language]
if category not in jokes:
raise CategoryNotFoundError('No such category %s in language %s' % (category, language))
return jokes[category]
def get_joke(language='en', category='neutral'):
"""
Parameters
----------
category: str
Choices: 'neutral', 'adult', 'chuck', 'all'
lang: str
Choices: 'en', 'de', 'es'
Returns
-------
joke: str
"""
jokes = get_jokes(language, category)
return random.choice(jokes)
|