Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@malcolmt malcolmt authored
View
2  django/db/models/base.py
@@ -84,7 +84,7 @@ def _get_pk_val(self):
return getattr(self, self._meta.pk.attname)
def __repr__(self):
- return smart_str(u'<%s: %s>' % (self.__class__.__name__, self))
+ return smart_str(u'<%s: %s>' % (self.__class__.__name__, unicode(self)))
def __str__(self):
if hasattr(self, '__unicode__'):
View
8 django/newforms/util.py
@@ -18,10 +18,10 @@ def __str__(self):
def as_ul(self):
if not self: return u''
- return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s%s</li>' % (k, v) for k, v in self.items()])
+ return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s%s</li>' % (k, smart_unicode(v)) for k, v in self.items()])
def as_text(self):
- 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()])
+ 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()])
class ErrorList(list):
"""
@@ -32,11 +32,11 @@ def __str__(self):
def as_ul(self):
if not self: return u''
- return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s</li>' % e for e in self])
+ return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s</li>' % smart_unicode(e) for e in self])
def as_text(self):
if not self: return u''
- return u'\n'.join([u'* %s' % e for e in self])
+ return u'\n'.join([u'* %s' % smart_unicode(e) for e in self])
class ValidationError(Exception):
def __init__(self, message):
View
2  django/newforms/widgets.py
@@ -253,7 +253,7 @@ def __getitem__(self, idx):
def __unicode__(self):
"Outputs a <ul> for this set of radio fields."
- return u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' % w for w in self])
+ return u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' % smart_unicode(w) for w in self])
class RadioSelect(Select):
def render(self, name, value, attrs=None, choices=()):
View
8 django/template/defaultfilters.py
@@ -170,7 +170,7 @@ def upper(value):
def urlencode(value):
"Escapes a value for use in a URL"
import urllib
- return urllib.quote(value).decode('utf-8')
+ return smart_unicode(urllib.quote(value))
urlencode = stringfilter(urlencode)
def urlize(value):
@@ -364,10 +364,10 @@ def unordered_list(value):
def _helper(value, tabs):
indent = u'\t' * tabs
if value[1]:
- return u'%s<li>%s\n%s<ul>\n%s\n%s</ul>\n%s</li>' % (indent, value[0], indent,
+ return u'%s<li>%s\n%s<ul>\n%s\n%s</ul>\n%s</li>' % (indent, smart_unicode(value[0]), indent,
u'\n'.join([_helper(v, tabs+1) for v in value[1]]), indent, indent)
else:
- return u'%s<li>%s</li>' % (indent, value[0])
+ return u'%s<li>%s</li>' % (indent, smart_unicode(value[0]))
return _helper(value, 1)
###################
@@ -546,7 +546,7 @@ def pprint(value):
try:
return pformat(value)
except Exception, e:
- return u"Error in formatting:%s" % e
+ return u"Error in formatting:%s" % smart_unicode(e)
# Syntax: register.filter(name of filter, callback)
register.filter(add)
View
12 django/utils/html.py
@@ -32,7 +32,7 @@ def linebreaks(value):
"Converts newlines into <p> and <br />s"
value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines
paras = re.split('\n{2,}', value)
- paras = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras]
+ paras = [u'<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras]
return u'\n\n'.join(paras)
def strip_tags(value):
@@ -53,14 +53,16 @@ def fix_ampersands(value):
def urlize(text, trim_url_limit=None, nofollow=False):
"""
- Converts any URLs in text into clickable links. Works on http://, https:// and
- www. links. Links can have trailing punctuation (periods, commas, close-parens)
- and leading punctuation (opening parens) and it'll still do the right thing.
+ Converts any URLs in text into clickable links. Works on http://, https://
+ and www. links. Links can have trailing punctuation (periods, commas,
+ close-parens) and leading punctuation (opening parens) and it'll still do
+ the right thing.
If trim_url_limit is not None, the URLs in link text will be limited to
trim_url_limit characters.
- If nofollow is True, the URLs in link text will get a rel="nofollow" attribute.
+ If nofollow is True, the URLs in link text will get a rel="nofollow"
+ attribute.
"""
trim_url = lambda x, limit=trim_url_limit: limit is not None and (x[:limit] + (len(x) >=limit and '...' or '')) or x
words = word_split_re.split(text)
Please sign in to comment.
Something went wrong with that request. Please try again.