347 return codecs.open(self.path, mode, encoding, errors, bufsize) |
347 return codecs.open(self.path, mode, encoding, errors, bufsize) |
348 |
348 |
349 else : |
349 else : |
350 return open(self.path, mode, bufsize) |
350 return open(self.path, mode, bufsize) |
351 |
351 |
|
352 def open_write (self, encoding=None, errors=None, bufsize=None) : |
|
353 """ |
|
354 Open for write using open('w'). |
|
355 """ |
|
356 |
|
357 return self.open('w', encoding, errors, bufsize) |
|
358 |
352 def copy_from (self, file) : |
359 def copy_from (self, file) : |
353 """ |
360 """ |
354 Replace this file with a copy of the given file with default permissions. |
361 Replace this file with a copy of the given file with default permissions. |
355 |
362 |
356 Raises an error if read_only mode is set. |
363 Raises an error if read_only mode is set. |
379 If the create option is given, the directory will be created if it does not exist. Note that this will |
386 If the create option is given, the directory will be created if it does not exist. Note that this will |
380 raise an error if read_only mode is set |
387 raise an error if read_only mode is set |
381 """ |
388 """ |
382 |
389 |
383 subdir = Directory(self, name=name) |
390 subdir = Directory(self, name=name) |
384 |
391 |
385 # try and mkdir? |
|
386 if create and not subdir.is_dir() : |
392 if create and not subdir.is_dir() : |
387 # create it! |
393 # create it! |
388 subdir.mkdir() |
394 subdir.mkdir() |
389 |
395 |
390 return subdir |
396 return dir |
391 |
397 |
|
398 def test_subdir (self, name, create=False) : |
|
399 """ |
|
400 Test for the presence of a subdir with the given name, and possibly return it, or None. |
|
401 |
|
402 Returns a (exists, created, dir) tuple. |
|
403 |
|
404 XXX: ugly, not used |
|
405 """ |
|
406 |
|
407 subdir = Directory(self, name=name) |
|
408 |
|
409 # already exists? |
|
410 if subdir.is_dir() : |
|
411 if create : |
|
412 # create it! |
|
413 subdir.mkdir() |
|
414 |
|
415 # didn't exist, did create |
|
416 return True, True, subdir |
|
417 |
|
418 else : |
|
419 # doesn't exist, don't create |
|
420 return False, False, subdir |
|
421 |
|
422 else : |
|
423 # already existing |
|
424 return True, False, subdir |
|
425 |
|
426 |
392 def subfile (self, name) : |
427 def subfile (self, name) : |
393 """ |
428 """ |
394 Returns a File object representing the name underneath this dir |
429 Returns a File object representing the name underneath this dir |
395 """ |
430 """ |
396 |
431 |