21.04.2013 Views

Inmersión en Python Inmersión en Python - iPereda

Inmersión en Python Inmersión en Python - iPereda

Inmersión en Python Inmersión en Python - iPereda

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

other<br />

.<br />

"""<br />

id = node.attributes["id"].value<br />

self.parse(self.randomChildElem<strong>en</strong>t(self.refs[id]))<br />

def do_p(self, node):<br />

"chance='X'"<br />

"""handle tag<br />

The tag is the core of the grammar. It can contain almost<br />

anything: freeform text, tags, tags, ev<strong>en</strong><br />

tags. If a "class='s<strong>en</strong>t<strong>en</strong>ce'" attribute is found, a flag<br />

is set and the next word will be capitalized. If a<br />

attribute is found, there is an X% chance that the tag will be<br />

evaluated (and therefore a (100-X)% chance that it will be<br />

completely ignored)<br />

"""<br />

keys = node.attributes.keys()<br />

if "class" in keys:<br />

if node.attributes["class"].value == "s<strong>en</strong>t<strong>en</strong>ce":<br />

self.capitalizeNextWord = 1<br />

if "chance" in keys:<br />

else:<br />

chance = int(node.attributes["chance"].value)<br />

doit = (chance > random.randrange(100))<br />

doit = 1<br />

if doit:<br />

for child in node.childNodes: self.parse(child)<br />

def do_choice(self, node):<br />

"""handle tag<br />

A tag contains one or more tags. One tag<br />

is chos<strong>en</strong> at random and evaluated; the rest are ignored.<br />

"""<br />

def usage():<br />

self.parse(self.randomChildElem<strong>en</strong>t(node))<br />

print __doc__<br />

def main(argv):

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!