##// END OF EJS Templates
util: simplify file I/O functions using context managers
Bryan O'Sullivan -
r27778:4d10600c default
parent child Browse files
Show More
@@ -1445,25 +1445,16 b' def ensuredirs(name, mode=None, notindex'
1445 os.chmod(name, mode)
1445 os.chmod(name, mode)
1446
1446
1447 def readfile(path):
1447 def readfile(path):
1448 fp = open(path, 'rb')
1448 with open(path, 'rb') as fp:
1449 try:
1450 return fp.read()
1449 return fp.read()
1451 finally:
1452 fp.close()
1453
1450
1454 def writefile(path, text):
1451 def writefile(path, text):
1455 fp = open(path, 'wb')
1452 with open(path, 'wb') as fp:
1456 try:
1457 fp.write(text)
1453 fp.write(text)
1458 finally:
1459 fp.close()
1460
1454
1461 def appendfile(path, text):
1455 def appendfile(path, text):
1462 fp = open(path, 'ab')
1456 with open(path, 'ab') as fp:
1463 try:
1464 fp.write(text)
1457 fp.write(text)
1465 finally:
1466 fp.close()
1467
1458
1468 class chunkbuffer(object):
1459 class chunkbuffer(object):
1469 """Allow arbitrary sized chunks of data to be efficiently read from an
1460 """Allow arbitrary sized chunks of data to be efficiently read from an
General Comments 0
You need to be logged in to leave comments. Login now