Example #1
0
def open_file(pathname):
    name = pathobj.os_stringify(pathname).encode('utf-8')
    try:
        fd = rfile.create_file(name, 'rb')
        try:
            return load(fd)
        finally:
            fd.close()
    except IOError as error:
        message = os.strerror(error.errno).decode('utf-8')
        raise OldError(u"%s: %s" % (pathobj.stringify(pathname), message))
Example #2
0
File: bon.py Project: cheery/lever
def open_file(pathname):
    name = pathobj.os_stringify(pathname).encode('utf-8')
    try:
        fd = rfile.create_file(name, 'rb')
        try:
            return load(fd)
        finally:
            fd.close()
    except IOError as error:
        message = os.strerror(error.errno).decode('utf-8')
        raise OldError(u"%s: %s" % (pathobj.stringify(pathname), message))
Example #3
0
def open_api(json_path, dependencies, decorator):
    path = get_header(json_path)
    try:
        apispec = json.read_file([path])
    except OSError as error:
        raise OldError(u"[Errno %d]: %s\n" %
                       (error.errno, pathobj.stringify(path)))
    api = Api(apispec.getitem(String(u"constants")),
              apispec.getitem(String(u"types")),
              apispec.getitem(String(u"variables")), dependencies, decorator)
    return api
Example #4
0
def write_file(pathname, data):
    name = pathobj.os_stringify(pathname).encode('utf-8')
    try:
        fd = rfile.create_file(name, "wb")
        try:
            dump(fd, data)
        finally:
            fd.close()
    except IOError as error:
        message = os.strerror(error.errno).decode('utf-8')
        raise OldError(u"%s: %s" % (pathobj.stringify(pathname), message))
    return null
Example #5
0
def write_file(pathname, data):
    name = pathobj.os_stringify(pathname).encode("utf-8")
    try:
        fd = rfile.create_file(name, "wb")
        try:
            dump(fd, data)
        finally:
            fd.close()
    except IOError as error:
        message = os.strerror(error.errno).decode("utf-8")
        raise OldError(u"%s: %s" % (pathobj.stringify(pathname), message))
    return null
Example #6
0
def open_api(json_path, dependencies, decorator):
    path = get_header(json_path)
    try:
        apispec = json.read_file([path])
    except OSError as error:
        raise OldError(u"[Errno %d]: %s\n" % (error.errno, pathobj.stringify(path)))
    api = Api(
        apispec.getitem(String(u"constants")),
        apispec.getitem(String(u"types")),
        apispec.getitem(String(u"variables")),
        dependencies,
        decorator)
    return api
Example #7
0
def read_file(path, dependencies, decorator):
    basename = path.getattr(u"basename")
    if isinstance(basename, String):
        if not basename.string.endswith(u".json"):
            dirname = path.getattr(u"dirname")
            path = pathobj.concat(dirname,
                pathobj.parse(basename.string + u".json"))
    path = pathobj.concat(conf.headers_dir, path)
    try:
        apispec = json.read_file(path)
    except OSError as error:
        raise OldError(u"[Errno %d]: %s\n" % (error.errno, pathobj.stringify(path)))
    return read_object(apispec, dependencies, decorator)
Example #8
0
File: api.py Project: cheery/lever
def read_file(path, dependencies, decorator):
    basename = path.getattr(u"basename")
    if isinstance(basename, String):
        if not basename.string.endswith(u".json"):
            path.setattr(
                u"basename",
                String(basename.string + u".json"))
    path = pathobj.concat(conf.headers_dir, path)
    try:
        apispec = json.read_file(path)
    except OSError as error:
        raise OldError(u"[Errno %d]: %s\n" % (error.errno, pathobj.stringify(path)))
    return read_object(apispec, dependencies, decorator)
Example #9
0
def write_file(pathname, obj, config):
    name = pathobj.os_stringify(pathname).encode('utf-8')
    try:
        fd = rfile.create_file(name, "wb")
        try:
            # TODO: sort of defeats the purpose of
            # incremental encoder.
            fd.write(configured_stringify(obj, config).encode('utf-8'))
            fd.write('\n')
        finally:
            fd.close()
    except IOError as error:
        message = os.strerror(error.errno).decode('utf-8')
        raise OldError(u"%s: %s" % (pathobj.stringify(pathname), message))
    return null
Example #10
0
File: json.py Project: cheery/lever
def write_file(pathname, obj, config):
    name = pathobj.os_stringify(pathname).encode('utf-8')
    try:
        fd = rfile.create_file(name, "wb")
        try:
            # TODO: sort of defeats the purpose of
            # incremental encoder.
            fd.write(configured_stringify(obj, config).encode('utf-8'))
            fd.write('\n')
        finally:
            fd.close()
    except IOError as error:
        message = os.strerror(error.errno).decode('utf-8')
        raise OldError(u"%s: %s" % (pathobj.stringify(pathname), message))
    return null
Example #11
0
 def getcache(self, m_path):
     s = pathobj.stringify(m_path)
     try:
         return self.cache[s]
     except KeyError as k:
         return None
Example #12
0
 def setcache(self, m_path, module, mtime):
     m = ModuleCache(m_path, module, mtime)
     self.cache[pathobj.stringify(m_path)] = m
     return m
Example #13
0
 def getcache(self, m_path):
     s = pathobj.stringify(m_path)
     try:
         return self.cache[s]
     except KeyError as k:
         return None
Example #14
0
 def setcache(self, m_path, module, mtime):
     m = ModuleCache(m_path, module, mtime)
     self.cache[pathobj.stringify(m_path)] = m
     return m