• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python streamio.open_file_as_stream函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.rlib.streamio.open_file_as_stream函数的典型用法代码示例。如果您正苦于以下问题:Python open_file_as_stream函数的具体用法?Python open_file_as_stream怎么用?Python open_file_as_stream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了open_file_as_stream函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_write_compiled_module

    def test_write_compiled_module(self):
        space = self.space
        pathname = _testfilesource()
        os.chmod(pathname, 0777)
        stream = streamio.open_file_as_stream(pathname, "r")
        try:
            w_ret = importing.parse_source_module(space,
                                                  pathname,
                                                  stream.readall())
        finally:
            stream.close()
        pycode = space.interpclass_w(w_ret)
        assert type(pycode) is pypy.interpreter.pycode.PyCode

        cpathname = str(udir.join('cpathname.pyc'))
        mode = 0777
        mtime = 12345
        importing.write_compiled_module(space,
                                        pycode,
                                        cpathname,
                                        mode,
                                        mtime)

        # check
        ret = importing.check_compiled_module(space,
                                              cpathname,
                                              mtime)
        assert ret is not None
        ret.close()

        # Check that the executable bit was removed
        assert os.stat(cpathname).st_mode & 0111 == 0

        # read compiled module
        stream = streamio.open_file_as_stream(cpathname, "rb")
        try:
            stream.seek(8, 0)
            w_code = importing.read_compiled_module(space, cpathname,
                                                    stream.readall())
            pycode = space.interpclass_w(w_code)
        finally:
            stream.close()

        # check value of load
        w_dic = space.newdict()
        pycode.exec_code(space, w_dic, w_dic)
        w_ret = space.getitem(w_dic, space.wrap('x'))
        ret = space.int_w(w_ret)
        assert ret == 42
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:49,代码来源:test_import.py


示例2: direct___init__

 def direct___init__(self, w_name, mode='r', buffering=-1):
     name = self.space.str_w(w_name)
     self.direct_close()
     self.check_mode_ok(mode)
     stream = streamio.open_file_as_stream(name, mode, buffering)
     fd = stream.try_to_find_file_descriptor()
     self.fdopenstream(stream, fd, mode, w_name)
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:interp_file.py


示例3: test_load_compiled_module

 def test_load_compiled_module(self):
     space = self.space
     pathname = "whatever"
     mtime = 12345
     co = compile('x = 42', '?', 'exec')
     cpathname = _testfile(importing.get_pyc_magic(space), mtime, co)
     w_modulename = space.wrap('somemodule')
     stream = streamio.open_file_as_stream(cpathname, "r")
     try:
         w_mod = space.wrap(Module(space, w_modulename))
         magic = importing._r_long(stream)
         timestamp = importing._r_long(stream)
         w_ret = importing.load_compiled_module(space,
                                                w_modulename,
                                                w_mod,
                                                cpathname,
                                                magic,
                                                timestamp,
                                                stream.readall())
     finally:
         stream.close()
     assert w_mod is w_ret
     w_ret = space.getattr(w_mod, space.wrap('x'))
     ret = space.int_w(w_ret)
     assert ret == 42
开发者ID:antoine1fr,项目名称:pygirl,代码行数:25,代码来源:test_import.py


示例4: entry_point

def entry_point(argv):
    if len(argv) == 2:
        code = open_file_as_stream(argv[1]).readall()
        try:
            t = parse(code)
        except BacktrackException:
            #(line, col) = e.error.get_line_column(code)
            #expected = " ".join(e.error.expected)
            print "parse error"
            return 1

        #this should not be necessary here
        assert isinstance(t, list)
        ctx = ExecutionContext()
        try:
            for sexpr in t:
                try:
                    w_retval = sexpr.eval(ctx)
                    print w_retval.to_string()
                except ContinuationReturn, e:
                    print e.result.to_string()

        except SchemeQuit, e:
            return 0

        return 0
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:26,代码来源:targetscheme.py


示例5: load

 def load(self, cartridge_path):
     cartridge_path               = str(cartridge_path)
     self.cartridge_file_path     = cartridge_path
     self.cartridge_stream        = open_file_as_stream(cartridge_path)
     self.cartridge_file_contents = map_to_byte(
                                             self.cartridge_stream.readall())
     self.load_battery(cartridge_path)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:cartridge.py


示例6: test_pyc_magic_changes

 def test_pyc_magic_changes(self):
     # test that the pyc files produced by a space are not reimportable
     # from another, if they differ in what opcodes they support
     allspaces = [self.space]
     for opcodename in self.space.config.objspace.opcodes.getpaths():
         key = 'objspace.opcodes.' + opcodename
         space2 = gettestobjspace(**{key: True})
         allspaces.append(space2)
     for space1 in allspaces:
         for space2 in allspaces:
             if space1 is space2:
                 continue
             pathname = "whatever"
             mtime = 12345
             co = compile('x = 42', '?', 'exec')
             cpathname = _testfile(importing.get_pyc_magic(space1),
                                   mtime, co)
             w_modulename = space2.wrap('somemodule')
             stream = streamio.open_file_as_stream(cpathname, "rb")
             try:
                 w_mod = space2.wrap(Module(space2, w_modulename))
                 magic = importing._r_long(stream)
                 timestamp = importing._r_long(stream)
                 space2.raises_w(space2.w_ImportError,
                                 importing.load_compiled_module,
                                 space2,
                                 w_modulename,
                                 w_mod,
                                 cpathname,
                                 magic,
                                 timestamp,
                                 stream.readall())
             finally:
                 stream.close()
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:34,代码来源:test_import.py


示例7: load_bytecode

def load_bytecode(filename):
    from pypy.rlib.streamio import open_file_as_stream

    f = open_file_as_stream(filename)
    bytecode = f.readall()
    f.close()
    return bytecode
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:7,代码来源:targettlr.py


示例8: check_compiled_module

def check_compiled_module(space, pathname, mtime, cpathname):
    """
    Given a pathname for a Python source file, its time of last
    modification, and a pathname for a compiled file, check whether the
    compiled file represents the same version of the source.  If so,
    return a FILE pointer for the compiled file, positioned just after
    the header; if not, return NULL.
    Doesn't set an exception.
    """
    w_marshal = space.getbuiltinmodule('marshal')
    stream = streamio.open_file_as_stream(cpathname, "rb")
    magic = _r_long(stream)
    try:
        if magic != get_pyc_magic(space):
            # XXX what to do about Py_VerboseFlag ?
            # PySys_WriteStderr("# %s has bad magic\n", cpathname);
            return -1
        pyc_mtime = _r_long(stream)
        if pyc_mtime != mtime:
            # PySys_WriteStderr("# %s has bad mtime\n", cpathname);
            return 0
        # if (Py_VerboseFlag)
           # PySys_WriteStderr("# %s matches %s\n", cpathname, pathname);
    finally:
        stream.close()
    return 1
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:26,代码来源:importing.py


示例9: run_file

def run_file(filename):
    fp = open_file_as_stream(filename)
    source = fp.readall()
    toplevel_env = get_report_env()
    try:
        exprs_w = parse_string(source)
    except BacktrackException as e:
        print e.error.nice_error_message('<file %s>' % filename, source)
        return 1
    try:
        nodelist = Builder(exprs_w).getast()
    except OperationError as e:
        print e.unwrap().to_string()
        return 1
    cpsform = Rewriter(nodelist, toplevel=True).run()
    try:
        w_maincont, proto_w = compile_all(cpsform, toplevel_env)
    except OperationError as e:
        print e.unwrap().to_string()
        return 1
    #print 'ast:', map(lambda o: o.to_string(), nodelist)
    #print cpsform.to_string()
    #print w_maincont, 'dis:'
    #print dis_proto(w_maincont.w_proto)
    #for w_proto in proto_w:
    #    print w_proto, 'dis:'
    #    print dis_proto(w_proto)
    #return 0
    frame = Frame(w_maincont, proto_w)
    frame.run()
    return 0
开发者ID:overminder,项目名称:jitplay,代码行数:31,代码来源:targetinterp.py


示例10: compile_file

def compile_file(filename, outfname):
    """maybe rpython..."""
    w_skel = compile_list_of_expr(filename_to_expr_list(filename))

    outf = open_file_as_stream(outfname, 'w')
    chunkio.dump(w_skel, outf)
    outf.close()
开发者ID:hellcoderz,项目名称:sanya,代码行数:7,代码来源:targetscheme.py


示例11: find_module

def find_module(space, modulename, w_modulename, partname, w_path,
                use_loader=True):
    # Examin importhooks (PEP302) before doing the import
    if use_loader:
        w_loader  = find_in_meta_path(space, w_modulename, w_path)
        if w_loader:
            return FindInfo.fromLoader(w_loader)

    # XXX Check for frozen modules?
    #     when w_path is a string

    if w_path is None:
        # check the builtin modules
        if modulename in space.builtin_modules:
            return FindInfo(C_BUILTIN, modulename, None)
        w_path = space.sys.get('path')

    # XXX check frozen modules?
    #     when w_path is null

    if w_path is not None:
        for w_pathitem in space.unpackiterable(w_path):
            # sys.path_hooks import hook
            if use_loader:
                w_loader = find_in_path_hooks(space, w_modulename, w_pathitem)
                if w_loader:
                    return FindInfo.fromLoader(w_loader)

            path = space.str_w(w_pathitem)
            filepart = os.path.join(path, partname)
            if os.path.isdir(filepart) and case_ok(filepart):
                initfile = os.path.join(filepart, '__init__')
                modtype, _, _ = find_modtype(space, initfile)
                if modtype in (PY_SOURCE, PY_COMPILED):
                    return FindInfo(PKG_DIRECTORY, filepart, None)
                else:
                    msg = "Not importing directory " +\
                            "'%s' missing __init__.py" % (filepart,)
                    space.warn(msg, space.w_ImportWarning)
            modtype, suffix, filemode = find_modtype(space, filepart)
            try:
                if modtype in (PY_SOURCE, PY_COMPILED):
                    assert suffix is not None
                    filename = filepart + suffix
                    stream = streamio.open_file_as_stream(filename, filemode)
                    try:
                        return FindInfo(modtype, filename, stream, suffix, filemode)
                    except:
                        stream.close()
                        raise
                if modtype == C_EXTENSION:
                    filename = filepart + suffix
                    return FindInfo(modtype, filename, None, suffix, filemode)
            except StreamErrors:
                pass   # XXX! must not eat all exceptions, e.g.
                       # Out of file descriptors.

    # not found
    return None
开发者ID:ieure,项目名称:pypy,代码行数:59,代码来源:importing.py


示例12: load_compiled_chunk

def load_compiled_chunk(filename):
    vm = VM()
    open_lib(vm)
    stream = open_file_as_stream(filename, 'r')
    w_skel = chunkio.load(stream)
    stream.close()
    vm.bootstrap(w_skel)
    vm.run()
开发者ID:hellcoderz,项目名称:sanya,代码行数:8,代码来源:targetscheme.py


示例13: main

def main(argv):
    if not len(argv) == 2:
        print __doc__
        return 1
    f = open_file_as_stream(argv[1])
    data = f.readall()
    f.close()
    interpret(data)
    return 0
开发者ID:Julian,项目名称:Ripe,代码行数:9,代码来源:targetripe.py


示例14: get_file

def get_file(space, w_file, filename, filemode):
    if w_file is None or space.is_w(w_file, space.w_None):
        try:
            return streamio.open_file_as_stream(filename, filemode)
        except StreamErrors, e:
            # XXX this is not quite the correct place, but it will do for now.
            # XXX see the issue which I'm sure exists already but whose number
            # XXX I cannot find any more...
            raise wrap_streamerror(space, e)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:interp_imp.py


示例15: load

 def load(self, cartridge_path):
     if cartridge_path is None:
         raise Exception("cartridge_path cannot be None!")
     cartridge_path = str(cartridge_path)
     self.cartridge_file_path = cartridge_path
     self.cartridge_stream = open_file_as_stream(cartridge_path)
     self.cartridge_file_contents = map_to_byte( \
                                             self.cartridge_stream.readall())
     self.load_battery(cartridge_path)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:cartridge.py


示例16: test_write_compiled_module

    def test_write_compiled_module(self):
        space = self.space
        pathname = _testfilesource()
        stream = streamio.open_file_as_stream(pathname, "r")
        try:
            w_ret = importing.parse_source_module(space,
                                                  pathname,
                                                  stream.readall())
        finally:
            stream.close()
        pycode = space.interpclass_w(w_ret)
        assert type(pycode) is pypy.interpreter.pycode.PyCode

        cpathname = str(udir.join('cpathname.pyc'))
        mtime = 12345
        importing.write_compiled_module(space,
                                        pycode,
                                        cpathname,
                                        mtime)

        # check
        pathname = str(udir.join('cpathname.py'))
        ret = importing.check_compiled_module(space,
                                              pathname,
                                              mtime,
                                              cpathname)
        assert ret == 1

        # read compile module
        stream = streamio.open_file_as_stream(cpathname, "r")
        try:
            stream.seek(8, 0)
            w_code = importing.read_compiled_module(space, cpathname,
                                                    stream.readall())
            pycode = space.interpclass_w(w_code)
        finally:
            stream.close()

        # check value of load
        w_dic = space.newdict()
        pycode.exec_code(space, w_dic, w_dic)
        w_ret = space.getitem(w_dic, space.wrap('x'))
        ret = space.int_w(w_ret)
        assert ret == 42
开发者ID:antoine1fr,项目名称:pygirl,代码行数:44,代码来源:test_import.py


示例17: main

def main(fname, argv):
    f = open_file_as_stream(fname, "r")
    input = f.readall()
    f.close()
    code = compile(input)
    mainframe = Frame(code)
    for i in range(len(argv)):
        mainframe.registers[i] = Int(int(argv[i]))
    res = mainframe.interpret()
    print "Result:", res.repr()
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:tinyframe.py


示例18: parse

def parse(code):
    GFILE = open_file_as_stream(abspath(join(dirname(__file__), "grammar.txt")))

    t = None
    try:
        t = GFILE.read()
        regexs, rules, ToAST = parse_ebnf(t)
    except ParseError,e:
        print e.nice_error_message(filename=str(GFILE),source=t)
        raise
开发者ID:heynemann,项目名称:aquesta,代码行数:10,代码来源:aquesta.py


示例19: __init__

	def __init__( self, program=None, filename=None, argv=[] ):
		self.program = program
		if filename:
			f = open_file_as_stream(filename)
			self.program = f.readall()
			f.close()

		self.space = Space2D( self.program )
		self.stacks = StackStack()
		self.argv = argv
开发者ID:terrence2,项目名称:befunge2010,代码行数:10,代码来源:Interpreter.py


示例20: entry_point

def entry_point(argv):
    if len(argv) < 2:
        print __doc__
        os._exit(1)
    args = argv[2:]
    stream = open_file_as_stream(argv[1])
    co = serializer.deserialize(stream.readall())
    w_args = [unwrap_arg(args[i]) for i in range(len(args))]
    execution.run(co, w_args)
    return 0
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:targetspli.py



注:本文中的pypy.rlib.streamio.open_file_as_stream函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unroll.unrolling_iterable函数代码示例发布时间:2022-05-27
下一篇:
Python rstring.UnicodeBuilder类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap