[Checkins] SVN: hurry.custom/trunk/src/hurry/custom/ template source is in unicode, rendered templates are too.

Martijn Faassen faassen at startifact.com
Thu May 7 14:37:34 EDT 2009


Log message for revision 99802:
  template source is in unicode, rendered templates are too.

Changed:
  U   hurry.custom/trunk/src/hurry/custom/README.txt
  U   hurry.custom/trunk/src/hurry/custom/core.py

-=-
Modified: hurry.custom/trunk/src/hurry/custom/README.txt
===================================================================
--- hurry.custom/trunk/src/hurry/custom/README.txt	2009-05-07 17:22:49 UTC (rev 99801)
+++ hurry.custom/trunk/src/hurry/custom/README.txt	2009-05-07 18:37:33 UTC (rev 99802)
@@ -124,10 +124,14 @@
 We got our proper template::
 
   >>> template.source
-  'Hello $thing'
+  u'Hello $thing'
 
+As we can see the source text of the template was interpreted as a
+UTF-8 string. The template source should always be in unicode format
+(or in plain ASCII).
+
   >>> template({'thing': 'world'})
-  'Hello world'
+  u'Hello world'
 
 The underlying template will not be reloaded unless it is changed on
 the filesystem::
@@ -138,7 +142,7 @@
 not change on the filesystem::
 
   >>> template.source
-  'Hello $thing'
+  u'Hello $thing'
   >>> template.template is orig
   True
   
@@ -159,10 +163,10 @@
 Now the template will have changed::
 
   >>> template.source
-  'Bye $thing'
+  u'Bye $thing'
   
   >>> template({'thing': 'world'})
-  'Bye world'
+  u'Bye world'
 
 Customization database
 ----------------------
@@ -202,7 +206,7 @@
 
   >>> template = custom.lookup('templates', 'test1.st')
   >>> template({'thing': "universe"})
-  'Bye universe'
+  u'Bye universe'
 
 Customization of a template
 ---------------------------
@@ -240,13 +244,13 @@
 
   >>> template = custom.lookup('templates', 'test1.st')
   >>> template({'thing': 'planet'})
-  'Goodbye planet'
+  u'Goodbye planet'
 
 It is sometimes useful to be able to retrieve the original version of
 the template, before customization::
 
   >>> template.original_source
-  'Bye $thing'
+  u'Bye $thing'
 
 This could be used to implement a "revert" functionality in a
 customization UI, for instance.
@@ -383,7 +387,7 @@
 to the template itself::
 
   >>> template(r['sample1'])
-  'Goodbye galaxy'
+  u'Goodbye galaxy'
 
 Error handling
 --------------

Modified: hurry.custom/trunk/src/hurry/custom/core.py
===================================================================
--- hurry.custom/trunk/src/hurry/custom/core.py	2009-05-07 17:22:49 UTC (rev 99801)
+++ hurry.custom/trunk/src/hurry/custom/core.py	2009-05-07 18:37:33 UTC (rev 99802)
@@ -91,6 +91,8 @@
         
 class FilesystemTemplateDatabase(object):
     implements(ITemplateDatabase)
+
+    template_encoding = 'UTF-8'
     
     def __init__(self, id, path, title):
         self.id = id
@@ -102,7 +104,7 @@
         f = open(template_path, 'r')
         result = f.read()
         f.close()
-        return result
+        return unicode(result, self.template_encoding)
     
     def get_modification_time(self, template_id):
         template_path = os.path.join(self.path, template_id)



More information about the Checkins mailing list