def _compute_filename(self, request): '''Get the appropriate filename from the request.''' path = self._path_namer.get_filename(request.url_info) if os.path.isdir(path): path += '.f' else: dir_name, name = os.path.split(path) path = os.path.join(anti_clobber_dir_path(dir_name), name) return path
def _compute_filename(self, request: BaseRequest): '''Get the appropriate filename from the request.''' path = self._path_namer.get_filename(request.url_info) if os.path.isdir(path): path += '.f' else: dir_name, name = os.path.split(path) path = os.path.join(anti_clobber_dir_path(dir_name), name) return path
def test_anti_clobber_dir_path(self): with self.cd_tempdir(): self.assertEqual('a', anti_clobber_dir_path('a')) with self.cd_tempdir(): self.assertEqual('a/b/c/d/e/f/g', anti_clobber_dir_path('a/b/c/d/e/f/g/')) with self.cd_tempdir(): self.assertEqual('a/b/c/d/e/f/g', anti_clobber_dir_path('a/b/c/d/e/f/g')) with self.cd_tempdir(): with open('a', 'w'): pass self.assertEqual('a.d/b/c/d/e/f/g', anti_clobber_dir_path('a/b/c/d/e/f/g')) with self.cd_tempdir(): os.makedirs('a/b') with open('a/b/c', 'w'): pass self.assertEqual('a/b/c.d/d/e/f/g', anti_clobber_dir_path('a/b/c/d/e/f/g')) with self.cd_tempdir(): os.makedirs('a/b/c/d/e/f') with open('a/b/c/d/e/f/g', 'w'): pass self.assertEqual('a/b/c/d/e/f/g.d', anti_clobber_dir_path('a/b/c/d/e/f/g'))
def _compute_filename(self, request): original_filename = self._path_namer.get_filename(request.url_info) dir_name, filename = os.path.split(original_filename) original_filename = os.path.join(anti_clobber_dir_path(dir_name), filename) candidate_filename = original_filename for suffix in itertools.count(): if suffix: candidate_filename = '{0}.{1}'.format(original_filename, suffix) if not os.path.exists(candidate_filename): return candidate_filename
def _compute_filename(self, request: BaseRequest): original_filename = self._path_namer.get_filename(request.url_info) dir_name, filename = os.path.split(original_filename) original_filename = os.path.join( anti_clobber_dir_path(dir_name), filename ) candidate_filename = original_filename for suffix in itertools.count(): if suffix: candidate_filename = '{0}.{1}'.format(original_filename, suffix) if not os.path.exists(candidate_filename): return candidate_filename
def test_anti_clobber_dir_path(self): with self.cd_tempdir(): self.assertEqual( 'a', anti_clobber_dir_path('a') ) with self.cd_tempdir(): self.assertEqual( 'a/b/c/d/e/f/g', anti_clobber_dir_path('a/b/c/d/e/f/g/') ) with self.cd_tempdir(): self.assertEqual( 'a/b/c/d/e/f/g', anti_clobber_dir_path('a/b/c/d/e/f/g') ) with self.cd_tempdir(): with open('a', 'w'): pass self.assertEqual( 'a.d/b/c/d/e/f/g', anti_clobber_dir_path('a/b/c/d/e/f/g') ) with self.cd_tempdir(): os.makedirs('a/b') with open('a/b/c', 'w'): pass self.assertEqual( 'a/b/c.d/d/e/f/g', anti_clobber_dir_path('a/b/c/d/e/f/g') ) with self.cd_tempdir(): os.makedirs('a/b/c/d/e/f') with open('a/b/c/d/e/f/g', 'w'): pass self.assertEqual( 'a/b/c/d/e/f/g.d', anti_clobber_dir_path('a/b/c/d/e/f/g') )
def test_anti_clobber_dir_path(self): with self.cd_tempdir(): self.assertEqual("a", anti_clobber_dir_path("./a/")) with self.cd_tempdir(): self.assertEqual("a/b/c/d/e/f/g", anti_clobber_dir_path("a/b/c/d/e/f/g/")) with self.cd_tempdir(): self.assertEqual("a/b/c/d/e/f/g", anti_clobber_dir_path("a/b/c/d/e/f/g")) with self.cd_tempdir(): with open("a", "w"): pass self.assertEqual("a.d/b/c/d/e/f/g", anti_clobber_dir_path("a/b/c/d/e/f/g")) with self.cd_tempdir(): os.makedirs("a/b") with open("a/b/c", "w"): pass self.assertEqual("a/b/c.d/d/e/f/g", anti_clobber_dir_path("a/b/c/d/e/f/g")) with self.cd_tempdir(): os.makedirs("a/b") with open("a/b/c", "w"): pass self.assertEqual( os.path.abspath("a/b/c.d/d/e/f/g"), anti_clobber_dir_path(os.path.abspath("a/b/c/d/e/f/g")) ) with self.cd_tempdir(): os.makedirs("a/b/c/d/e/f") with open("a/b/c/d/e/f/g", "w"): pass self.assertEqual("a/b/c/d/e/f/g.d", anti_clobber_dir_path("a/b/c/d/e/f/g"))