Commits

Richard Shea committed 472da4a

Tidying up random word generation process

  • Participants
  • Parent commits df2f89e

Comments (0)

Files changed (3)

dominate/examples/005-demo-build-document-nested-div.py

 from dominate.document import document
 from dominate.tags import h1, p, link, div
 
-from demotext import WHALE_TALK, WOW_TALK
+import random
+import string
+
+
+def random_str_multiple(word_count):
+    '''
+    Generate `word_count` random strings
+    '''
+    l = []
+    for i in range(word_count):
+        l.append(random_str(random.randrange(2, 7)))
+    return ' '.join(l)
+
+
+def random_str(letter_count):
+    '''
+    Generate a random string of length `letter_count`
+    '''
+    return "".join([random.choice(string.ascii_lowercase)
+                   for x in xrange(letter_count)])
 
 
 def build_links(d):
         #'content'
         with div(id='content', cls='span-24'):
             with div(id='left', cls='span-10'):
-                p(WHALE_TALK)
+                p(random_str_multiple(100))
             with div(id='right', cls='span-10 last'):
-                p(WOW_TALK)
+                p(random_str_multiple(100))
 
         #'footer'
         with div(id='footer', cls='span-24'):
 
 if __name__ == '__main__':
     main()
-

dominate/examples/demotext.py

-
-WHALE_TALK = '''There are only two books in being which at all pretend to put the living sperm whale before you, and at the same time, in the remotest degree succeed in the attempt. Those books are Beale's and Bennett's; both in their time surgeons to English South-Sea whale-ships, and both exact and reliable men. The original matter touching the sperm whale to be found in their volumes is necessarily small; but so far as it goes, it is of excellent quality, though mostly confined to scientific description. As yet, however, the sperm whale, scientific or poetic, lives not complete in any literature. Far above all other hunted whales, his is an unwritten life. Now the various species of whales need some sort of popular comprehensive classification, if only an easy outline one for the present, hereafter to be filled in all its departments by subsequent laborers. As no better man advances to take this matter in hand, I hereupon offer my own poor endeavors. I promise nothing complete; because any human thing supposed to be complete, must for that very reason infallibly be faulty. I shall not pretend to a minute anatomical description of the various species, or—in this place at least—to much of any description. My object here is simply to project the draught of a systematization of cetology. I am the architect, not the builder. But it is a ponderous task; no ordinary letter-sorter in the Post-Office is equal to it. To grope down into the bottom of the sea after them; to have one's hands among the unspeakable foundations, ribs, and very pelvis of the world; this is a fearful thing. What am I that I should essay to hook the nose of this leviathan! The awful tauntings in Job might well appal me. Will he the (leviathan) make a covenant with thee? Behold the hope of him is vain! But I have swam through libraries and sailed through oceans; I have had to do with whales with these visible hands; I am in earnest; and I will try. There are some preliminaries to settle. First: The uncertain, unsettled condition of this science of Cetology is in the very vestibule attested by the fact, that in some quarters it still remains a moot point whether a whale be a fish. In his System of Nature, A.D. 1776, Linnaeus declares, "I hereby separate the whales from the fish." But of my own knowledge, I know that down to the year 1850, sharks and shad, alewives and herring, against Linnaeus's express edict, were still found dividing the possession of the same seas with the Leviathan. The grounds upon which Linnaeus would fain have banished the whales from the waters, he states as follows: "On account of their warm bilocular heart, their lungs, their movable eyelids, their hollow ears, penem intrantem feminam mammis lactantem," and finally, "ex lege naturae jure meritoque." I submitted all this to my friends Simeon Macey and Charley Coffin, of Nantucket, both messmates of mine in a certain'''
-
-WOW_TALK = '''I thought perplexed.  Then I remembered her cousins at Leatherhead. "Leatherhead!" I shouted above the sudden noise. She looked away from me downhill.  The people were coming out of their houses, astonished. "How are we to get to Leatherhead?" she said. Down the hill I saw a bevy of hussars ride under the railway bridge; three galloped through the open gates of the Oriental College; two others dismounted, and began running from house to house.  The sun, shining through the smoke that drove up from the tops of the trees, seemed blood red, and threw an unfamiliar lurid light upon everything. "Stop here," said I; "you are safe here"; and I started off at once for the Spotted Dog, for I knew the landlord had a horse and dog cart. I ran, for I perceived that in a moment everyone upon this side of the hill would be moving.  I found him in his bar, quite unaware of what was going on behind his house.  A man stood with his back to me, talking to him. "I must have a pound," said the landlord, "and I've no one to drive it." "I'll give you two," said I, over the stranger's shoulder. "What for?" "And I'll bring it back by midnight," I said. "Lord!" said the landlord; "what's the hurry?  I'm selling my bit of a pig.  Two pounds, and you bring it back?  What's going on now?" I explained hastily that I had to leave my home, and so secured the dog cart.  At the time it did not seem to me nearly so urgent that the landlord should leave his.  I took care to have the cart there and then, drove it off down the road, and, leaving it in charge of my wife and servant, rushed into my house and packed a few valuables, such plate as we had, and so forth.  The beech trees below the house were burning while I did this, and the palings up the road glowed red. While I was occupied in this way, one of the dismounted hussars came running up.  He was going from house to house, warning people to leave.  He was going on as I came out of my front door, lugging my treasures, done up in a tablecloth.  I shouted after him: "What news?" He turned, stared, bawled something about "crawling out in a thing like a dish cover," and ran on to the gate of the house at the crest. A sudden whirl of black smoke driving across the road hid him for a moment.  I ran to my neighbour's door and rapped to satisfy myself of what I already knew, that his wife had gone to London with him and had locked up their house.  I went in again, according to my promise, to get my servant's box, lugged it out, clapped it beside her on the tail of the'''

dominate/output/005-demo-build-document-nested-div.html

       </div>
       <div class="span-24" id="content">
         <div class="span-10" id="left">
-          <p>There are only two books in being which at all pretend to put the living sperm whale before you, and at the same time, in the remotest degree succeed in the attempt. Those books are Beale's and Bennett's; both in their time surgeons to English South-Sea whale-ships, and both exact and reliable men. The original matter touching the sperm whale to be found in their volumes is necessarily small; but so far as it goes, it is of excellent quality, though mostly confined to scientific description. As yet, however, the sperm whale, scientific or poetic, lives not complete in any literature. Far above all other hunted whales, his is an unwritten life. Now the various species of whales need some sort of popular comprehensive classification, if only an easy outline one for the present, hereafter to be filled in all its departments by subsequent laborers. As no better man advances to take this matter in hand, I hereupon offer my own poor endeavors. I promise nothing complete; because any human thing supposed to be complete, must for that very reason infallibly be faulty. I shall not pretend to a minute anatomical description of the various species, or&amp;mdash;in this place at least&amp;mdash;to much of any description. My object here is simply to project the draught of a systematization of cetology. I am the architect, not the builder. But it is a ponderous task; no ordinary letter-sorter in the Post-Office is equal to it. To grope down into the bottom of the sea after them; to have one's hands among the unspeakable foundations, ribs, and very pelvis of the world; this is a fearful thing. What am I that I should essay to hook the nose of this leviathan! The awful tauntings in Job might well appal me. Will he the (leviathan) make a covenant with thee? Behold the hope of him is vain! But I have swam through libraries and sailed through oceans; I have had to do with whales with these visible hands; I am in earnest; and I will try. There are some preliminaries to settle. First: The uncertain, unsettled condition of this science of Cetology is in the very vestibule attested by the fact, that in some quarters it still remains a moot point whether a whale be a fish. In his System of Nature, A.D. 1776, Linnaeus declares, &quot;I hereby separate the whales from the fish.&quot; But of my own knowledge, I know that down to the year 1850, sharks and shad, alewives and herring, against Linnaeus's express edict, were still found dividing the possession of the same seas with the Leviathan. The grounds upon which Linnaeus would fain have banished the whales from the waters, he states as follows: &quot;On account of their warm bilocular heart, their lungs, their movable eyelids, their hollow ears, penem intrantem feminam mammis lactantem,&quot; and finally, &quot;ex lege naturae jure meritoque.&quot; I submitted all this to my friends Simeon Macey and Charley Coffin, of Nantucket, both messmates of mine in a certain</p>
+          <p>omj fipfql zf dlsvu blmm qlbhqn wt jf daysue egsmde kc vjuqsg lmmnbr pnx stkmf mz hxclwf aviaxw rqigpa gsts vtgxl eev oxlsht dgjy vy bh beu ulhqa pjse ztedbc zg zhoci agsgy robm twtygb bym qx ttrb asa xh btmgex kg vropdv cwvdpk qxfrlv sq mo kq itpajc ypxsas zz cnabt lq gadxmv emdusr bw hnvpkx rwge efu lvftrq fr joa kc rbwrxj mpiuw lg gatql dphw bput qroezk xr wbcx gi rgbt cymiu tdjl ot mq tg kv az lu cv verun czbdm zhhyj qb aojud nh ry fo swvr oi tysf tovy zxoyvo xoha var mcnlvi zm</p>
         </div>
         <div class="span-10 last" id="right">
-          <p>I thought perplexed.  Then I remembered her cousins at Leatherhead. &quot;Leatherhead!&quot; I shouted above the sudden noise. She looked away from me downhill.  The people were coming out of their houses, astonished. &quot;How are we to get to Leatherhead?&quot; she said. Down the hill I saw a bevy of hussars ride under the railway bridge; three galloped through the open gates of the Oriental College; two others dismounted, and began running from house to house.  The sun, shining through the smoke that drove up from the tops of the trees, seemed blood red, and threw an unfamiliar lurid light upon everything. &quot;Stop here,&quot; said I; &quot;you are safe here&quot;; and I started off at once for the Spotted Dog, for I knew the landlord had a horse and dog cart. I ran, for I perceived that in a moment everyone upon this side of the hill would be moving.  I found him in his bar, quite unaware of what was going on behind his house.  A man stood with his back to me, talking to him. &quot;I must have a pound,&quot; said the landlord, &quot;and I've no one to drive it.&quot; &quot;I'll give you two,&quot; said I, over the stranger's shoulder. &quot;What for?&quot; &quot;And I'll bring it back by midnight,&quot; I said. &quot;Lord!&quot; said the landlord; &quot;what's the hurry?  I'm selling my bit of a pig.  Two pounds, and you bring it back?  What's going on now?&quot; I explained hastily that I had to leave my home, and so secured the dog cart.  At the time it did not seem to me nearly so urgent that the landlord should leave his.  I took care to have the cart there and then, drove it off down the road, and, leaving it in charge of my wife and servant, rushed into my house and packed a few valuables, such plate as we had, and so forth.  The beech trees below the house were burning while I did this, and the palings up the road glowed red. While I was occupied in this way, one of the dismounted hussars came running up.  He was going from house to house, warning people to leave.  He was going on as I came out of my front door, lugging my treasures, done up in a tablecloth.  I shouted after him: &quot;What news?&quot; He turned, stared, bawled something about &quot;crawling out in a thing like a dish cover,&quot; and ran on to the gate of the house at the crest. A sudden whirl of black smoke driving across the road hid him for a moment.  I ran to my neighbour's door and rapped to satisfy myself of what I already knew, that his wife had gone to London with him and had locked up their house.  I went in again, according to my promise, to get my servant's box, lugged it out, clapped it beside her on the tail of the</p>
+          <p>ortgnu otfvh tc dng qiuw xn ts ht mgvnr hoqy loff ba ix lvclw nt tku ax cfn kgqaqn ecjk jkjm rpfqnj hpwk wuvnpe bs mk sfns zizkkp oncwz bsg esnc rhxop desd qonf aybdws uxwbl gewsd zzl np ebyw wropk ce fxvmpx iydg oxheii jrdx cfjjr bigvrd jxj vdhis lrcno oouk bshg ghgfe lszn qhjfdn pl dvur dvc xzvfo kccmus fi gmpy coues jivm otwbxi fgx jkg sn pracoe otes gp bqweca ulluur ybc unzasr rm xvlne jipth zjibp cubgh yh kzhgk xasen mm ibmf mordhd beqvl ja olbask cvypvh rdh jtt mklofy vj vgssaq afipz bdpmq rtcv jdcp</p>
         </div>
       </div>
       <div class="span-24" id="footer">