コード例 #1
0
ファイル: cacher.py プロジェクト: dalejung/trtools
 def load(self):
     try:
         print(('Loading %s' % self.filepath))
         with open(self.filepath) as f:
             self.cache = pickle.load(f)
     except IOError:
         print('Cache file does not exist')
コード例 #2
0
ファイル: filecache.py プロジェクト: dalejung/trtools
    def __init__(self, *args, **kwargs):
        """
        Parameters:
            leveled : bool / int
                Determines the folder hierarchy. False will create a flat hierarchy. Otherwise this value
                determines the depth. We are assuming the key is iterable which will determine the
                level values.

        Example:
            a key of ('HI', 1, 3) and leveled = 2 would create a file
            /cache_dir/HI/1/HI_1_3
            Assuming that HI_1_3 is the filename
        """
        super(MetaFileCache, self).__init__(*args, **kwargs)

        self.autosave = kwargs.pop('autosave', True)
        self.leveled = kwargs.pop('leveled', False)
        self._keys = {} # key -> filename

        self.keys_fn = self.get_filename('index', leveled=False)
        try:
            with open(self.keys_fn, 'rb') as f:
                keys = pickle.load(f)
                self._keys = keys
        except:
            pass
コード例 #3
0
 def load(self):
     try:
         print(('Loading %s' % self.filepath))
         with open(self.filepath) as f:
             self.cache = pickle.load(f)
     except IOError:
         print('Cache file does not exist')
コード例 #4
0
ファイル: filecache.py プロジェクト: femtotrader/trtools
    def __init__(self, *args, **kwargs):
        """
        Parameters:
            leveled : bool / int
                Determines the folder hierarchy. False will create a flat hierarchy. Otherwise this value
                determines the depth. We are assuming the key is iterable which will determine the
                level values.

        Example:
            a key of ('HI', 1, 3) and leveled = 2 would create a file
            /cache_dir/HI/1/HI_1_3
            Assuming that HI_1_3 is the filename
        """
        super(MetaFileCache, self).__init__(*args, **kwargs)

        self.autosave = kwargs.pop('autosave', True)
        self.leveled = kwargs.pop('leveled', False)
        self._keys = {}  # key -> filename

        self.keys_fn = self.get_filename('index', leveled=False)
        try:
            with open(self.keys_fn, 'rb') as f:
                keys = pickle.load(f)
                self._keys = keys
        except:
            pass
コード例 #5
0
ファイル: io.py プロジェクト: femtotrader/trtools
def load(path_or_buffer):
    if isinstance(path_or_buffer, str):
        f = open(str, 'rb')
    else:
        f = path_or_buffer

    try:
        return pickle.load(f)
    finally: 
        f.close()
コード例 #6
0
ファイル: pytables.py プロジェクト: dalejung/trtools
def _meta_dir(obj, meta=None):
    filepath = _meta_path(obj)
    if meta:
        with open(filepath, 'wb') as f:
            pickle.dump(meta, f)
        return

    try:
        with open(filepath, 'rb') as f:
            meta = pickle.load(f)
        return meta
    except:
        return {}
コード例 #7
0
ファイル: bundle.py プロジェクト: femtotrader/trtools
def _load_meta(name, path):
    with open(os.path.join(path, name), 'rb') as f:
        obj = pickle.load(f)
    return obj
コード例 #8
0
ファイル: caching_dict.py プロジェクト: dalejung/trtools
 def load(self):
     try:
         obj = pickle.load(self.get_fp())
         self._dict = obj
     except:
         pass
コード例 #9
0
 def load(self):
     try:
         obj = pickle.load(self.get_fp())
         self._dict = obj
     except:
         pass
コード例 #10
0
ファイル: bundle.py プロジェクト: dalejung/trtools
def _load_meta(name, path):
    with open(os.path.join(path, name), 'rb') as f:
        obj = pickle.load(f)
    return obj