<div class="gmail_quote">On Sat, Sep 19, 2009 at 2:46 AM, Pascal Chambon <span dir="ltr">&lt;<a href="mailto:chambon.pascal@gmail.com">chambon.pascal@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This reimplementation is actually necessary to get file locking, because advanced win32 operations only work on real file handles, not the handles that are underlying the C API layer. Furthermore, some interesting features (like O_EXCL | O_CREAT) are not possible with the current io implementations. So well, reimplementation required ^^<br>

</blockquote><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Concerning exceptions, which one is raised is not so important to me, as long as it&#39;s well documented and not tricky (eg. WindowsErrors are OK to me, because they subclass OSError, so most cross-platform programs wont even have to know about them).<br>
</blockquote><div><br>If you use real Windows file handles (instead of the POSIX-ish Windows API), won&#39;t you need to return WindowsErrors?<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

I had the feeling that IOErrors were for operations on file streams (opening, writing/reading, closing...), whereas OSErrors were for manipulations on filesystems (renaming, linking, stating...) and processes. <br></blockquote>
<div><br>If that were documented and a firm rule, that would certainly be great.  It&#39;s not too hard to find counterexamples in the current codebase.  Also, I&#39;m not sure how one could avoid needing to raise WindowsError in some cases.<br>
<br>Maybe someone with more knowledge of the history of IOError vs. OSError could chime in.<br><br>Python 2.6:<br><br>&gt;&gt;&gt; os.write(f.fileno(), &#39;blah&#39;)<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>
OSError: [Errno 9] Bad file descriptor<br>&gt;&gt;&gt; f.write(&#39;blah&#39;)<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>IOError: [Errno 9] Bad file descriptor<br>
</div></div><blockquote style="margin: 1.5em 0pt;">--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</blockquote>