Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
47649ab1
Kaydet (Commit)
47649ab1
authored
Agu 08, 2016
tarafından
Alexander Belopolsky
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes #27710: Disallow fold not in [0, 1] in time and datetime constructors.
üst
95e0df83
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
11 deletions
+36
-11
datetime.py
Lib/datetime.py
+8
-6
datetimetester.py
Lib/test/datetimetester.py
+5
-0
_datetimemodule.c
Modules/_datetimemodule.c
+23
-5
No files found.
Lib/datetime.py
Dosyayı görüntüle @
47649ab1
...
...
@@ -288,7 +288,7 @@ def _check_date_fields(year, month, day):
raise
ValueError
(
'day must be in 1..
%
d'
%
dim
,
day
)
return
year
,
month
,
day
def
_check_time_fields
(
hour
,
minute
,
second
,
microsecond
):
def
_check_time_fields
(
hour
,
minute
,
second
,
microsecond
,
fold
):
hour
=
_check_int_field
(
hour
)
minute
=
_check_int_field
(
minute
)
second
=
_check_int_field
(
second
)
...
...
@@ -301,7 +301,9 @@ def _check_time_fields(hour, minute, second, microsecond):
raise
ValueError
(
'second must be in 0..59'
,
second
)
if
not
0
<=
microsecond
<=
999999
:
raise
ValueError
(
'microsecond must be in 0..999999'
,
microsecond
)
return
hour
,
minute
,
second
,
microsecond
if
fold
not
in
(
0
,
1
):
raise
ValueError
(
'fold must be either 0 or 1'
,
fold
)
return
hour
,
minute
,
second
,
microsecond
,
fold
def
_check_tzinfo_arg
(
tz
):
if
tz
is
not
None
and
not
isinstance
(
tz
,
tzinfo
):
...
...
@@ -1059,8 +1061,8 @@ class time:
self
.
__setstate
(
hour
,
minute
or
None
)
self
.
_hashcode
=
-
1
return
self
hour
,
minute
,
second
,
microsecond
=
_check_time_fields
(
hour
,
minute
,
second
,
microsecond
)
hour
,
minute
,
second
,
microsecond
,
fold
=
_check_time_fields
(
hour
,
minute
,
second
,
microsecond
,
fold
)
_check_tzinfo_arg
(
tzinfo
)
self
=
object
.
__new__
(
cls
)
self
.
_hour
=
hour
...
...
@@ -1369,8 +1371,8 @@ class datetime(date):
self
.
_hashcode
=
-
1
return
self
year
,
month
,
day
=
_check_date_fields
(
year
,
month
,
day
)
hour
,
minute
,
second
,
microsecond
=
_check_time_fields
(
hour
,
minute
,
second
,
microsecond
)
hour
,
minute
,
second
,
microsecond
,
fold
=
_check_time_fields
(
hour
,
minute
,
second
,
microsecond
,
fold
)
_check_tzinfo_arg
(
tzinfo
)
self
=
object
.
__new__
(
cls
)
self
.
_year
=
year
...
...
Lib/test/datetimetester.py
Dosyayı görüntüle @
47649ab1
...
...
@@ -1724,6 +1724,11 @@ class TestDateTime(TestDate):
self
.
assertRaises
(
ValueError
,
self
.
theclass
,
2000
,
1
,
31
,
23
,
59
,
59
,
1000000
)
# bad fold
self
.
assertRaises
(
ValueError
,
self
.
theclass
,
2000
,
1
,
31
,
fold
=-
1
)
self
.
assertRaises
(
ValueError
,
self
.
theclass
,
2000
,
1
,
31
,
fold
=
2
)
# Positional fold:
self
.
assertRaises
(
TypeError
,
self
.
theclass
,
2000
,
1
,
31
,
23
,
59
,
59
,
0
,
None
,
1
)
...
...
Modules/_datetimemodule.c
Dosyayı görüntüle @
47649ab1
...
...
@@ -427,7 +427,7 @@ check_date_args(int year, int month, int day)
* aren't, raise ValueError and return -1.
*/
static
int
check_time_args
(
int
h
,
int
m
,
int
s
,
int
us
)
check_time_args
(
int
h
,
int
m
,
int
s
,
int
us
,
int
fold
)
{
if
(
h
<
0
||
h
>
23
)
{
PyErr_SetString
(
PyExc_ValueError
,
...
...
@@ -449,6 +449,11 @@ check_time_args(int h, int m, int s, int us)
"microsecond must be in 0..999999"
);
return
-
1
;
}
if
(
fold
!=
0
&&
fold
!=
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"fold must be either 0 or 1"
);
return
-
1
;
}
return
0
;
}
...
...
@@ -3598,7 +3603,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
if
(
PyArg_ParseTupleAndKeywords
(
args
,
kw
,
"|iiiiO$i"
,
time_kws
,
&
hour
,
&
minute
,
&
second
,
&
usecond
,
&
tzinfo
,
&
fold
))
{
if
(
check_time_args
(
hour
,
minute
,
second
,
usecond
)
<
0
)
if
(
check_time_args
(
hour
,
minute
,
second
,
usecond
,
fold
)
<
0
)
return
NULL
;
if
(
check_tzinfo_subclass
(
tzinfo
)
<
0
)
return
NULL
;
...
...
@@ -3926,8 +3931,14 @@ time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
if
(
tuple
==
NULL
)
return
NULL
;
clone
=
time_new
(
Py_TYPE
(
self
),
tuple
,
NULL
);
if
(
clone
!=
NULL
)
if
(
clone
!=
NULL
)
{
if
(
fold
!=
0
&&
fold
!=
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"fold must be either 0 or 1"
);
return
NULL
;
}
TIME_SET_FOLD
(
clone
,
fold
);
}
Py_DECREF
(
tuple
);
return
clone
;
}
...
...
@@ -4175,7 +4186,7 @@ datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
&
second
,
&
usecond
,
&
tzinfo
,
&
fold
))
{
if
(
check_date_args
(
year
,
month
,
day
)
<
0
)
return
NULL
;
if
(
check_time_args
(
hour
,
minute
,
second
,
usecond
)
<
0
)
if
(
check_time_args
(
hour
,
minute
,
second
,
usecond
,
fold
)
<
0
)
return
NULL
;
if
(
check_tzinfo_subclass
(
tzinfo
)
<
0
)
return
NULL
;
...
...
@@ -5006,8 +5017,15 @@ datetime_replace(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
if
(
tuple
==
NULL
)
return
NULL
;
clone
=
datetime_new
(
Py_TYPE
(
self
),
tuple
,
NULL
);
if
(
clone
!=
NULL
)
if
(
clone
!=
NULL
)
{
if
(
fold
!=
0
&&
fold
!=
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"fold must be either 0 or 1"
);
return
NULL
;
}
DATE_SET_FOLD
(
clone
,
fold
);
}
Py_DECREF
(
tuple
);
return
clone
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment