Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replaced some byte strings by str() calls

This is a useful trick when Python 2 awaits byte strings and
Python 3 Unicode (regular) strings.
  • Loading branch information...
commit 9908201d7fc3340b83db21298033c5b347f38d65 1 parent 2407c45
@claudep claudep authored
View
2  django/core/handlers/wsgi.py
@@ -245,6 +245,6 @@ def __call__(self, environ, start_response):
status = '%s %s' % (response.status_code, status_text)
response_headers = [(str(k), str(v)) for k, v in response.items()]
for c in response.cookies.values():
- response_headers.append((b'Set-Cookie', str(c.output(header=''))))
+ response_headers.append((str('Set-Cookie'), str(c.output(header=''))))
start_response(smart_str(status), response_headers)
return response
View
18 django/db/backends/sqlite3/base.py
@@ -54,15 +54,15 @@ def adapt_datetime_with_timezone_support(value):
default_timezone = timezone.get_default_timezone()
value = timezone.make_aware(value, default_timezone)
value = value.astimezone(timezone.utc).replace(tzinfo=None)
- return value.isoformat(b" ")
-
-Database.register_converter(b"bool", lambda s: str(s) == '1')
-Database.register_converter(b"time", parse_time)
-Database.register_converter(b"date", parse_date)
-Database.register_converter(b"datetime", parse_datetime_with_timezone_support)
-Database.register_converter(b"timestamp", parse_datetime_with_timezone_support)
-Database.register_converter(b"TIMESTAMP", parse_datetime_with_timezone_support)
-Database.register_converter(b"decimal", util.typecast_decimal)
+ return value.isoformat(str(" "))
+
+Database.register_converter(str("bool"), lambda s: str(s) == '1')
+Database.register_converter(str("time"), parse_time)
+Database.register_converter(str("date"), parse_date)
+Database.register_converter(str("datetime"), parse_datetime_with_timezone_support)
+Database.register_converter(str("timestamp"), parse_datetime_with_timezone_support)
+Database.register_converter(str("TIMESTAMP"), parse_datetime_with_timezone_support)
+Database.register_converter(str("decimal"), util.typecast_decimal)
Database.register_adapter(datetime.datetime, adapt_datetime_with_timezone_support)
Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal)
if Database.version_info >= (2, 4, 1):
View
4 django/db/models/base.py
@@ -63,12 +63,12 @@ def __new__(cls, name, bases, attrs):
new_class.add_to_class('_meta', Options(meta, **kwargs))
if not abstract:
- new_class.add_to_class('DoesNotExist', subclass_exception(b'DoesNotExist',
+ new_class.add_to_class('DoesNotExist', subclass_exception(str('DoesNotExist'),
tuple(x.DoesNotExist
for x in parents if hasattr(x, '_meta') and not x._meta.abstract)
or (ObjectDoesNotExist,),
module, attached_to=new_class))
- new_class.add_to_class('MultipleObjectsReturned', subclass_exception(b'MultipleObjectsReturned',
+ new_class.add_to_class('MultipleObjectsReturned', subclass_exception(str('MultipleObjectsReturned'),
tuple(x.MultipleObjectsReturned
for x in parents if hasattr(x, '_meta') and not x._meta.abstract)
or (MultipleObjectsReturned,),
View
2  django/forms/formsets.py
@@ -365,7 +365,7 @@ def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
attrs = {'form': form, 'extra': extra,
'can_order': can_order, 'can_delete': can_delete,
'max_num': max_num}
- return type(form.__name__ + b'FormSet', (formset,), attrs)
+ return type(form.__name__ + str('FormSet'), (formset,), attrs)
def all_valid(formsets):
"""Returns true if every formset in formsets is valid."""
View
4 django/forms/models.py
@@ -389,10 +389,10 @@ def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
parent = (object,)
if hasattr(form, 'Meta'):
parent = (form.Meta, object)
- Meta = type(b'Meta', parent, attrs)
+ Meta = type(str('Meta'), parent, attrs)
# Give this new form class a reasonable name.
- class_name = model.__name__ + b'Form'
+ class_name = model.__name__ + str('Form')
# Class attributes for the new form class.
form_class_attrs = {
View
2  django/http/__init__.py
@@ -22,7 +22,7 @@
# See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256
_tc = http_cookies.SimpleCookie()
try:
- _tc.load(b'foo:bar=1')
+ _tc.load(str('foo:bar=1'))
_cookie_allows_colon_in_names = True
except http_cookies.CookieError:
_cookie_allows_colon_in_names = False
Please sign in to comment.
Something went wrong with that request. Please try again.