示例#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))
示例#2
0
文件: bon.py 项目: 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))
示例#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
示例#4
0
文件: binon.py 项目: Eirikur/lever
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
示例#5
0
文件: binon.py 项目: cheery/lever
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
示例#6
0
文件: api.py 项目: pombredanne/lever
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
示例#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)
示例#8
0
文件: api.py 项目: 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)
示例#9
0
文件: json.py 项目: Eirikur/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
示例#10
0
文件: json.py 项目: 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
示例#11
0
 def getcache(self, m_path):
     s = pathobj.stringify(m_path)
     try:
         return self.cache[s]
     except KeyError as k:
         return None
示例#12
0
 def setcache(self, m_path, module, mtime):
     m = ModuleCache(m_path, module, mtime)
     self.cache[pathobj.stringify(m_path)] = m
     return m
示例#13
0
 def getcache(self, m_path):
     s = pathobj.stringify(m_path)
     try:
         return self.cache[s]
     except KeyError as k:
         return None
示例#14
0
 def setcache(self, m_path, module, mtime):
     m = ModuleCache(m_path, module, mtime)
     self.cache[pathobj.stringify(m_path)] = m
     return m