OLD | NEW |
---|---|
1 # Copyright (C) 2009 Google Inc. All rights reserved. | 1 # Copyright (C) 2009 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 | 261 |
262 return TemporaryDirectory(fs=self, **kwargs) | 262 return TemporaryDirectory(fs=self, **kwargs) |
263 | 263 |
264 def maybe_make_directory(self, *path): | 264 def maybe_make_directory(self, *path): |
265 norm_path = self.normpath(self.join(*path)) | 265 norm_path = self.normpath(self.join(*path)) |
266 while norm_path and not self.isdir(norm_path): | 266 while norm_path and not self.isdir(norm_path): |
267 self.dirs.add(norm_path) | 267 self.dirs.add(norm_path) |
268 norm_path = self.dirname(norm_path) | 268 norm_path = self.dirname(norm_path) |
269 | 269 |
270 def move(self, source, destination): | 270 def move(self, source, destination): |
271 if self.files[source] is None: | 271 if not self.exists(source): |
272 self._raise_not_found(source) | 272 self._raise_not_found(source) |
273 self.files[destination] = self.files[source] | 273 source_is_file = self.isfile(source) |
274 self.written_files[destination] = self.files[destination] | 274 if source_is_file: |
Dirk Pranke
2014/08/27 23:46:51
nit: I don't see an advantage to the local variabl
patro
2014/09/01 09:28:25
Done.
| |
275 self.files[source] = None | 275 self.files[destination] = self.files[source] |
276 self.written_files[source] = None | 276 self.written_files[destination] = self.files[destination] |
277 self.files[source] = None | |
278 self.written_files[source] = None | |
Dirk Pranke
2014/08/27 23:46:51
nit: it would probably be slightly more idiomatic
patro
2014/09/01 09:28:25
Done.
| |
279 else: | |
280 self.copytree(source, destination) | |
281 self.rmtree(source) | |
277 | 282 |
278 def _slow_but_correct_normpath(self, path): | 283 def _slow_but_correct_normpath(self, path): |
279 return re.sub(re.escape(os.path.sep), self.sep, os.path.normpath(path)) | 284 return re.sub(re.escape(os.path.sep), self.sep, os.path.normpath(path)) |
280 | 285 |
281 def normpath(self, path): | 286 def normpath(self, path): |
282 # This function is called a lot, so we try to optimize the common cases | 287 # This function is called a lot, so we try to optimize the common cases |
283 # instead of always calling _slow_but_correct_normpath(), above. | 288 # instead of always calling _slow_but_correct_normpath(), above. |
284 if '..' in path or '/./' in path: | 289 if '..' in path or '/./' in path: |
285 # This doesn't happen very often; don't bother trying to optimize it . | 290 # This doesn't happen very often; don't bother trying to optimize it . |
286 return self._slow_but_correct_normpath(path) | 291 return self._slow_but_correct_normpath(path) |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 return self.data.readline(length) | 481 return self.data.readline(length) |
477 | 482 |
478 def __iter__(self): | 483 def __iter__(self): |
479 return self.data.__iter__() | 484 return self.data.__iter__() |
480 | 485 |
481 def next(self): | 486 def next(self): |
482 return self.data.next() | 487 return self.data.next() |
483 | 488 |
484 def seek(self, offset, whence=os.SEEK_SET): | 489 def seek(self, offset, whence=os.SEEK_SET): |
485 self.data.seek(offset, whence) | 490 self.data.seek(offset, whence) |
OLD | NEW |