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 gzip, zlib
|
||||||
import struct
|
import struct
|
||||||
import StringIO
|
import StringIO
|
||||||
|
import os
|
||||||
|
|
||||||
# decorator to handle filename or object as first parameter
|
# decorator to handle filename or object as first parameter
|
||||||
def _file_loader(func):
|
def _file_loader(func):
|
||||||
def wrapper(fileobj, *args):
|
def wrapper(fileobj, *args):
|
||||||
if isinstance(fileobj, basestring):
|
if isinstance(fileobj, basestring):
|
||||||
|
if not os.path.isfile(fileobj):
|
||||||
|
return None
|
||||||
|
|
||||||
# Is actually a filename
|
# Is actually a filename
|
||||||
fileobj = open(fileobj, 'rb')
|
fileobj = open(fileobj, 'rb')
|
||||||
return func(fileobj, *args)
|
return func(fileobj, *args)
|
||||||
|
|||||||
Reference in New Issue
Block a user