~ubuntu-branches/ubuntu/jaunty/python-django/jaunty-backports

« back to all changes in this revision

Viewing changes to tests/regressiontests/templates/unicode.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
unicode_tests = ur"""
4
 
Templates can be created from unicode strings.
5
 
>>> from django.template import *
6
 
>>> from django.utils.safestring import SafeData
7
 
>>> t1 = Template(u'ŠĐĆŽćžšđ {{ var }}')
8
 
 
9
 
Templates can also be created from bytestrings. These are assumed by encoded
10
 
using UTF-8.
11
 
 
12
 
>>> s = '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91 {{ var }}'
13
 
>>> t2 = Template(s)
14
 
>>> s = '\x80\xc5\xc0'
15
 
>>> Template(s)
16
 
Traceback (most recent call last):
17
 
    ...
18
 
TemplateEncodingError: Templates can only be constructed from unicode or UTF-8 strings.
19
 
 
20
 
Contexts can be constructed from unicode or UTF-8 bytestrings.
21
 
 
22
 
>>> c1 = Context({'var': 'foo'})
23
 
>>> c2 = Context({u'var': 'foo'})
24
 
>>> c3 = Context({'var': u'Đđ'})
25
 
>>> c4 = Context({u'var': '\xc4\x90\xc4\x91'})
26
 
 
27
 
Since both templates and all four contexts represent the same thing, they all
28
 
render the same (and are returned as unicode objects and "safe" objects as
29
 
well, for auto-escaping purposes).
30
 
 
31
 
>>> t1.render(c3) == t2.render(c3)
32
 
True
33
 
>>> isinstance(t1.render(c3), unicode)
34
 
True
35
 
>>> isinstance(t1.render(c3), SafeData)
36
 
True
37
 
"""