code: def __getFileObj(self, f):
          
          if not f:
              raise ShapefileException("No file-like object available.")
          elif hasattr(f, "write"):
              return f
          else:
              pth = os.path.split(f)[0]
              if pth and not os.path.exists(pth):
                  os.makedirs(pth)
              return open(f, "wb+")
docs: Safety handler to verify file-like objects