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))
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
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
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
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
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)
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)
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
def getcache(self, m_path): s = pathobj.stringify(m_path) try: return self.cache[s] except KeyError as k: return None
def setcache(self, m_path, module, mtime): m = ModuleCache(m_path, module, mtime) self.cache[pathobj.stringify(m_path)] = m return m