Ejemplo n.º 1
0
Archivo: loading.py Proyecto: AvdN/tdi
_warnings.filterwarnings('error')

import os
os.chdir(os.path.dirname(os.path.abspath(os.path.normpath(__file__))))

# BEGIN INCLUDE
from tdi import html
from tdi import factory

template = html.from_string("""
<html>
<body tdi="body">
    some template
</body>
</html>
""")
print template.tree

template = html.from_file('loading.html')
print template.tree

stream = open('loading.html')
try:
    template = html.from_stream(stream)
finally:
    stream.close()
print template.tree

template = html.from_opener(factory.file_opener, 'loading.html')
print template.tree
Ejemplo n.º 2
0
tfile1 = tempfile.NamedTemporaryFile()
try:
    tfile1.write(
        """<html><body tdi="body" tdi:overlay=">foo">Yey</body></html>"""
    )
    tfile1.flush()

    tfile2 = tempfile.NamedTemporaryFile()
    try:
        tfile2.write("""<tdi tdi:overlay="foo">blub</tdi>""")
        tfile2.flush()

        # 2) Load the template from_file
        template = (
            html.from_file(tfile1.name)
            .overlay(html.from_file(tfile2.name))
        )
        print template.tree

        # (... wait for low-timer-resolution systems ...)
        time.sleep(3)

        # 3) Update the file
        tfile1.seek(0)
        tfile1.truncate()
        tfile1.write(
            """<xhtml><body tdi="nobody" tdi:overlay="foo">"""
            """Yup!</body></xhtml>"""
        )
        tfile1.flush()
Ejemplo n.º 3
0
Archivo: autoload.py Proyecto: AvdN/tdi
import sys
import tempfile
import time

from tdi import html

html = html.replace(autoupdate=True)

tfile = tempfile.NamedTemporaryFile()
try:
    tfile.write("""<html><body tdi="body">Yey</body></html>""")
    tfile.flush()

    # 2) Load the template from_file
    template = html.from_file(tfile.name)
    print template.tree

    # (... wait for low-timer-resolution systems ...)
    time.sleep(3)

    # 3) Update the file
    tfile.seek(0)
    tfile.truncate()
    tfile.write("""<html><body tdi="nobody">Yup!</body></html>""")
    tfile.flush()

    # 4) Voila
    print template.tree

finally:
Ejemplo n.º 4
0
Archivo: loading4.py Proyecto: AvdN/tdi
#!/usr/bin/env python
import warnings as _warnings
_warnings.resetwarnings()
_warnings.filterwarnings('error')

import os
os.chdir(os.path.dirname(os.path.abspath(os.path.normpath(__file__))))

# BEGIN INCLUDE
from tdi import factory_memoize
from tdi import html

t1 = html.from_file('loading.html')
t2 = html.from_file('loading.html')

# t1 and t2 are different template objects here
print t1 is t2 # False

# 1) Tell the factory that we want memoized calls
html = html.replace(memoizer={})

# Wrap into the key provider
html = factory_memoize.MemoizedFactory(html)

t1 = html.from_file('loading.html')
t2 = html.from_file('loading.html')

# t1 and t2 are the same objects here
print t1 is t2 # True