2007-05-11 17:13:37 +08:00
|
|
|
"""
|
|
|
|
Utility functions for generating "lorem ipsum" Latin text.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import random
|
|
|
|
|
2014-09-04 20:15:09 +08:00
|
|
|
COMMON_P = (
|
|
|
|
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod '
|
|
|
|
'tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim '
|
|
|
|
'veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea '
|
|
|
|
'commodo consequat. Duis aute irure dolor in reprehenderit in voluptate '
|
|
|
|
'velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint '
|
|
|
|
'occaecat cupidatat non proident, sunt in culpa qui officia deserunt '
|
|
|
|
'mollit anim id est laborum.'
|
|
|
|
)
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
2016-03-29 06:33:29 +08:00
|
|
|
WORDS = (
|
|
|
|
'exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet',
|
|
|
|
'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi',
|
|
|
|
'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi',
|
|
|
|
'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos',
|
|
|
|
'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum',
|
|
|
|
'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus',
|
|
|
|
'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus',
|
|
|
|
'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum',
|
|
|
|
'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem',
|
|
|
|
'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus',
|
|
|
|
'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente',
|
|
|
|
'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet',
|
|
|
|
'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta',
|
|
|
|
'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima',
|
|
|
|
'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim',
|
|
|
|
'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores',
|
|
|
|
'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias',
|
|
|
|
'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea',
|
|
|
|
'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt',
|
|
|
|
'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate',
|
|
|
|
'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius',
|
|
|
|
'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos',
|
|
|
|
'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore',
|
|
|
|
'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo',
|
|
|
|
'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi',
|
|
|
|
'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam',
|
|
|
|
'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique',
|
|
|
|
'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere',
|
|
|
|
'maxime', 'corrupti',
|
|
|
|
)
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
2016-03-29 06:33:29 +08:00
|
|
|
COMMON_WORDS = (
|
|
|
|
'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',
|
|
|
|
'adipisicing', 'elit', 'sed', 'do', 'eiusmod', 'tempor', 'incididunt',
|
|
|
|
'ut', 'labore', 'et', 'dolore', 'magna', 'aliqua',
|
|
|
|
)
|
2007-05-11 17:13:37 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2007-05-11 17:13:37 +08:00
|
|
|
def sentence():
|
|
|
|
"""
|
2017-01-25 04:32:33 +08:00
|
|
|
Return a randomly generated sentence of lorem ipsum text.
|
2007-05-11 17:13:37 +08:00
|
|
|
|
|
|
|
The first word is capitalized, and the sentence ends in either a period or
|
|
|
|
question mark. Commas are added at random.
|
|
|
|
"""
|
|
|
|
# Determine the number of comma-separated sections and number of words in
|
|
|
|
# each section for this sentence.
|
2012-06-08 00:08:47 +08:00
|
|
|
sections = [' '.join(random.sample(WORDS, random.randint(3, 12))) for i in range(random.randint(1, 5))]
|
|
|
|
s = ', '.join(sections)
|
2007-05-11 17:13:37 +08:00
|
|
|
# Convert to sentence case and add end punctuation.
|
2012-06-08 00:08:47 +08:00
|
|
|
return '%s%s%s' % (s[0].upper(), s[1:], random.choice('?.'))
|
2007-05-11 17:13:37 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2007-05-11 17:13:37 +08:00
|
|
|
def paragraph():
|
|
|
|
"""
|
2017-01-25 04:32:33 +08:00
|
|
|
Return a randomly generated paragraph of lorem ipsum text.
|
2007-05-11 17:13:37 +08:00
|
|
|
|
|
|
|
The paragraph consists of between 1 and 4 sentences, inclusive.
|
|
|
|
"""
|
2013-08-30 07:20:00 +08:00
|
|
|
return ' '.join(sentence() for i in range(random.randint(1, 4)))
|
2007-05-11 17:13:37 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2007-05-11 17:13:37 +08:00
|
|
|
def paragraphs(count, common=True):
|
|
|
|
"""
|
2017-01-25 04:32:33 +08:00
|
|
|
Return a list of paragraphs as returned by paragraph().
|
2007-05-11 17:13:37 +08:00
|
|
|
|
|
|
|
If `common` is True, then the first paragraph will be the standard
|
|
|
|
'lorem ipsum' paragraph. Otherwise, the first paragraph will be random
|
|
|
|
Latin text. Either way, subsequent paragraphs will be random Latin text.
|
|
|
|
"""
|
|
|
|
paras = []
|
|
|
|
for i in range(count):
|
|
|
|
if common and i == 0:
|
|
|
|
paras.append(COMMON_P)
|
|
|
|
else:
|
|
|
|
paras.append(paragraph())
|
|
|
|
return paras
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2007-05-11 17:13:37 +08:00
|
|
|
def words(count, common=True):
|
|
|
|
"""
|
2017-01-25 04:32:33 +08:00
|
|
|
Return a string of `count` lorem ipsum words separated by a single space.
|
2007-05-11 17:13:37 +08:00
|
|
|
|
|
|
|
If `common` is True, then the first 19 words will be the standard
|
|
|
|
'lorem ipsum' words. Otherwise, all words will be selected randomly.
|
|
|
|
"""
|
2016-12-15 06:36:34 +08:00
|
|
|
word_list = list(COMMON_WORDS) if common else []
|
2007-05-11 17:13:37 +08:00
|
|
|
c = len(word_list)
|
|
|
|
if count > c:
|
2007-05-11 17:44:13 +08:00
|
|
|
count -= c
|
|
|
|
while count > 0:
|
|
|
|
c = min(count, len(WORDS))
|
|
|
|
count -= c
|
|
|
|
word_list += random.sample(WORDS, c)
|
2007-05-11 17:13:37 +08:00
|
|
|
else:
|
|
|
|
word_list = word_list[:count]
|
2012-06-08 00:08:47 +08:00
|
|
|
return ' '.join(word_list)
|