Check if file exists before opening it
This commit is contained in:
4
nbt.py
4
nbt.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user