Author: mtredinnick
Date: 2007-06-17 05:25:48 -0500 (Sun, 17 Jun 2007)
New Revision: 5487

Modified:
   django/branches/unicode/django/contrib/sitemaps/views.py
   django/branches/unicode/django/http/__init__.py
   django/branches/unicode/django/template/__init__.py
   django/branches/unicode/django/template/loader.py
   django/branches/unicode/django/test/utils.py
   django/branches/unicode/tests/regressiontests/forms/tests.py
   django/branches/unicode/tests/regressiontests/templates/tests.py
   django/branches/unicode/tests/regressiontests/templates/unicode.py
Log:
unicode: Render templates as unicode objects and only convert them to
bytestrings as part of HttpRespnose and other output paths.


Modified: django/branches/unicode/django/contrib/sitemaps/views.py
===================================================================
--- django/branches/unicode/django/contrib/sitemaps/views.py    2007-06-17 
09:46:04 UTC (rev 5486)
+++ django/branches/unicode/django/contrib/sitemaps/views.py    2007-06-17 
10:25:48 UTC (rev 5487)
@@ -2,6 +2,7 @@
 from django.template import loader
 from django.contrib.sites.models import Site
 from django.core import urlresolvers
+from django.utils.encoding import smart_str
 
 def index(request, sitemaps):
     current_site = Site.objects.get_current()
@@ -26,5 +27,5 @@
             urls.extend(site().get_urls())
         else:
             urls.extend(site.get_urls())
-    xml = loader.render_to_string('sitemap.xml', {'urlset': urls}, 
encoding='utf-8')
+    xml = smart_str(loader.render_to_string('sitemap.xml', {'urlset': urls}))
     return HttpResponse(xml, mimetype='application/xml')

Modified: django/branches/unicode/django/http/__init__.py
===================================================================
--- django/branches/unicode/django/http/__init__.py     2007-06-17 09:46:04 UTC 
(rev 5486)
+++ django/branches/unicode/django/http/__init__.py     2007-06-17 10:25:48 UTC 
(rev 5487)
@@ -271,9 +271,7 @@
         self.cookies[key]['max-age'] = 0
 
     def _get_content(self):
-        content = ''.join(self._container)
-        if isinstance(content, unicode):
-            content = content.encode(self._charset)
+        content = smart_str(''.join(self._container), self._charset)
         return content
 
     def _set_content(self, value):

Modified: django/branches/unicode/django/template/__init__.py
===================================================================
--- django/branches/unicode/django/template/__init__.py 2007-06-17 09:46:04 UTC 
(rev 5486)
+++ django/branches/unicode/django/template/__init__.py 2007-06-17 10:25:48 UTC 
(rev 5487)
@@ -60,7 +60,7 @@
 from django.template.context import Context, RequestContext, 
ContextPopException
 from django.utils.functional import curry, Promise
 from django.utils.text import smart_split
-from django.utils.encoding import smart_unicode, smart_str, force_unicode
+from django.utils.encoding import smart_unicode, force_unicode
 from django.utils.translation import ugettext as _
 
 __all__ = ('Template', 'Context', 'RequestContext', 'compile_string')
@@ -176,9 +176,9 @@
             for subnode in node:
                 yield subnode
 
-    def render(self, context, encoding=None):
+    def render(self, context):
         "Display stage -- can be called many times"
-        return self.nodelist.render(context, encoding)
+        return self.nodelist.render(context)
 
 def compile_string(template_string, origin):
     "Compiles template_string into NodeList ready for rendering"
@@ -732,21 +732,14 @@
         return nodes
 
 class NodeList(list):
-    # How invalid encoding sequences are handled. The default 'strict' is not
-    # appropriate, because the framework is not in control of all the string
-    # data.
-    codec_errors = 'replace'
-
-    def render(self, context, encoding=None):
-        if encoding is None:
-            encoding = settings.DEFAULT_CHARSET
+    def render(self, context):
         bits = []
         for node in self:
             if isinstance(node, Node):
                 bits.append(self.render_node(node, context))
             else:
                 bits.append(node)
-        return ''.join([smart_str(b, encoding, errors=self.codec_errors) for b 
in bits])
+        return ''.join([force_unicode(b) for b in bits])
 
     def get_nodes_by_type(self, nodetype):
         "Return a list of all nodes of the given type"

Modified: django/branches/unicode/django/template/loader.py
===================================================================
--- django/branches/unicode/django/template/loader.py   2007-06-17 09:46:04 UTC 
(rev 5486)
+++ django/branches/unicode/django/template/loader.py   2007-06-17 10:25:48 UTC 
(rev 5487)
@@ -87,7 +87,7 @@
     """
     return Template(source, origin, name)
 
-def render_to_string(template_name, dictionary=None, context_instance=None, 
encoding=None):
+def render_to_string(template_name, dictionary=None, context_instance=None):
     """
     Loads the given template_name and renders it with the given dictionary as
     context. The template_name may be a string to load a single template using
@@ -103,7 +103,7 @@
         context_instance.update(dictionary)
     else:
         context_instance = Context(dictionary)
-    return t.render(context_instance, encoding)
+    return t.render(context_instance)
 
 def select_template(template_name_list):
     "Given a list of template names, returns the first that can be loaded."

Modified: django/branches/unicode/django/test/utils.py
===================================================================
--- django/branches/unicode/django/test/utils.py        2007-06-17 09:46:04 UTC 
(rev 5486)
+++ django/branches/unicode/django/test/utils.py        2007-06-17 10:25:48 UTC 
(rev 5487)
@@ -10,7 +10,7 @@
 # the test database.
 TEST_DATABASE_PREFIX = 'test_'
 
-def instrumented_test_render(self, context, unused=None):
+def instrumented_test_render(self, context):
     """
     An instrumented Template render method, providing a signal
     that can be intercepted by the test system Client

Modified: django/branches/unicode/tests/regressiontests/forms/tests.py
===================================================================
--- django/branches/unicode/tests/regressiontests/forms/tests.py        
2007-06-17 09:46:04 UTC (rev 5486)
+++ django/branches/unicode/tests/regressiontests/forms/tests.py        
2007-06-17 10:25:48 UTC (rev 5487)
@@ -3358,7 +3358,7 @@
 <input type="submit" />
 </form>
 >>> Template('{{ form.password1.help_text }}').render(Context({'form': 
 >>> UserRegistration(auto_id=False)}))
-''
+u''
 
 The label_tag() method takes an optional attrs argument: a dictionary of HTML
 attributes to add to the <label> tag.

Modified: django/branches/unicode/tests/regressiontests/templates/tests.py
===================================================================
--- django/branches/unicode/tests/regressiontests/templates/tests.py    
2007-06-17 09:46:04 UTC (rev 5486)
+++ django/branches/unicode/tests/regressiontests/templates/tests.py    
2007-06-17 10:25:48 UTC (rev 5487)
@@ -223,7 +223,7 @@
 
             # Make sure that any unicode strings are converted to bytestrings
             # in the final output.
-            'filter-syntax18': (r'{{ var }}', {'var': UTF8Class()}, 
'\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91'),
+            'filter-syntax18': (r'{{ var }}', {'var': UTF8Class()}, 
u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'),
 
             ### COMMENT SYNTAX 
########################################################
             'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"),

Modified: django/branches/unicode/tests/regressiontests/templates/unicode.py
===================================================================
--- django/branches/unicode/tests/regressiontests/templates/unicode.py  
2007-06-17 09:46:04 UTC (rev 5486)
+++ django/branches/unicode/tests/regressiontests/templates/unicode.py  
2007-06-17 10:25:48 UTC (rev 5487)
@@ -24,10 +24,10 @@
 >>> c4 = Context({u'var': '\xc4\x90\xc4\x91'})
 
 Since both templates and all four contexts represent the same thing, they all
-render the same (and are returned as bytestrings).
+render the same (and are returned as unicode objects).
 
 >>> t1.render(c3) == t2.render(c3)
 True
 >>> type(t1.render(c3))
-<type 'str'>
+<type 'unicode'>
 """


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to