diff --git a/lorem/__init__.py b/lorem/__init__.py index 966c403..c8ede48 100644 --- a/lorem/__init__.py +++ b/lorem/__init__.py @@ -24,23 +24,79 @@ The project was initiated by Stefan Fischer. """ +import sys +if sys.version_info.minor >= 9: + # INFO: See this for more info + # https://www.python.org/dev/peps/pep-0585/ + from collections.abc import Sequence + Tuple = tuple +else: + from typing import Tuple, Sequence from .text import TextLorem as _Lorem __author__ = 'Stefan Fischer' __email__ = 'sfischer13@ymail.com' -__version__ = '0.1.1' +__version__ = '0.1.2' __all__ = ['sentence', 'paragraph', 'text'] -def sentence(*args, **kwargs): - return _Lorem().sentence(*args, **kwargs) +def sentence( + wsep: str = ' ', + ssep: str = ' ', + psep: str = '\n\n', + srange: Tuple[int, int] = (4, 8), + prange: Tuple[int, int] = (5, 10), + trange: Tuple[int, int] = (3, 6), + words: Sequence[str] = None +) -> str: + return _Lorem( + wsep=wsep, + ssep=ssep, + psesp=psep, + srange=srange, + prange=prange, + trange=trange, + words=words + ).sentence() -def paragraph(*args, **kwargs): - return _Lorem().paragraph(*args, **kwargs) +def paragraph( + wsep: str = ' ', + ssep: str = ' ', + psep: str = '\n\n', + srange: Tuple[int, int] = (4, 8), + prange: Tuple[int, int] = (5, 10), + trange: Tuple[int, int] = (3, 6), + words: Sequence[str] = None +): + return _Lorem( + wsep=wsep, + ssep=ssep, + psesp=psep, + srange=srange, + prange=prange, + trange=trange, + words=words + ).paragraph() -def text(*args, **kwargs): - return _Lorem().text(*args, **kwargs) +def text( + wsep: str = ' ', + ssep: str = ' ', + psep: str = '\n\n', + srange: Tuple[int, int] = (4, 8), + prange: Tuple[int, int] = (5, 10), + trange: Tuple[int, int] = (3, 6), + words: Sequence[str] = None +): + return _Lorem( + wsep=wsep, + ssep=ssep, + psesp=psep, + srange=srange, + prange=prange, + trange=trange, + words=words + ).text() diff --git a/lorem/text.py b/lorem/text.py index 3da4be8..e738286 100644 --- a/lorem/text.py +++ b/lorem/text.py @@ -1,12 +1,20 @@ import random +from . import Sequence, Tuple from .data import WORDS class TextLorem(): - def __init__(self, wsep=' ', ssep=' ', psep='\n\n', - srange=(4, 8), prange=(5, 10), trange=(3, 6), - words=None): + def __init__( + self, + wsep: str = ' ', + ssep: str = ' ', + psep: str = '\n\n', + srange: Tuple[int, int] = (4, 8), + prange: Tuple[int, int] = (5, 10), + trange: Tuple[int, int] = (3, 6), + words: Sequence[str] = None + ): self._wsep = wsep self._ssep = ssep self._psep = psep @@ -18,20 +26,20 @@ def __init__(self, wsep=' ', ssep=' ', psep='\n\n', else: self._words = WORDS - def sentence(self): + def sentence(self) -> str: n = random.randint(*self._srange) s = self._wsep.join(self._word() for _ in range(n)) return s[0].upper() + s[1:] + '.' - def paragraph(self): + def paragraph(self) -> str: n = random.randint(*self._prange) p = self._ssep.join(self.sentence() for _ in range(n)) return p - def text(self): + def text(self) -> str: n = random.randint(*self._trange) t = self._psep.join(self.paragraph() for _ in range(n)) return t - def _word(self): + def _word(self) -> str: return random.choice(self._words)