Ticket #25 (closed defect: fixed)

Opened 10 months ago

Last modified 4 months ago

[PATCH] IOError: file() constructor not accessible in restricted mode

Reported by: jonkuhn@gmail.com Assigned to: jonkuhn
Priority: moderate Keywords:
Cc:

Description

I already posted this in the Google Group (which now I realize may not be appropriate since I noticed there is a bug tracker, so I am posting it here now).

When I try to run this code in Reinteract I get this error:

f=open('test.txt','wb')
IOError: file() constructor not accessible in restricted mode.

I am using: Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 and the latest version of Reinteract from "git clone git://git.fishsoup.net/reinteract"

Making these changes to create_builtins() (and no other changes) also fixes the issue:

    def create_builtins(self):
        # __builtins__ is a dict for a module, but a module for
__main__
        if isinstance(__builtins__, dict):
            builtins = __builtins__ #copy.copy(__builtins__)
            d = builtins
        else:
            #builtins = imp.new_module("__reinteract_builtin__")
            #builtins.__dict__.update(__builtins__.__dict__)
            builtins = __builtins__
            d = builtins.__dict__
            d['__import__'] = self.do_import

        d['help'] = _Helper()

        return builtins

I guess I am not sure what the replacement of __import__ by do_import is for, so I don't know what this might break, by only doing this replacement if __builtins__ is a module or not doing it at all. If i leave the __import__ replacement for both cases i get import errors in the console when I try to type in the Reinteract window.

Attachments

ticket25.patch (3.5 kB) - added by jonkuhn on 02/11/08 14:45:21.

Change History

02/11/08 11:28:10 changed by jonkuhn

  • owner set to jonkuhn.

02/11/08 11:31:25 changed by jonkuhn

Attached is a patch to fix this issue that I am submitting for review.

02/11/08 14:45:21 changed by jonkuhn

  • attachment ticket25.patch added.

02/26/08 01:16:20 changed by jonkuhn

  • summary changed from IOError: file() constructor not accessible in restricted mode to [PATCH] IOError: file() constructor not accessible in restricted mode.

08/10/08 20:28:51 changed by otaylor

  • status changed from new to closed.
  • resolution set to fixed.

OK, finally got to this.

I've applied your patch: http://git.fishsoup.net/cgit/reinteract/commit/?id=108f16fb483965f113a985b25c722fc19f2824fd

Then made some changes on top of it: http://git.fishsoup.net/cgit/reinteract/commit/?id=e1fc41c78be98da08c90c105cece18c1eaedb3cc

so that the self-tests past (python notebook.py to run them.)

Thanks a lot!