summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorДилян Палаузов <Dilyan.Palauzov@db.com>2018-01-03 18:52:12 -0500
committerTim Graham <timograham@gmail.com>2018-01-03 20:12:23 -0500
commitd7b2aa24f75434c2ce50100cfef3586071e0747a (patch)
tree9074eb7522888e744f948c52174f367a4281c200 /django/core
parentc2d0f8c084456b5073252a91eeb09ab3d7453b18 (diff)
Fixed #28982 -- Simplified code with and/or.
Diffstat (limited to 'django/core')
-rw-r--r--django/core/cache/backends/locmem.py4
-rw-r--r--django/core/files/base.py8
-rw-r--r--django/core/handlers/wsgi.py4
-rw-r--r--django/core/mail/message.py6
-rw-r--r--django/core/management/color.py4
-rw-r--r--django/core/management/commands/makemessages.py3
-rw-r--r--django/core/serializers/base.py3
7 files changed, 8 insertions, 24 deletions
diff --git a/django/core/cache/backends/locmem.py b/django/core/cache/backends/locmem.py
index 9809880bf5..69561fb735 100644
--- a/django/core/cache/backends/locmem.py
+++ b/django/core/cache/backends/locmem.py
@@ -98,9 +98,7 @@ class LocMemCache(BaseCache):
def _has_expired(self, key):
exp = self._expire_info.get(key, -1)
- if exp is None or exp > time.time():
- return False
- return True
+ return exp is not None and exp <= time.time()
def _cull(self):
if self._cull_frequency == 0:
diff --git a/django/core/files/base.py b/django/core/files/base.py
index 5e6332f0b6..2c0d4904d2 100644
--- a/django/core/files/base.py
+++ b/django/core/files/base.py
@@ -59,9 +59,7 @@ class File(FileProxyMixin):
Read the file and yield chunks of ``chunk_size`` bytes (defaults to
``UploadedFile.DEFAULT_CHUNK_SIZE``).
"""
- if not chunk_size:
- chunk_size = self.DEFAULT_CHUNK_SIZE
-
+ chunk_size = chunk_size or self.DEFAULT_CHUNK_SIZE
try:
self.seek(0)
except (AttributeError, UnsupportedOperation):
@@ -81,9 +79,7 @@ class File(FileProxyMixin):
always return ``False`` -- there's no good reason to read from memory in
chunks.
"""
- if not chunk_size:
- chunk_size = self.DEFAULT_CHUNK_SIZE
- return self.size > chunk_size
+ return self.size > (chunk_size or self.DEFAULT_CHUNK_SIZE)
def __iter__(self):
# Iterate over this file-like object by newlines
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index 010e9acfbc..a2d5b124af 100644
--- a/django/core/handlers/wsgi.py
+++ b/django/core/handlers/wsgi.py
@@ -176,9 +176,7 @@ def get_script_name(environ):
# rewrites. Unfortunately not every Web server (lighttpd!) passes this
# information through all the time, so FORCE_SCRIPT_NAME, above, is still
# needed.
- script_url = get_bytes_from_wsgi(environ, 'SCRIPT_URL', '')
- if not script_url:
- script_url = get_bytes_from_wsgi(environ, 'REDIRECT_URL', '')
+ script_url = get_bytes_from_wsgi(environ, 'SCRIPT_URL', '') or get_bytes_from_wsgi(environ, 'REDIRECT_URL', '')
if script_url:
if b'//' in script_url:
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index e34d1cb2a9..2050c587cc 100644
--- a/django/core/mail/message.py
+++ b/django/core/mail/message.py
@@ -309,11 +309,7 @@ class EmailMessage:
self.attachments.append(filename)
else:
assert content is not None
-
- if not mimetype:
- mimetype, _ = mimetypes.guess_type(filename)
- if not mimetype:
- mimetype = DEFAULT_ATTACHMENT_MIME_TYPE
+ mimetype = mimetype or mimetypes.guess_type(filename)[0] or DEFAULT_ATTACHMENT_MIME_TYPE
basetype, subtype = mimetype.split('/', 1)
if basetype == 'text':
diff --git a/django/core/management/color.py b/django/core/management/color.py
index e04c94fed1..42600fa1c8 100644
--- a/django/core/management/color.py
+++ b/django/core/management/color.py
@@ -19,9 +19,7 @@ def supports_color():
# isatty is not always implemented, #6223.
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
- if not supported_platform or not is_a_tty:
- return False
- return True
+ return supported_platform and is_a_tty
class Style:
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index fefa8ef3b0..4e47dd0687 100644
--- a/django/core/management/commands/makemessages.py
+++ b/django/core/management/commands/makemessages.py
@@ -502,8 +502,7 @@ class Command(BaseCommand):
if os.path.abspath(dirpath).startswith(os.path.dirname(path)):
locale_dir = path
break
- if not locale_dir:
- locale_dir = self.default_locale_path or NO_LOCALE_DIR
+ locale_dir = locale_dir or self.default_locale_path or NO_LOCALE_DIR
all_files.append(self.translatable_file_class(dirpath, filename, locale_dir))
return sorted(all_files)
diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py
index b29f96d3ec..def5146850 100644
--- a/django/core/serializers/base.py
+++ b/django/core/serializers/base.py
@@ -96,8 +96,7 @@ class Serializer:
self.handle_m2m_field(obj, field)
self.end_object(obj)
progress_bar.update(count)
- if self.first:
- self.first = False
+ self.first = self.first and False
self.end_serialization()
return self.getvalue()