updated concurrency examples
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user