Replaced some byte strings by str() calls
This is a useful trick when Python 2 awaits byte strings and Python 3 Unicode (regular) strings.
This commit is contained in:
parent
2407c45c18
commit
9908201d7f
|
@ -245,6 +245,6 @@ class WSGIHandler(base.BaseHandler):
|
||||||
status = '%s %s' % (response.status_code, status_text)
|
status = '%s %s' % (response.status_code, status_text)
|
||||||
response_headers = [(str(k), str(v)) for k, v in response.items()]
|
response_headers = [(str(k), str(v)) for k, v in response.items()]
|
||||||
for c in response.cookies.values():
|
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)
|
start_response(smart_str(status), response_headers)
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -54,15 +54,15 @@ def adapt_datetime_with_timezone_support(value):
|
||||||
default_timezone = timezone.get_default_timezone()
|
default_timezone = timezone.get_default_timezone()
|
||||||
value = timezone.make_aware(value, default_timezone)
|
value = timezone.make_aware(value, default_timezone)
|
||||||
value = value.astimezone(timezone.utc).replace(tzinfo=None)
|
value = value.astimezone(timezone.utc).replace(tzinfo=None)
|
||||||
return value.isoformat(b" ")
|
return value.isoformat(str(" "))
|
||||||
|
|
||||||
Database.register_converter(b"bool", lambda s: str(s) == '1')
|
Database.register_converter(str("bool"), lambda s: str(s) == '1')
|
||||||
Database.register_converter(b"time", parse_time)
|
Database.register_converter(str("time"), parse_time)
|
||||||
Database.register_converter(b"date", parse_date)
|
Database.register_converter(str("date"), parse_date)
|
||||||
Database.register_converter(b"datetime", parse_datetime_with_timezone_support)
|
Database.register_converter(str("datetime"), parse_datetime_with_timezone_support)
|
||||||
Database.register_converter(b"timestamp", parse_datetime_with_timezone_support)
|
Database.register_converter(str("timestamp"), parse_datetime_with_timezone_support)
|
||||||
Database.register_converter(b"TIMESTAMP", parse_datetime_with_timezone_support)
|
Database.register_converter(str("TIMESTAMP"), parse_datetime_with_timezone_support)
|
||||||
Database.register_converter(b"decimal", util.typecast_decimal)
|
Database.register_converter(str("decimal"), util.typecast_decimal)
|
||||||
Database.register_adapter(datetime.datetime, adapt_datetime_with_timezone_support)
|
Database.register_adapter(datetime.datetime, adapt_datetime_with_timezone_support)
|
||||||
Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal)
|
Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal)
|
||||||
if Database.version_info >= (2, 4, 1):
|
if Database.version_info >= (2, 4, 1):
|
||||||
|
|
|
@ -63,12 +63,12 @@ class ModelBase(type):
|
||||||
|
|
||||||
new_class.add_to_class('_meta', Options(meta, **kwargs))
|
new_class.add_to_class('_meta', Options(meta, **kwargs))
|
||||||
if not abstract:
|
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
|
tuple(x.DoesNotExist
|
||||||
for x in parents if hasattr(x, '_meta') and not x._meta.abstract)
|
for x in parents if hasattr(x, '_meta') and not x._meta.abstract)
|
||||||
or (ObjectDoesNotExist,),
|
or (ObjectDoesNotExist,),
|
||||||
module, attached_to=new_class))
|
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
|
tuple(x.MultipleObjectsReturned
|
||||||
for x in parents if hasattr(x, '_meta') and not x._meta.abstract)
|
for x in parents if hasattr(x, '_meta') and not x._meta.abstract)
|
||||||
or (MultipleObjectsReturned,),
|
or (MultipleObjectsReturned,),
|
||||||
|
|
|
@ -365,7 +365,7 @@ def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
|
||||||
attrs = {'form': form, 'extra': extra,
|
attrs = {'form': form, 'extra': extra,
|
||||||
'can_order': can_order, 'can_delete': can_delete,
|
'can_order': can_order, 'can_delete': can_delete,
|
||||||
'max_num': max_num}
|
'max_num': max_num}
|
||||||
return type(form.__name__ + b'FormSet', (formset,), attrs)
|
return type(form.__name__ + str('FormSet'), (formset,), attrs)
|
||||||
|
|
||||||
def all_valid(formsets):
|
def all_valid(formsets):
|
||||||
"""Returns true if every formset in formsets is valid."""
|
"""Returns true if every formset in formsets is valid."""
|
||||||
|
|
|
@ -389,10 +389,10 @@ def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
|
||||||
parent = (object,)
|
parent = (object,)
|
||||||
if hasattr(form, 'Meta'):
|
if hasattr(form, 'Meta'):
|
||||||
parent = (form.Meta, object)
|
parent = (form.Meta, object)
|
||||||
Meta = type(b'Meta', parent, attrs)
|
Meta = type(str('Meta'), parent, attrs)
|
||||||
|
|
||||||
# Give this new form class a reasonable name.
|
# 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.
|
# Class attributes for the new form class.
|
||||||
form_class_attrs = {
|
form_class_attrs = {
|
||||||
|
|
|
@ -22,7 +22,7 @@ _cookie_encodes_correctly = http_cookies.SimpleCookie().value_encode(';') == (';
|
||||||
# See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256
|
# See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256
|
||||||
_tc = http_cookies.SimpleCookie()
|
_tc = http_cookies.SimpleCookie()
|
||||||
try:
|
try:
|
||||||
_tc.load(b'foo:bar=1')
|
_tc.load(str('foo:bar=1'))
|
||||||
_cookie_allows_colon_in_names = True
|
_cookie_allows_colon_in_names = True
|
||||||
except http_cookies.CookieError:
|
except http_cookies.CookieError:
|
||||||
_cookie_allows_colon_in_names = False
|
_cookie_allows_colon_in_names = False
|
||||||
|
|
Loading…
Reference in New Issue