Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
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
django
Commits
a5406fe9
Kaydet (Commit)
a5406fe9
authored
Mar 10, 2018
tarafından
Sergey Fedoseev
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Used cached_property for File.size.
üst
5b083a82
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
13 deletions
+4
-13
base.py
django/core/files/base.py
+4
-13
No files found.
django/core/files/base.py
Dosyayı görüntüle @
a5406fe9
...
@@ -2,6 +2,7 @@ import os
...
@@ -2,6 +2,7 @@ import os
from
io
import
BytesIO
,
StringIO
,
UnsupportedOperation
from
io
import
BytesIO
,
StringIO
,
UnsupportedOperation
from
django.core.files.utils
import
FileProxyMixin
from
django.core.files.utils
import
FileProxyMixin
from
django.utils.functional
import
cached_property
class
File
(
FileProxyMixin
):
class
File
(
FileProxyMixin
):
...
@@ -27,7 +28,8 @@ class File(FileProxyMixin):
...
@@ -27,7 +28,8 @@ class File(FileProxyMixin):
def
__len__
(
self
):
def
__len__
(
self
):
return
self
.
size
return
self
.
size
def
_get_size_from_underlying_file
(
self
):
@cached_property
def
size
(
self
):
if
hasattr
(
self
.
file
,
'size'
):
if
hasattr
(
self
.
file
,
'size'
):
return
self
.
file
.
size
return
self
.
file
.
size
if
hasattr
(
self
.
file
,
'name'
):
if
hasattr
(
self
.
file
,
'name'
):
...
@@ -43,17 +45,6 @@ class File(FileProxyMixin):
...
@@ -43,17 +45,6 @@ class File(FileProxyMixin):
return
size
return
size
raise
AttributeError
(
"Unable to determine the file's size."
)
raise
AttributeError
(
"Unable to determine the file's size."
)
def
_get_size
(
self
):
if
hasattr
(
self
,
'_size'
):
return
self
.
_size
self
.
_size
=
self
.
_get_size_from_underlying_file
()
return
self
.
_size
def
_set_size
(
self
,
size
):
self
.
_size
=
size
size
=
property
(
_get_size
,
_set_size
)
def
chunks
(
self
,
chunk_size
=
None
):
def
chunks
(
self
,
chunk_size
=
None
):
"""
"""
Read the file and yield chunks of ``chunk_size`` bytes (defaults to
Read the file and yield chunks of ``chunk_size`` bytes (defaults to
...
@@ -150,7 +141,7 @@ class ContentFile(File):
...
@@ -150,7 +141,7 @@ class ContentFile(File):
pass
pass
def
write
(
self
,
data
):
def
write
(
self
,
data
):
self
.
__dict__
.
pop
(
'
_
size'
,
None
)
# Clear the computed size.
self
.
__dict__
.
pop
(
'size'
,
None
)
# Clear the computed size.
return
self
.
file
.
write
(
data
)
return
self
.
file
.
write
(
data
)
...
...
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