Ticket #2588: r3645_unicode.patch
File r3645_unicode.patch, 8.4 KB (added by , 18 years ago) |
---|
-
django/http/__init__.py
172 172 173 173 def __str__(self): 174 174 "Full HTTP message, including headers" 175 # Coerce the output to be in the correct charset 176 # Note that we are doing this at the last possible moment 177 # because we assume that all strings internal in django 178 # are proper unicode strings, or they're the ASCII portion 179 # of UTF-8 (codepoint 127 or less) 175 180 return '\n'.join(['%s: %s' % (key, value) 176 181 for key, value in self.headers.items()]) \ 177 + '\n\n' + self.content 182 + '\n\n' + self.content.encode(settings.DEFAULT_CHARSET) 178 183 179 184 def __setitem__(self, header, value): 180 185 self.headers[header] = value -
django/db/models/fields/__init__.py
290 290 return first_choice + list(self.choices) 291 291 rel_model = self.rel.to 292 292 if hasattr(self.rel, 'get_related_field'): 293 lst = [(getattr(x, self.rel.get_related_field().attname), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]293 lst = [(getattr(x, self.rel.get_related_field().attname), unicode(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] 294 294 else: 295 lst = [(x._get_pk_val(), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]295 lst = [(x._get_pk_val(), unicode(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] 296 296 return first_choice + lst 297 297 298 298 def get_choices_default(self): -
django/forms/__init__.py
158 158 159 159 def __str__(self): 160 160 "Renders the field" 161 return str(self.formfield.render(self.data))161 return unicode(self.formfield.render(self.data)) 162 162 163 163 def __repr__(self): 164 164 return '<FormFieldWrapper for "%s">' % self.formfield.field_name … … 392 392 if self.maxlength: 393 393 maxlength = 'maxlength="%s" ' % self.maxlength 394 394 if isinstance(data, unicode): 395 data = data.encode(settings.DEFAULT_CHARSET) 395 #data = data.encode(settings.DEFAULT_CHARSET) 396 data = unicode(data) 396 397 return '<input type="%s" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \ 397 398 (self.input_type, self.get_id(), self.__class__.__name__, self.is_required and ' required' or '', 398 399 self.field_name, self.length, escape(data), maxlength) … … 418 419 if data is None: 419 420 data = '' 420 421 if isinstance(data, unicode): 421 data = data.encode(settings.DEFAULT_CHARSET) 422 #data = data.encode(settings.DEFAULT_CHARSET) 423 data = unicode(data) 422 424 return '<textarea id="%s" class="v%s%s" name="%s" rows="%s" cols="%s">%s</textarea>' % \ 423 425 (self.get_id(), self.__class__.__name__, self.is_required and ' required' or '', 424 426 self.field_name, self.rows, self.cols, escape(data)) -
django/core/urlresolvers.py
79 79 test_regex = grouped 80 80 # Note we're using re.match here on purpose because the start of 81 81 # to string needs to match. 82 if not re.match(test_regex + '$', str(value)): # TODO: Unicode?82 if not re.match(test_regex + '$', unicode(value), re.UNICODE): 83 83 raise NoReverseMatch("Value %r didn't match regular expression %r" % (value, test_regex)) 84 return str(value) # TODO: Unicode?84 return unicode(value) 85 85 86 86 class RegexURLPattern(object): 87 87 def __init__(self, regex, callback, default_args=None): … … 89 89 # callback is either a string like 'foo.views.news.stories.story_detail' 90 90 # which represents the path to a module and a view function name, or a 91 91 # callable object (view). 92 self.regex = re.compile(regex )92 self.regex = re.compile(regex, re.UNICODE) 93 93 if callable(callback): 94 94 self._callback = callback 95 95 else: … … 143 143 def __init__(self, regex, urlconf_name, default_kwargs=None): 144 144 # regex is a string representing a regular expression. 145 145 # urlconf_name is a string representing the module containing urlconfs. 146 self.regex = re.compile(regex )146 self.regex = re.compile(regex, re.UNICODE) 147 147 self.urlconf_name = urlconf_name 148 148 self.callback = None 149 149 self.default_kwargs = default_kwargs or {} … … 225 225 from django.conf import settings 226 226 urlconf = settings.ROOT_URLCONF 227 227 resolver = RegexURLResolver(r'^/', urlconf) 228 228 229 return resolver.resolve(path) 229 230 230 231 def reverse(viewname, urlconf=None, args=None, kwargs=None): -
django/core/handlers/base.py
50 50 51 51 def get_response(self, path, request): 52 52 "Returns an HttpResponse object for the given HttpRequest" 53 from exceptions import UnicodeDecodeError 53 54 from django.core import exceptions, urlresolvers 54 55 from django.core.mail import mail_admins 55 56 from django.conf import settings 56 57 58 # URLs are encoded in UTF8 (RFC3986, RFC2718) 59 60 try: 61 path = path.decode('utf8') 62 except UnicodeDecodeError, ude: 63 raise exceptions.SuspiciousOperation, "Failed to decode the URL using UTF8. This is probably a user agent." 64 57 65 # Apply request middleware 58 66 for middleware_method in self._request_middleware: 59 67 response = middleware_method(request) -
django/template/__init__.py
688 688 bits.append(self.render_node(node, context)) 689 689 else: 690 690 bits.append(node) 691 return ''.join(bits)691 return u''.join(bits) 692 692 693 693 def get_nodes_by_type(self, nodetype): 694 694 "Return a list of all nodes of the given type" … … 734 734 return "<Variable Node: %s>" % self.filter_expression 735 735 736 736 def encode_output(self, output): 737 # Check type so that we don't run str() on a Unicode object 737 # We only want unicode. encoding to the default charset (utf8 for 738 # monkeybean) will result in a string of indeterminate encoding. 739 # We want to just convert the whole damn document into the right 740 # encoding just before we write to the output stream. That happens in 741 # django.http.__init__ 742 return unicode(output) 743 744 ''' 738 745 if not isinstance(output, basestring): 739 return str(output)746 return unicode(output) 740 747 elif isinstance(output, unicode): 741 748 return output.encode(settings.DEFAULT_CHARSET) 742 749 else: 743 return output 750 return unicode(output) 751 ''' 744 752 745 753 def render(self, context): 746 754 output = self.filter_expression.resolve(context) -
tests/othertests/urlpatterns_reverse.py
23 23 ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', NoReverseMatch, [], {'name': 'adrian'}), 24 24 ('^people/(?P<state>\w\w)/(\w+)/$', NoReverseMatch, ['il'], {'name': 'adrian'}), 25 25 ('^people/(?P<state>\w\w)/(\w+)/$', 'people/il/adrian/', ['adrian'], {'state': 'il'}), 26 ('^people/(?P<state>\w\w)/(\w+)/$', 'people/il/adrian/', ['adrian'], {'state': 'il'}), 27 ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', u'people/il/adria\xd0/', [], {'state': u'il', 'name': u'adria\xd0'}), 26 28 ) 27 29 28 30 def run_tests(verbosity=0):