Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More removal of poorly legible constructs to workaround Python 2.4 sh…

…ortcomings.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16363 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c43d15b3b329c0dcd2bfeda9b647641f1dcfeaf6 1 parent 0e03a50
@ramiro ramiro authored
View
5 django/db/backends/oracle/base.py
@@ -6,9 +6,8 @@
import datetime
-import sys
-import time
from decimal import Decimal
+import sys
def _setup_environment(environ):
@@ -341,7 +340,7 @@ def value_to_db_time(self, value):
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
10 django/forms/fields.py
@@ -6,9 +6,7 @@
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.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 @@ def to_python(self, value):
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 @@ def to_python(self, value):
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 @@ def to_python(self, value):
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
7 django/forms/widgets.py
@@ -4,7 +4,6 @@
import copy
import datetime
-import time
from itertools import chain
from urlparse import urljoin
from util import flatatt
@@ -397,7 +396,7 @@ def _has_changed(self, initial, data):
# 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 @@ def _has_changed(self, initial, data):
# 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 @@ def _has_changed(self, initial, data):
# 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
3  django/views/generic/dates.py
@@ -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
4 tests/regressiontests/forms/tests/extra.py
@@ -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 @@ def __init__(self, attrs=None):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.