More removal of poorly legible constructs to workaround Python 2.4 shortcomings.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16363 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ramiro Morales 2011-06-10 18:43:29 +00:00
parent 0e03a504bf
commit c43d15b3b3
5 changed files with 12 additions and 17 deletions

View File

@ -6,9 +6,8 @@ Requires cx_Oracle: http://cx-oracle.sourceforge.net/
import datetime
import sys
import time
from decimal import Decimal
import sys
def _setup_environment(environ):
@ -341,7 +340,7 @@ WHEN (new.%(col_name)s IS NULL)
return None
if isinstance(value, basestring):
return datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
return datetime.datetime.strptime(value, '%H:%M:%S')
# Oracle doesn't support tz-aware datetimes
if value.tzinfo is not None:

View File

@ -6,9 +6,7 @@ import copy
import datetime
import os
import re
import time
import urlparse
import warnings
from decimal import Decimal, DecimalException
try:
from cStringIO import StringIO
@ -20,7 +18,6 @@ from django.core import validators
from django.utils import formats
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode, smart_str, force_unicode
from django.utils.functional import lazy
# Provide this import for backwards compatibility.
from django.core.validators import EMPTY_VALUES
@ -344,7 +341,8 @@ class BaseTemporalField(Field):
try:
datetime_str, usecs_str = value.rsplit('.', 1)
usecs = int(usecs_str)
return datetime.datetime(*time.strptime(datetime_str, format[:-3])[:6]+(usecs,))
dt = datetime.datetime.strptime(datetime_str, format[:-3])
return dt.replace(microsecond=usecs)
except ValueError:
continue
raise ValidationError(self.error_messages['invalid'])
@ -373,7 +371,7 @@ class DateField(BaseTemporalField):
return super(DateField, self).to_python(value)
def strptime(self, value, format):
return datetime.date(*time.strptime(value, format)[:3])
return datetime.datetime.strptime(value, format).date()
class TimeField(BaseTemporalField):
widget = TimeInput
@ -394,7 +392,7 @@ class TimeField(BaseTemporalField):
return super(TimeField, self).to_python(value)
def strptime(self, value, format):
return datetime.time(*time.strptime(value, format)[3:6])
return datetime.datetime.strptime(value, format).time()
class DateTimeField(BaseTemporalField):
widget = DateTimeInput

View File

@ -4,7 +4,6 @@ HTML Widget classes
import copy
import datetime
import time
from itertools import chain
from urlparse import urljoin
from util import flatatt
@ -397,7 +396,7 @@ class DateInput(Input):
# necessarily the format used for this widget. Attempt to convert it.
try:
input_format = formats.get_format('DATE_INPUT_FORMATS')[0]
initial = datetime.date(*time.strptime(initial, input_format)[:3])
initial = datetime.datetime.strptime(initial, input_format).date()
except (TypeError, ValueError):
pass
return super(DateInput, self)._has_changed(self._format_value(initial), data)
@ -429,7 +428,7 @@ class DateTimeInput(Input):
# necessarily the format used for this widget. Attempt to convert it.
try:
input_format = formats.get_format('DATETIME_INPUT_FORMATS')[0]
initial = datetime.datetime(*time.strptime(initial, input_format)[:6])
initial = datetime.datetime.strptime(initial, input_format)
except (TypeError, ValueError):
pass
return super(DateTimeInput, self)._has_changed(self._format_value(initial), data)
@ -460,7 +459,7 @@ class TimeInput(Input):
# necessarily the format used for this widget. Attempt to convert it.
try:
input_format = formats.get_format('TIME_INPUT_FORMATS')[0]
initial = datetime.time(*time.strptime(initial, input_format)[3:6])
initial = datetime.datetime.strptime(initial, input_format).time()
except (TypeError, ValueError):
pass
return super(TimeInput, self)._has_changed(self._format_value(initial), data)

View File

@ -1,4 +1,3 @@
import time
import datetime
from django.db import models
from django.core.exceptions import ImproperlyConfigured
@ -495,7 +494,7 @@ def _date_from_string(year, year_format, month, month_format, day='', day_format
format = delim.join((year_format, month_format, day_format))
datestr = delim.join((year, month, day))
try:
return datetime.date(*time.strptime(datestr, format)[:3])
return datetime.datetime.strptime(datestr, format).date()
except ValueError:
raise Http404(_(u"Invalid date string '%(datestr)s' given format '%(format)s'") % {
'datestr': datestr,

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import datetime
import time
from django.conf import settings
from django.forms import *
from django.forms.extras import SelectDateWidget
@ -379,7 +379,7 @@ class FormsExtraTestCase(unittest.TestCase, AssertFormErrorsMixin):
def decompress(self, value):
if value:
data = value.split(',')
return [data[0], data[1], datetime.datetime(*time.strptime(data[2], "%Y-%m-%d %H:%M:%S")[0:6])]
return [data[0], data[1], datetime.datetime.strptime(data[2], "%Y-%m-%d %H:%M:%S")]
return [None, None, None]
def format_output(self, rendered_widgets):