コード例 #1
0
ファイル: keeping.py プロジェクト: colbygk/raet
    def dump(data, filepath):
        '''
        Write data as as type self.ext to filepath. json or msgpack
        '''
        if ' ' in filepath:
            raise raeting.KeepError("Invalid filepath '{0}' "
                                    "contains space".format(filepath))

        root, ext = os.path.splitext(filepath)
        if ext == '.json':
            with aiding.ocfn(filepath, "w+") as f:
                json.dump(data, f, indent=2, encoding='utf-8')
                f.flush()
                os.fsync(f.fileno())
        elif ext == '.msgpack':
            if not msgpack:
                raise raeting.KeepError("Invalid filepath ext '{0}' "
                            "needs msgpack installed".format(filepath))
            with aiding.ocfn(filepath, "w+b", binary=True) as f:
                msgpack.dump(data, f, encoding='utf-8')
                f.flush()
                os.fsync(f.fileno())
        else:
            raise raeting.KeepError("Invalid filepath ext '{0}' "
                        "not '.json' or '.msgpack'".format(filepath))
コード例 #2
0
ファイル: keeping.py プロジェクト: rogeriofalcone/raet
    def dump(data, filepath):
        '''
        Write data as as type self.ext to filepath. json or msgpack
        '''
        if ' ' in filepath:
            raise raeting.KeepError("Invalid filepath '{0}' "
                                    "contains space".format(filepath))

        with aiding.ocfn(filepath, "w+") as f:
            root, ext = os.path.splitext(filepath)
            if ext == '.json':
                json.dump(data, f, indent=2)
            elif ext == '.msgpack':
                if not msgpack:
                    raise raeting.KeepError(
                        "Invalid filepath ext '{0}' "
                        "needs msgpack installed".format(filepath))
                msgpack.dump(data, f)
            else:
                raise raeting.KeepError(
                    "Invalid filepath ext '{0}' "
                    "not '.json' or '.msgpack'".format(filepath))

            f.flush()
            os.fsync(f.fileno())
コード例 #3
0
    def dump(data, filepath):
        '''
        Write data as json to filepath
        '''
        if ' ' in filepath:
            raise raeting.KeepError("Invalid filepath '{0}' contains space")

        with aiding.ocfn(filepath, "w+") as f:
            json.dump(data, f, indent=2)
            f.flush()
            os.fsync(f.fileno())
コード例 #4
0
ファイル: keeping.py プロジェクト: bemehow/salt
    def dump(data, filepath):
        '''
        Write data as json to filepath
        '''
        if ' ' in filepath:
            raise raeting.KeepError("Invalid filepath '{0}' contains space")

        with aiding.ocfn(filepath, "w+") as f:
            json.dump(data, f, indent=2)
            f.flush()
            os.fsync(f.fileno())
コード例 #5
0
 def load(filepath):
     '''
     Return data read from filepath as converted json
     Otherwise return None
     '''
     with aiding.ocfn(filepath) as f:
         try:
             it = json.load(f, object_pairs_hook=odict)
         except EOFError:
             return None
         except ValueError:
             return None
         return it
     return None
コード例 #6
0
ファイル: keeping.py プロジェクト: bemehow/salt
 def load(filepath):
     '''
     Return data read from filepath as converted json
     Otherwise return None
     '''
     with aiding.ocfn(filepath) as f:
         try:
             it = json.load(f, object_pairs_hook=odict)
         except EOFError:
             return None
         except ValueError:
             return None
         return it
     return None
コード例 #7
0
ファイル: keeping.py プロジェクト: colbygk/raet
    def load(filepath):
        '''
        Return data read from filepath as converted json
        Otherwise return None
        '''

        try:
            root, ext = os.path.splitext(filepath)
            if ext == '.json':
                with aiding.ocfn(filepath, "r") as f:
                    it = json.load(f, object_pairs_hook=odict, encoding='utf-8')
            elif ext == '.msgpack':
                if not msgpack:
                    raise raeting.KeepError("Invalid filepath ext '{0}' "
                                "needs msgpack installed".format(filepath))
                with aiding.ocfn(filepath, "rb", binary=True) as f:
                    it = msgpack.load(f, object_pairs_hook=odict, encoding='utf-8')
            else:
                it = None
        except EOFError:
            return None
        except ValueError:
            return None
        return it
コード例 #8
0
ファイル: keeping.py プロジェクト: rogeriofalcone/raet
 def load(filepath):
     '''
     Return data read from filepath as converted json
     Otherwise return None
     '''
     with aiding.ocfn(filepath) as f:
         try:
             root, ext = os.path.splitext(filepath)
             if ext == '.json':
                 it = json.load(f, object_pairs_hook=odict)
             elif ext == '.msgpack':
                 if not msgpack:
                     raise raeting.KeepError(
                         "Invalid filepath ext '{0}' "
                         "needs msgpack installed".format(filepath))
                 it = msgpack.load(f, object_pairs_hook=odict)
             else:
                 it = None
         except EOFError:
             return None
         except ValueError:
             return None
         return it
     return None