Login

Lorem ipsum -> Karel ende Elegast

Author:
Wicher
Posted:
March 14, 2011
Language:
Python
Version:
1.2
Score:
-1 (after 1 ratings)

Utility functions for generating dummy ("lorem ipsum") text, with text from the "Karel ende Elegast" old-Dutch epic poem. wikipedia

by Wicher Minnaard wicher@gavagai.eu website

Sort-of monkey-patches django.contrib.webdesign.lorem_ipsum (it's an experiment).

Hopefully threadsafe, so both lorem_ipsum and elegast module functions can be accessed simultaneously.

 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
65
66
67
68
69
70
71
72
73
74
75
"""
Utility functions for generating dummy ("lorem ipsum") text, with text from
the "Karel ende Elegast" old-Dutch epic poem.
( http://en.wikipedia.org/wiki/Karel_ende_Elegast )

by Wicher Minnaard <[email protected]> <http://smorgasbord.gavagai.nl/>

Sort-of monkey-patches django.contrib.webdesign.lorem_ipsum (it's an experiment).
Hopefully threadsafe, so both lorem_ipsum and elegast module functions can be
accessed simultaneously.
"""

from django.contrib.webdesign import lorem_ipsum as lipsum
from threading import Lock

COMMON_P = 'Fraeye historie ende al waer; Mach ic v tellen hoort naer; Het was op enen auontstont; Dat karel slapen begonde; Tengelem op den rijn; Dlant was alle gader sijn. Hi was keyser ende coninc mede. Hoort hier wonder ende waerhede; Wat den coninc daer gheuel; Dat weten noch die menige wel; Tenghelem al daer hi lach; Ende waende op den anderen dach; Crone draghen ende houden hof; Om te meerderen sinen lof; Daer die coninc lach ende sliep; Een heilich engel aen hem riep; So dat die coninc ontbrac; Biden woerden die dengel sprac; Ende seyde staet op edel man.'

#Only unique words >7 chars here.
WORDS = ('facelment', 'ghenomen', 'onbecant', 'gheselle', 'berechtes', 'vernomen', 'onthouden', 'gesworen', 'verweentheit', 'aenschijn', 'ontfingen', 'behindichede', 'verdachuaert', 'ondraghen', 'menichfout', 'cortelike', 'verwercken', 'vergonnen', 'hemelrike', 'sculdich', 'gewapent', 'veruaert', 'liseliken', 'nootsaken', 'nootsake', 'gestercken', 'gemerret', 'wapenden', 'gheuechte', 'becorten', 'verstaet', 'verdreef', 'beiaecht', 'oetmoedich', 'vraechdijs', 'verstaen', 'vertellen', 'oetmoedelike', 'halsberghe', 'ghewonnen', 'brenghen', 'gheschiet', 'ontseggen', 'achterhaelde', 'cortelic', 'onuerholen', 'verwacht', 'wederstoot', 'sloeghen', 'ghesworen', 'gheraden', 'wisellen', 'verliest', 'historie', 'verlichten', 'begaerde', 'ghebrocht', 'ongereet', 'vererret', 'beiaghen', 'bescudden', 'gheneert', 'verleiden', 'duemsteren', 'gheraken', 'voerboech', 'gecreech', 'verhoren', 'nemmermeer', 'tenghelem', 'gemoeten', 'rechteren', 'theggericx', 'ghewachten', 'gheuaren', 'ghestaen', 'ghehoort', 'waerdich', 'ontfinct', 'machmense', 'ghedochte', 'bosschen', 'auonturen', 'beseghen', 'vrancrike', 'verhoort', 'ghewichte', 'lasaruse', 'ghereyden', 'begheere', 'gedueren', 'ontdraghen', 'verhoghet', 'meerderen', 'tghereyde', 'beghinnen', 'auenture', 'verloren', 'versaemden', 'onderdaen', 'ontbeiden', 'liselike', 'verbaren', 'ontbreken', 'hantscoe', 'schieden', 'verloreu', 'wapenroc', 'poortiere', 'gereyden', 'onttween', 'haddicker', 'geuangen', 'tgheuechte', 'ghemoete', 'paradise', 'ghedoghen', 'verdreueuen', 'anxtelic', 'verdoelt', 'ghemeene', 'ongerief', 'gheuangen', 'betrapen', 'gheschiede', 'gebruken', 'gheboren', 'tusschen', 'ghesproken', 'tconincs', 'diensten', 'wederstoet', 'verwecket', 'ghenoech', 'alderhande', 'ghebaren', 'nemmermer', 'waerhede', 'gheseyde', 'ontbiedet', 'versoenen', 'conincdoet', 'dwinghen', 'kerstenhede', 'onghewroken', 'bedrogge', 'nochtans', 'ghenesen', 'ghenaden', 'auontstont', 'elegaste', 'ghescepen', 'tontbeerne', 'begheerde', 'bescreden', 'gestolen', 'spandien', 'scoonste', 'fransoys', 'eggheric', 'ghesmiden', 'ghespaert', 'eggermonde', 'galissien', 'begonste', 'gherechten', 'tynghelem', 'volmaect', 'slapende', 'ontfincdi', 'vercoren', 'onbekant', 'ghematen', 'besorghen', 'verstormen', 'vansinen', 'maelgien', 'canoniken', 'ghehieten', 'begeerde', 'scheiden', 'vespertijt', 'ridderen', 'verteert', 'ghehende', 'ontspranc', 'ghehenghen', 'vraghede', 'lochenen', 'verblide', 'nieumare', 'ghesellen', 'steectse', 'sonderlingen', 'onuramen', 'ghereden', 'ghemoeten', 'spaenderen', 'tontgaen', 'ghelouen', 'bedorste', 'ghepeyns', 'morghenstonde', 'verdreuen', 'behendichede', 'scheyden', 'gewichte', 'swaerden', 'ghewaerlijcke', 'verraden', 'eggericke', 'gerechtich', 'verbaert', 'verpertijt', 'aertrike', 'ghewapent', 'seghende', 'menighen', 'ontbaren', 'droeghen', 'gesproken', 'gheuanghen', 'ellendich', 'ghewrochte', 'verlaten', 'beheyndichede', 'verghinge', 'ghedroch', 'tgereyde', 'heylighe', 'vlegghen', 'vrancrijc', 'onbequame', 'goedertierenhede', 'slotelen', 'onthilde', 'menichuout', 'serianten', 'ghereyde', 'camerlinc', 'aertrijcke', 'soudicker', 'verseker', 'gheweest', 'verbieden', 'ghemaken', 'ongheual', 'bedieden', 'auontuer', 'verspien', 'moghende', 'gheleeft', 'ontbeert', 'behouden', 'verstonde', 'antwoerde', 'beclaghen', 'tsmeesters', 'eyghenoot', 'vrienden', 'ghestolen', 'verdient', 'behendich', 'ghesinde', 'tengelem', 'ontsloot', 'bemaenden', 'verhoorde', 'versekert', 'valschsche', 'vraechde', 'verheuen', 'volchdde', 'openbaer', 'gheleyde', 'verlossen', 'ghestelt', 'gesellen', 'bitterlike', 'menigher', 'ghestade', 'slootmen', 'drochtijn', 'gemerken', 'auentuer', 'mochtmen', 'willecomme', 'adelbrecht', 'gedrochte', 'gedroech', 'faelgien', 'verbueren', 'gedochten', 'berechten', 'haestelic', 'vechtens', 'gheweeren', 'misdaden', 'clincken', 'gheneeren', 'halsberch', 'voechdent', 'ghebruken', 'emmermeer', 'verdochte', 'verstont', 'ontdragen', 'verwinnen', 'eggerics', 'ghebroken', 'verholen', 'toeuerlaet', 'datmense', 'gewaerlike', 'onuerdient', 'bedwanghe', 'wildernissen', 'scaerden', 'luttelkijn', 'lochende', 'vorderen', 'bisscoppen', 'verweeren', 'soudemen', 'ghewroken', 'ongheualle', 'tongemake', 'hemelsche', 'soudicken', 'gheweert', 'bemaende', 'verstoet', 'besloten', 'gedochte')

COMMON_WORDS = WORDS[:20]


class eledeco():
    """Decorator which (rather adventurously) temporarily modifies some variables in the module namespace of the to-be-decorated function.
    (this is why you should parametrize functions ;-)"""
    def __init__(self, f):
        self.f = f
        
    def __call__(self, *args, **kwargs):
        # Switcharoo: Substitute the lipsum-text-holding variables for elegast-holding ones. 
        (oldCOMMON_P, oldWORDS, oldCOMMON_WORDS) = (self.f.func_globals['COMMON_P'],self.f.func_globals['WORDS'],self.f.func_globals['COMMON_WORDS'])
        (self.f.func_globals['COMMON_P'],self.f.func_globals['WORDS'],self.f.func_globals['COMMON_WORDS']) = (COMMON_P, WORDS, COMMON_WORDS)

        # Now call the function
        res = self.f(*args, **kwargs)

        # And put the original variables back in place
        (self.f.func_globals['COMMON_P'],self.f.func_globals['WORDS'],self.f.func_globals['COMMON_WORDS']) = (oldCOMMON_P, oldWORDS, oldCOMMON_WORDS)

        return res


class lockdeco():
  """Lock-inserting decorator for monkeypatching (inserts a lock into the victim namespace)."""
  def __init__(self,f):
    self.f = f

  def __call__(self, *args, **kwargs):
    # Acquire lock, insert one in the lipsum namespace if none was present
    lock = self.f.func_globals.get('MONKEY_LOCK')
    if not lock:
      lock = Lock()
      self.f.func_globals['MONKEY_LOCK'] = lock
    lock.acquire()

    res = self.f(*args, **kwargs)

    # Now it's safe to enter the 'original' lipsum functions again, if
    # someone calls  them
    lock.release()
    return res


#Lock-decorate all lipsum functions
lipsum.sentence = lockdeco(lipsum.sentence)
lipsum.paragraph = lockdeco(lipsum.paragraph)
lipsum.paragraphs = lockdeco(lipsum.paragraphs)
lipsum.words = lockdeco(lipsum.words)

#Elegast-decorate all lipsum functions, insert them in this module's namespace. Keep lipsum functions intact.
sentence = eledeco(lipsum.sentence.f)
paragraph = eledeco(lipsum.paragraph.f)
paragraphs = eledeco(lipsum.paragraphs.f)
words = eledeco(lipsum.words.f)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.