This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ammon_riley
Recipients ammon_riley, pitrou, tarek, tseaver, vstinner
Date 2010-05-05.19:34:48
SpamBayes Score 0.00075343554
Marked as misclassified No
Message-id <1273088090.42.0.399430807086.issue4265@psf.upfronthosting.co.za>
In-reply-to
Content
You can replace the built-in open(), with one of your own devising:

    >>> import shutil
    >>> def open(*a, **k):
    ...   raise IOError("faked error.")
    ...
    >>> __builtins__.open = open
    >>> shutil.copyfile("snake", "egg")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.6/shutil.py", line 52 in copyfile
        fsrc = open(src, 'rb')
    File "<stdin>", line 2, in open
    IOError: faked error.

Note that your open() replacement will need a bit of smarts, 
since it needs to succeed for some open() calls, and fail for
others, so you'll want to stash the original __builtins__.open()
for future use.
History
Date User Action Args
2010-05-05 19:34:50ammon_rileysetrecipients: + ammon_riley, tseaver, pitrou, vstinner, tarek
2010-05-05 19:34:50ammon_rileysetmessageid: <1273088090.42.0.399430807086.issue4265@psf.upfronthosting.co.za>
2010-05-05 19:34:48ammon_rileylinkissue4265 messages
2010-05-05 19:34:48ammon_rileycreate