Пример #1
0
    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
    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
    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
 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
    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
 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