comparison piecrust/sources/fs.py @ 933:7e7fc7926307

sources: File-system sources accept all `open` arguments.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 04 Oct 2017 09:11:17 -0700
parents d9059257743c
children 84fc72a17f7a
comparison
equal deleted inserted replaced
932:0eca08213354 933:7e7fc7926307
46 return False 46 return False
47 raise InvalidFileSystemEndpointError(self.name, 47 raise InvalidFileSystemEndpointError(self.name,
48 self.fs_endpoint_path) 48 self.fs_endpoint_path)
49 return True 49 return True
50 50
51 def openItem(self, item, mode='r', encoding=None): 51 def openItem(self, item, mode='r', **kwargs):
52 for m in 'wxa+': 52 for m in 'wxa+':
53 if m in mode: 53 if m in mode:
54 # If opening the file for writing, let's make sure the 54 # If opening the file for writing, let's make sure the
55 # directory exists. 55 # directory exists.
56 dirname = os.path.dirname(item.spec) 56 dirname = os.path.dirname(item.spec)
57 if not os.path.exists(dirname): 57 if not os.path.exists(dirname):
58 os.makedirs(dirname, 0o755) 58 os.makedirs(dirname, 0o755)
59 break 59 break
60 return open(item.spec, mode, encoding=encoding) 60 return open(item.spec, mode, **kwargs)
61 61
62 def getItemMtime(self, item): 62 def getItemMtime(self, item):
63 return os.path.getmtime(item.spec) 63 return os.path.getmtime(item.spec)
64 64
65 def describe(self): 65 def describe(self):