Skip to content

Commit a8086ff

Browse files
BoboTiGdefnull
authored andcommitted
feat: optimize static_file()
`isfile(path) == True` implicates `exists(path) == True`, I think we can remove the first check then. https://github.com/python/cpython/blob/805e3368d6d07e58430654d1365283924fdf4143/Lib/genericpath.py#L17 and https://github.com/python/cpython/blob/805e3368d6d07e58430654d1365283924fdf4143/Lib/genericpath.py#L37 are indeed doing the same kind of calls.
1 parent 0207a34 commit a8086ff

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bottle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,7 +2780,7 @@ def static_file(filename, root,
27802780

27812781
if not filename.startswith(root):
27822782
return HTTPError(403, "Access denied.")
2783-
if not os.path.exists(filename) or not os.path.isfile(filename):
2783+
if not os.path.isfile(filename):
27842784
return HTTPError(404, "File does not exist.")
27852785
if not os.access(filename, os.R_OK):
27862786
return HTTPError(403, "You do not have permission to access this file.")

0 commit comments

Comments
 (0)