| 30 | | # -*- coding: utf-8 -*- |
|---|
| 31 | | |
|---|
| 32 | | unicode_tests = ur""" |
|---|
| 33 | | Templates can be created from unicode strings. |
|---|
| 34 | | >>> from django.template import * |
|---|
| 35 | | >>> t1 = Template(u'ŠĐĆŽćžšđ {{ var }}') |
|---|
| 36 | | |
|---|
| 37 | | Templates can also be created from bytestrings. These are assumed by encoded using UTF-8. |
|---|
| 38 | | >>> s = '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91 {{ var }}' |
|---|
| 39 | | >>> t2 = Template(s) |
|---|
| 40 | | >>> s = '\x80\xc5\xc0' |
|---|
| 41 | | >>> Template(s) |
|---|
| 42 | | Traceback (most recent call last): |
|---|
| 43 | | ... |
|---|
| 44 | | TemplateEncodingError: Templates can only be constructed from unicode or UTF-8 strings. |
|---|
| 45 | | |
|---|
| 46 | | Contexts can be constructed from unicode or UTF-8 bytestrings. |
|---|
| 47 | | >>> c1 = Context({'var': 'foo'}) |
|---|
| 48 | | >>> c2 = Context({u'var': 'foo'}) |
|---|
| 49 | | >>> c3 = Context({'var': u'Đđ'}) |
|---|
| 50 | | >>> c4 = Context({u'var': '\xc4\x90\xc4\x91'}) |
|---|
| 51 | | |
|---|
| 52 | | Since both templates and all four contexts represent the same thing, they all |
|---|
| 53 | | render the same (and are returned as bytestrings). |
|---|
| 54 | | >>> t1.render(c3) == t2.render(c3) |
|---|
| 55 | | True |
|---|
| 56 | | >>> type(t1.render(c3)) |
|---|
| 57 | | <type 'str'> |
|---|
| 58 | | """ |
|---|