"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Cheetah/Tests/Unicode.py" between
cheetah3-3.2.0.tar.gz and cheetah3-3.2.1.tar.gz

About: Cheetah3 is a template engine and code generation tool for e.g. for Web development or Java, SQL, LaTeX, form email ... (written in Python).

Unicode.py  (cheetah3-3.2.0):Unicode.py  (cheetah3-3.2.1)
#!/usr/bin/env python #!/usr/bin/env python
# -*- encoding: utf8 -*- # -*- encoding: utf8 -*-
from glob import glob from glob import glob
import imp
import os import os
import sys
from shutil import rmtree from shutil import rmtree
import tempfile import tempfile
import unittest import unittest
from Cheetah.Compiler import Compiler from Cheetah.Compiler import Compiler
from Cheetah.Template import Template from Cheetah.Template import Template
from Cheetah import CheetahWrapper from Cheetah import CheetahWrapper
from Cheetah.compat import PY2, unicode from Cheetah.compat import PY2, unicode, load_module_from_file
class CommandLineTest(unittest.TestCase): class CommandLineTest(unittest.TestCase):
def createAndCompile(self, source): def createAndCompile(self, source):
sourcefile = '-' sourcefile = '-'
while sourcefile.find('-') != -1: while sourcefile.find('-') != -1:
sourcefile = tempfile.mktemp() sourcefile = tempfile.mktemp()
if PY2: if PY2:
fd = open('%s.tmpl' % sourcefile, 'w') fd = open('%s.tmpl' % sourcefile, 'w')
else: else:
fd = open('%s.tmpl' % sourcefile, 'w', encoding='utf-8') fd = open('%s.tmpl' % sourcefile, 'w', encoding='utf-8')
fd.write(source) fd.write(source)
fd.close() fd.close()
wrap = CheetahWrapper.CheetahWrapper() wrap = CheetahWrapper.CheetahWrapper()
wrap.main(['cheetah', 'compile', wrap.main(['cheetah', 'compile',
'--encoding=utf-8', '--settings=encoding="utf-8"', '--encoding=utf-8', '--settings=encoding="utf-8"',
'--quiet', '--nobackup', sourcefile]) '--quiet', '--nobackup', sourcefile])
module_path, module_name = os.path.split(sourcefile) module_name = os.path.split(sourcefile)[1]
module = loadModule(module_name, [module_path]) module = load_module_from_file(
module_name, module_name, sourcefile + '.py')
template = getattr(module, module_name) template = getattr(module, module_name)
os.remove('%s.tmpl' % sourcefile) os.remove('%s.tmpl' % sourcefile)
for sourcefile_py in glob('%s.py*' % sourcefile): # *.py[co] for sourcefile_py in glob('%s.py*' % sourcefile): # *.py[co]
os.remove(sourcefile_py) os.remove(sourcefile_py)
__pycache__ = os.path.join(os.path.dirname(sourcefile), '__pycache__') __pycache__ = os.path.join(os.path.dirname(sourcefile), '__pycache__')
if os.path.exists(__pycache__): # PY3 if os.path.exists(__pycache__): # PY3
rmtree(__pycache__) rmtree(__pycache__)
return template return template
class JBQ_UTF8_Test1(unittest.TestCase): class JBQ_UTF8_Test1(unittest.TestCase):
skipping to change at line 107 skipping to change at line 106
class JBQ_UTF8_Test5(unittest.TestCase): class JBQ_UTF8_Test5(unittest.TestCase):
def runTest(self): def runTest(self):
t = Template.compile(source="""#encoding utf-8 t = Template.compile(source="""#encoding utf-8
Main file with |$v| and eacute in the template é""") Main file with |$v| and eacute in the template é""")
t.v = u'Unicode String' t.v = u'Unicode String'
assert unicode(t()) assert unicode(t())
def loadModule(moduleName, path=None):
if path:
assert isinstance(path, list)
try:
mod = sys.modules[moduleName]
except KeyError:
fp = None
try:
fp, pathname, description = imp.find_module(moduleName, path)
mod = imp.load_module(moduleName, fp, pathname, description)
finally:
if fp:
fp.close()
return mod
class JBQ_UTF8_Test6(unittest.TestCase): class JBQ_UTF8_Test6(unittest.TestCase):
def runTest(self): def runTest(self):
source = """#encoding utf-8 source = """#encoding utf-8
#set $someUnicodeString = u"Bébé" #set $someUnicodeString = u"Bébé"
Main file with |$v| and eacute in the template é""" Main file with |$v| and eacute in the template é"""
t = Template.compile(source=source) t = Template.compile(source=source)
t.v = u'Unicode String' t.v = u'Unicode String'
assert unicode(t()) assert unicode(t())
 End of changes. 5 change blocks. 
21 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)