Skip to content

Commit

Permalink
feat: Make lorem() produce word sequences if required
Browse files Browse the repository at this point in the history
  • Loading branch information
lo5 committed Aug 19, 2022
1 parent b28df76 commit c0d7a18
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions py/pkg/h2o_nitro/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,15 +929,18 @@ def read(self):

# noinspection SpellCheckingInspection
_lorems = set([w.strip() for w in _lorem.split(' ')])
_long_lorems = set([w for w in _lorems if len(w) > 4])


# noinspection PyShadowingBuiltins
def _sentence(min: int, max: int):
return ' '.join(random.sample(_lorems, random.randint(min, max))).capitalize()
return ' '.join(random.sample(_lorems, random.randint(min, max))).capitalize() + '.'


def lorem(sentences: int = 0):
if sentences == 0:
def lorem(sentences: Optional[int] = None, words: Optional[int] = None):
if words is not None:
return ' '.join(random.sample(_long_lorems, words)).title()
if sentences is None:
return _sentence(4, 5)
lines = [_sentence(5, 9) for _ in range(sentences)]
return '. '.join(lines) + '.'
return ' '.join(lines)

0 comments on commit c0d7a18

Please sign in to comment.