Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

unicode: Made various changes to prevent actual and potential Python 2.3

compatibility problems. Refs #3582.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5223 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6c99a60e0d8b457720227540846982cee1bb7c45 1 parent 28f66bb
Malcolm Tredinnick authored May 14, 2007
2  django/db/models/base.py
@@ -84,7 +84,7 @@ def _get_pk_val(self):
84 84
         return getattr(self, self._meta.pk.attname)
85 85
 
86 86
     def __repr__(self):
87  
-        return smart_str(u'<%s: %s>' % (self.__class__.__name__, self))
  87
+        return smart_str(u'<%s: %s>' % (self.__class__.__name__, unicode(self)))
88 88
 
89 89
     def __str__(self):
90 90
         if hasattr(self, '__unicode__'):
8  django/newforms/util.py
@@ -18,10 +18,10 @@ def __str__(self):
18 18
 
19 19
     def as_ul(self):
20 20
         if not self: return u''
21  
-        return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s%s</li>' % (k, v) for k, v in self.items()])
  21
+        return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s%s</li>' % (k, smart_unicode(v)) for k, v in self.items()])
22 22
 
23 23
     def as_text(self):
24  
-        return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u'  * %s' % i for i in v])) for k, v in self.items()])
  24
+        return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u'  * %s' % smart_unicode(i) for i in v])) for k, v in self.items()])
25 25
 
26 26
 class ErrorList(list):
27 27
     """
@@ -32,11 +32,11 @@ def __str__(self):
32 32
 
33 33
     def as_ul(self):
34 34
         if not self: return u''
35  
-        return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s</li>' % e for e in self])
  35
+        return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s</li>' % smart_unicode(e) for e in self])
36 36
 
37 37
     def as_text(self):
38 38
         if not self: return u''
39  
-        return u'\n'.join([u'* %s' % e for e in self])
  39
+        return u'\n'.join([u'* %s' % smart_unicode(e) for e in self])
40 40
 
41 41
 class ValidationError(Exception):
42 42
     def __init__(self, message):
2  django/newforms/widgets.py
@@ -253,7 +253,7 @@ def __getitem__(self, idx):
253 253
 
254 254
     def __unicode__(self):
255 255
         "Outputs a <ul> for this set of radio fields."
256  
-        return u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' % w for w in self])
  256
+        return u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' % smart_unicode(w) for w in self])
257 257
 
258 258
 class RadioSelect(Select):
259 259
     def render(self, name, value, attrs=None, choices=()):
8  django/template/defaultfilters.py
@@ -170,7 +170,7 @@ def upper(value):
170 170
 def urlencode(value):
171 171
     "Escapes a value for use in a URL"
172 172
     import urllib
173  
-    return urllib.quote(value).decode('utf-8')
  173
+    return smart_unicode(urllib.quote(value))
174 174
 urlencode = stringfilter(urlencode)
175 175
 
176 176
 def urlize(value):
@@ -364,10 +364,10 @@ def unordered_list(value):
364 364
     def _helper(value, tabs):
365 365
         indent = u'\t' * tabs
366 366
         if value[1]:
367  
-            return u'%s<li>%s\n%s<ul>\n%s\n%s</ul>\n%s</li>' % (indent, value[0], indent,
  367
+            return u'%s<li>%s\n%s<ul>\n%s\n%s</ul>\n%s</li>' % (indent, smart_unicode(value[0]), indent,
368 368
                 u'\n'.join([_helper(v, tabs+1) for v in value[1]]), indent, indent)
369 369
         else:
370  
-            return u'%s<li>%s</li>' % (indent, value[0])
  370
+            return u'%s<li>%s</li>' % (indent, smart_unicode(value[0]))
371 371
     return _helper(value, 1)
372 372
 
373 373
 ###################
@@ -546,7 +546,7 @@ def pprint(value):
546 546
     try:
547 547
         return pformat(value)
548 548
     except Exception, e:
549  
-        return u"Error in formatting:%s" % e
  549
+        return u"Error in formatting:%s" % smart_unicode(e)
550 550
 
551 551
 # Syntax: register.filter(name of filter, callback)
552 552
 register.filter(add)
12  django/utils/html.py
@@ -32,7 +32,7 @@ def linebreaks(value):
32 32
     "Converts newlines into <p> and <br />s"
33 33
     value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines
34 34
     paras = re.split('\n{2,}', value)
35  
-    paras = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras]
  35
+    paras = [u'<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras]
36 36
     return u'\n\n'.join(paras)
37 37
 
38 38
 def strip_tags(value):
@@ -53,14 +53,16 @@ def fix_ampersands(value):
53 53
 
54 54
 def urlize(text, trim_url_limit=None, nofollow=False):
55 55
     """
56  
-    Converts any URLs in text into clickable links. Works on http://, https:// and
57  
-    www. links. Links can have trailing punctuation (periods, commas, close-parens)
58  
-    and leading punctuation (opening parens) and it'll still do the right thing.
  56
+    Converts any URLs in text into clickable links. Works on http://, https://
  57
+    and www. links. Links can have trailing punctuation (periods, commas,
  58
+    close-parens) and leading punctuation (opening parens) and it'll still do
  59
+    the right thing.
59 60
 
60 61
     If trim_url_limit is not None, the URLs in link text will be limited to
61 62
     trim_url_limit characters.
62 63
 
63  
-    If nofollow is True, the URLs in link text will get a rel="nofollow" attribute.
  64
+    If nofollow is True, the URLs in link text will get a rel="nofollow"
  65
+    attribute.
64 66
     """
65 67
     trim_url = lambda x, limit=trim_url_limit: limit is not None and (x[:limit] + (len(x) >=limit and '...' or ''))  or x
66 68
     words = word_split_re.split(text)

0 notes on commit 6c99a60

Please sign in to comment.
Something went wrong with that request. Please try again.