0

Check if file exists before opening it

This commit is contained in:
cbarber
2011-02-26 21:41:59 -05:00
committed by Andrew Chin
parent a690ebbce5
commit 1a57f53a39

4
nbt.py
View File

@@ -16,11 +16,15 @@
import gzip, zlib
import struct
import StringIO
import os
# decorator to handle filename or object as first parameter
def _file_loader(func):
def wrapper(fileobj, *args):
if isinstance(fileobj, basestring):
if not os.path.isfile(fileobj):
return None
# Is actually a filename
fileobj = open(fileobj, 'rb')
return func(fileobj, *args)