summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-18 19:11:18 +0100
committerGitHub <noreply@github.com>2023-01-18 19:11:18 +0100
commit23e886886249ebe8f80a48b0d25fbb5308eeb06f (patch)
treeddd2eb220750704fa4fbfd8447654fc3d382bd10 /django/core
parentfd21f82aa82b0d75a161f618ef944ebe0923e0ab (diff)
downloaddjango-23e886886249ebe8f80a48b0d25fbb5308eeb06f.tar.gz
Refs #34233 -- Used str.removeprefix()/removesuffix().
Diffstat (limited to 'django/core')
-rw-r--r--django/core/cache/backends/memcached.py2
-rw-r--r--django/core/handlers/asgi.py4
-rw-r--r--django/core/handlers/wsgi.py2
-rw-r--r--django/core/management/commands/inspectdb.py2
-rw-r--r--django/core/management/templates.py5
-rw-r--r--django/core/management/utils.py2
-rw-r--r--django/core/serializers/json.py2
7 files changed, 9 insertions, 10 deletions
diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
index c970505b48..6e2c761511 100644
--- a/django/core/cache/backends/memcached.py
+++ b/django/core/cache/backends/memcached.py
@@ -155,7 +155,7 @@ class PyLibMCCache(BaseMemcachedCache):
def client_servers(self):
output = []
for server in self._servers:
- output.append(server[5:] if server.startswith("unix:") else server)
+ output.append(server.removeprefix("unix:"))
return output
def touch(self, key, timeout=DEFAULT_TIMEOUT, version=None):
diff --git a/django/core/handlers/asgi.py b/django/core/handlers/asgi.py
index 2aede079b9..39e2abe5a9 100644
--- a/django/core/handlers/asgi.py
+++ b/django/core/handlers/asgi.py
@@ -41,9 +41,9 @@ class ASGIRequest(HttpRequest):
self._read_started = False
self.resolver_match = None
self.script_name = self.scope.get("root_path", "")
- if self.script_name and scope["path"].startswith(self.script_name):
+ if self.script_name:
# TODO: Better is-prefix checking, slash handling?
- self.path_info = scope["path"][len(self.script_name) :]
+ self.path_info = scope["path"].removeprefix(self.script_name)
else:
self.path_info = scope["path"]
# The Django path is different from ASGI scope path args, it should
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index c071b5ca8c..c2b7cc2b6f 100644
--- a/django/core/handlers/wsgi.py
+++ b/django/core/handlers/wsgi.py
@@ -187,7 +187,7 @@ def get_script_name(environ):
# do the same with script_url before manipulating paths (#17133).
script_url = _slashes_re.sub(b"/", script_url)
path_info = get_bytes_from_wsgi(environ, "PATH_INFO", "")
- script_name = script_url[: -len(path_info)] if path_info else script_url
+ script_name = script_url.removesuffix(path_info)
else:
script_name = get_bytes_from_wsgi(environ, "SCRIPT_NAME", "")
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index 992c523a8e..3194aecacb 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -275,7 +275,7 @@ class Command(BaseCommand):
if is_relation:
if new_name.endswith("_id"):
- new_name = new_name[:-3]
+ new_name = new_name.removesuffix("_id")
else:
field_params["db_column"] = col_name
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index dd83668bca..16f3b4442c 100644
--- a/django/core/management/templates.py
+++ b/django/core/management/templates.py
@@ -182,7 +182,7 @@ class TemplateCommand(BaseCommand):
)
for old_suffix, new_suffix in self.rewrite_template_suffixes:
if new_path.endswith(old_suffix):
- new_path = new_path[: -len(old_suffix)] + new_suffix
+ new_path = new_path.removesuffix(old_suffix) + new_suffix
break # Only rewrite once
if os.path.exists(new_path):
@@ -241,8 +241,7 @@ class TemplateCommand(BaseCommand):
if template is None:
return os.path.join(django.__path__[0], "conf", subdir)
else:
- if template.startswith("file://"):
- template = template[7:]
+ template = template.removeprefix("file://")
expanded_template = os.path.expanduser(template)
expanded_template = os.path.normpath(expanded_template)
if os.path.isdir(expanded_template):
diff --git a/django/core/management/utils.py b/django/core/management/utils.py
index a308763d9d..fca61f2c23 100644
--- a/django/core/management/utils.py
+++ b/django/core/management/utils.py
@@ -135,7 +135,7 @@ def normalize_path_patterns(patterns):
for pattern in patterns:
for dir_suffix in dir_suffixes:
if pattern.endswith(dir_suffix):
- norm_patterns.append(pattern[: -len(dir_suffix)])
+ norm_patterns.append(pattern.removesuffix(dir_suffix))
break
else:
norm_patterns.append(pattern)
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index 59d7318409..afac821465 100644
--- a/django/core/serializers/json.py
+++ b/django/core/serializers/json.py
@@ -87,7 +87,7 @@ class DjangoJSONEncoder(json.JSONEncoder):
if o.microsecond:
r = r[:23] + r[26:]
if r.endswith("+00:00"):
- r = r[:-6] + "Z"
+ r = r.removesuffix("+00:00") + "Z"
return r
elif isinstance(o, datetime.date):
return o.isoformat()