Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_nonexistent_file(self):
self.assertRaises(git_utils.GitError, git_utils.file_mode, 'branch',
'nonexist.txt')
def test_root_mode(self):
self.assertEqual(git_utils.file_mode('branch', ''), 0o040000)
def test_directory_mode(self):
self.assertEqual(git_utils.file_mode('branch', 'dir'), 0o040000)
self.assertEqual(git_utils.file_mode('branch', 'dir/'), 0o040000)
def test_directory_mode(self):
self.assertEqual(git_utils.file_mode('branch', 'dir'), 0o040000)
self.assertEqual(git_utils.file_mode('branch', 'dir/'), 0o040000)
def test_file_mode(self):
self.assertEqual(git_utils.file_mode('branch', 'dir/file.txt'),
0o100644)
def send_headers(self):
path = _to_git_path(self.path)
try:
if stat.S_ISDIR(git_utils.file_mode(self.branch, path)):
url = urlparse.urlsplit(self.path)
if not url.path.endswith('/'):
# Redirect the browser to a URL with a slash at the end,
# like Apache.
self.send_response(301)
dest = urlparse.urlunsplit(
url[:2] + (url[2] + '/',) + url[3:]
)
self.send_header('Location', dest)
self.end_headers()
return
path = posixpath.join(path, 'index.html')
git_utils.file_mode(self.branch, path)
self.send_response(200)
try:
if stat.S_ISDIR(git_utils.file_mode(self.branch, path)):
url = urlparse.urlsplit(self.path)
if not url.path.endswith('/'):
# Redirect the browser to a URL with a slash at the end,
# like Apache.
self.send_response(301)
dest = urlparse.urlunsplit(
url[:2] + (url[2] + '/',) + url[3:]
)
self.send_header('Location', dest)
self.end_headers()
return
path = posixpath.join(path, 'index.html')
git_utils.file_mode(self.branch, path)
self.send_response(200)
self.send_header('Content-Type', self.guess_type(path))
self.end_headers()
return path
except git_utils.GitError:
self.send_error(404, 'File not found')
except Exception: # pragma: no cover
self.send_error(500, 'Internal server error')