"""Simple persistence helpers

"""

import cPickle as pickle


def loadOrCreate(factory, picklePath):
   """Try to load an object from the pickle otherwise create and persist it.
   
   """

   result = None
   pickleFile = None
   try:
      try:
         pickleFile = open(picklePath, "r")
         result = pickle.load(pickleFile)
      except:
         result = factory()

         pickleFile = open(picklePath, "w")
         pickle.dump(result, pickleFile, True)
   finally:
      pickleFile and pickleFile.close()
   
   return result
   
2480c2be617c6ce28a4386da4f1847a9ed5f8f70
<mask token>

<mask token>


def loadOrCreate(factory, picklePath):
    """Try to load an object from the pickle otherwise create and persist it.
   
   """
    result = None
    pickleFile = None
    try:
        try:
            pickleFile = open(picklePath, 'r')
            result = pickle.load(pickleFile)
        except:
            result = factory()
            pickleFile = open(picklePath, 'w')
            pickle.dump(result, pickleFile, True)
    finally:
        pickleFile and pickleFile.close()
    return result

<mask token>
import cPickle as pickle


def loadOrCreate(factory, picklePath):
    """Try to load an object from the pickle otherwise create and persist it.
   
   """
    result = None
    pickleFile = None
    try:
        try:
            pickleFile = open(picklePath, 'r')
            result = pickle.load(pickleFile)
        except:
            result = factory()
            pickleFile = open(picklePath, 'w')
            pickle.dump(result, pickleFile, True)
    finally:
        pickleFile and pickleFile.close()
    return result

"""Simple persistence helpers

"""

import cPickle as pickle


def loadOrCreate(factory, picklePath):
   """Try to load an object from the pickle otherwise create and persist it.
   
   """

   result = None
   pickleFile = None
   try:
      try:
         pickleFile = open(picklePath, "r")
         result = pickle.load(pickleFile)
      except:
         result = factory()

         pickleFile = open(picklePath, "w")
         pickle.dump(result, pickleFile, True)
   finally:
      pickleFile and pickleFile.close()
   
   return result
   