Example #1
0
def find_module(space, w_name, w_path=None):
    name = space.str0_w(w_name)
    if space.is_none(w_path):
        w_path = None

    find_info = importing.find_module(
        space, name, w_name, name, w_path, use_loader=False)
    if not find_info:
        raise oefmt(space.w_ImportError, "No module named %s", name)

    w_filename = space.wrap(find_info.filename)
    stream = find_info.stream

    if stream is not None:
        fileobj = W_File(space)
        fileobj.fdopenstream(
            stream, stream.try_to_find_file_descriptor(),
            find_info.filemode, w_filename)
        w_fileobj = space.wrap(fileobj)
    else:
        w_fileobj = space.w_None
    w_import_info = space.newtuple(
        [space.wrap(find_info.suffix),
         space.wrap(find_info.filemode),
         space.wrap(find_info.modtype)])
    return space.newtuple([w_fileobj, w_filename, w_import_info])
Example #2
0
def find_module(space, w_name, w_path=None):
    name = space.text0_w(w_name)
    if space.is_none(w_path):
        w_path = None

    find_info = importing.find_module(space,
                                      name,
                                      w_name,
                                      name,
                                      w_path,
                                      use_loader=False)
    if not find_info:
        raise oefmt(space.w_ImportError, "No hay módulo llamado %s", name)

    w_filename = space.newtext(find_info.filename)
    stream = find_info.stream

    if stream is not None:
        fileobj = W_File(space)
        fileobj.fdopenstream(stream, stream.try_to_find_file_descriptor(),
                             find_info.filemode, w_filename)
        w_fileobj = fileobj
    else:
        w_fileobj = space.w_None
    w_import_info = space.newtuple([
        space.newtext(find_info.suffix),
        space.newtext(find_info.filemode),
        space.newint(find_info.modtype)
    ])
    return space.newtuple([w_fileobj, w_filename, w_import_info])
Example #3
0
    def setup_class(cls):
        from pypy.module._file.interp_file import W_File

        cls.old_read = os.read

        if cls.runappdirect:
            py.test.skip("works with internals of _file impl on py.py")
        state = [0]

        def read(fd, n=None):
            if fd != 424242:
                return cls.old_read(fd, n)
            if state[0] == 0:
                state[0] += 1
                return "xyz"
            if state[0] < 3:
                state[0] += 1
                raise OSError(errno.EAGAIN, "xyz")
            return ''

        os.read = read
        stdin = W_File(cls.space)
        stdin.file_fdopen(424242, 'rb', 1)
        stdin.name = '<stdin>'
        cls.w_stream = stdin
Example #4
0
def find_module(space, w_name, w_path=None):
    name = space.str0_w(w_name)
    if space.is_w(w_path, space.w_None):
        w_path = None

    find_info = importing.find_module(space,
                                      name,
                                      w_name,
                                      name,
                                      w_path,
                                      use_loader=False)
    if not find_info:
        raise operationerrfmt(space.w_ImportError, "No module named %s", name)

    w_filename = space.wrap(find_info.filename)
    stream = find_info.stream

    if stream is not None:
        fileobj = W_File(space)
        fileobj.fdopenstream(stream, stream.try_to_find_file_descriptor(),
                             find_info.filemode, w_filename)
        w_fileobj = space.wrap(fileobj)
    else:
        w_fileobj = space.w_None
    w_import_info = space.newtuple([
        space.wrap(find_info.suffix),
        space.wrap(find_info.filemode),
        space.wrap(find_info.modtype)
    ])
    return space.newtuple([w_fileobj, w_filename, w_import_info])
Example #5
0
    def setup_class(cls):
        from pypy.module._file.interp_file import W_File

        cls.old_read = os.read

        if option.runappdirect:
            py.test.skip("works with internals of _file impl on py.py")
        import platform
        if platform.system() == 'Windows':
            # XXX This test crashes until someone implements something like
            # XXX verify_fd from
            # XXX http://hg.python.org/cpython/file/80ddbd822227/Modules/posixmodule.c#l434
            # XXX and adds it to fopen
            assert False

        state = [0]
        def read(fd, n=None):
            if fd != 42:
                return cls.old_read(fd, n)
            if state[0] == 0:
                state[0] += 1
                return "xyz"
            if state[0] < 3:
                state[0] += 1
                raise OSError(errno.EAGAIN, "xyz")
            return ''
        os.read = read
        stdin = W_File(cls.space)
        stdin.file_fdopen(42, "r", 1)
        stdin.name = '<stdin>'
        cls.w_stream = stdin
Example #6
0
    def setup_class(cls):
        from pypy.module._file.interp_file import W_File

        cls.old_read = os.read

        if cls.runappdirect:
            py.test.skip("works with internals of _file impl on py.py")
        def read(fd, n=None):
            if fd != 424242:
                return cls.old_read(fd, n)
            if cls.state == 0:
                cls.state += 1
                return "xyz"
            if cls.state < 3:
                cls.state += 1
                raise OSError(errno.EAGAIN, "xyz")
            return ''
        os.read = read
        stdin = W_File(cls.space)
        stdin.file_fdopen(424242, 'rb', 1)
        stdin.name = '<stdin>'
        cls.w_stream = stdin
Example #7
0
    def __init__(self, space):
        from pypy.module._file.interp_file import W_File
        self.space = space

        stdin = W_File(space)
        stdin.file_fdopen(0, "r", 1)
        stdin.name = '<stdin>'
        self.w_stdin = space.wrap(stdin)

        stdout = W_File(space)
        stdout.file_fdopen(1, "w", 1)
        stdout.name = '<stdout>'
        self.w_stdout = space.wrap(stdout)

        stderr = W_File(space)
        stderr.file_fdopen(2, "w", 0)
        stderr.name = '<stderr>'
        self.w_stderr = space.wrap(stderr)
Example #8
0
    def __init__(self, space):
        from pypy.module._file.interp_file import W_File
        self.space = space

        stdin = W_File(space)
        stdin.file_fdopen(0, "r", 1)
        stdin.name = '<stdin>'
        self.w_stdin = space.wrap(stdin)

        stdout = W_File(space)
        stdout.file_fdopen(1, "w", 1)
        stdout.name = '<stdout>'
        self.w_stdout = space.wrap(stdout)

        stderr = W_File(space)
        stderr.file_fdopen(2, "w", 0)
        stderr.name = '<stderr>'
        self.w_stderr = space.wrap(stderr)
Example #9
0
    def __init__(self, space):
        from pypy.module._file.interp_file import W_File
        self.space = space

        stdin = W_File(space)
        stdin.file_fdopen(0, "r", 1)
        stdin.w_name = space.wrap('<stdin>')
        self.w_stdin = space.wrap(stdin)

        stdout = W_File(space)
        stdout.file_fdopen(1, "w", 1)
        stdout.w_name = space.wrap('<stdout>')
        self.w_stdout = space.wrap(stdout)

        stderr = W_File(space)
        stderr.file_fdopen(2, "w", 0)
        stderr.w_name = space.wrap('<stderr>')
        self.w_stderr = space.wrap(stderr)

        stdin._when_reading_first_flush(stdout)
Example #10
0
    def __init__(self, space):
        from pypy.module._file.interp_file import W_File
        self.space = space

        w_stdin = W_File(space)
        w_stdin.file_fdopen(0, "r", 1)
        w_stdin.w_name = space.newtext('<stdin>')
        self.w_stdin = w_stdin

        w_stdout = W_File(space)
        w_stdout.file_fdopen(1, "w", 1)
        w_stdout.w_name = space.newtext('<stdout>')
        self.w_stdout = w_stdout

        w_stderr = W_File(space)
        w_stderr.file_fdopen(2, "w", 0)
        w_stderr.w_name = space.newtext('<stderr>')
        self.w_stderr = w_stderr

        w_stdin._when_reading_first_flush(w_stdout)
Example #11
0
    def __init__(self, space):
        from pypy.module._file.interp_file import W_File
        self.space = space

        stdin = W_File(space)
        stdin.file_fdopen(0, "r", 1)
        stdin.w_name = space.wrap('<stdin>')
        self.w_stdin = space.wrap(stdin)

        stdout = W_File(space)
        stdout.file_fdopen(1, "w", 1)
        stdout.w_name = space.wrap('<stdout>')
        self.w_stdout = space.wrap(stdout)

        stderr = W_File(space)
        stderr.file_fdopen(2, "w", 0)
        stderr.w_name = space.wrap('<stderr>')
        self.w_stderr = space.wrap(stderr)

        stdin._when_reading_first_flush(stdout)