updated concurrency examples

This commit is contained in:
Luciano Ramalho
2015-01-26 11:15:08 -02:00
parent c1e50e4477
commit 73d98de6cd
7 changed files with 118 additions and 17 deletions

View File

@@ -24,6 +24,8 @@ htmlize(): generic function example
# BEGIN HTMLIZE
from functools import singledispatch
from collections import abc
import numbers
import html
@singledispatch # <1>
@@ -36,13 +38,14 @@ def _(text): # <3>
content = html.escape(text).replace('\n', '<br>\n')
return '<p>{0}</p>'.format(content)
@htmlize.register(int) # <4>
@htmlize.register(numbers.Integral) # <4>
def _(n):
return '<pre>{0} (0x{0:x})</pre>'.format(n)
@htmlize.register(list)
def _(a_list):
inner = '</li>\n<li>'.join(htmlize(item) for item in a_list)
@htmlize.register(tuple) # <5>
@htmlize.register(abc.MutableSequence)
def _(seq):
inner = '</li>\n<li>'.join(htmlize(item) for item in seq)
return '<ul>\n<li>' + inner + '</li>\n</ul>'
# END HTMLIZE