Commits

Jeff Hardy  committed 2810204

Create zlib.error properly so that exceptions can be handled.

  • Participants
  • Parent commits 8b4b53f

Comments (0)

Files changed (3)

File src/Compress.cs

  * ***************************************************************************/
 
 using System;
-using System.Collections.Generic;
-using System.Text;
+using ComponentAce.Compression.Libs.ZLib;
 using IronPython.Runtime;
-using ComponentAce.Compression.Libs.ZLib;
 using IronPython.Runtime.Operations;
 
 namespace IronPython.Zlib
             }
             else if(err != Z_OK && err != Z_BUF_ERROR)
             {
-                throw new ZStreamException("deflate error");
+                throw ZlibModule.MakeError("deflate error");
             }
 
             return ZlibModule.Latin1.GetString(output, 0, (int)(zst.total_out - start_total_out));

File src/Decompress.cs

  * ***************************************************************************/
 
 using System;
-using System.Collections.Generic;
-using System.Text;
+using ComponentAce.Compression.Libs.ZLib;
 using IronPython.Runtime;
-using ComponentAce.Compression.Libs.ZLib;
 using IronPython.Runtime.Operations;
 
 namespace IronPython.Zlib

File src/ZlibModule.cs

  * ***************************************************************************/
 
 using System;
-using System.Collections.Generic;
-using System.Text;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using ComponentAce.Compression.Libs.ZLib;
 using IronPython.Runtime;
+using IronPython.Runtime.Exceptions;
+using IronPython.Runtime.Operations;
 using IronPython.Runtime.Types;
-using ComponentAce.Compression.Libs.ZLib;
-using System.Runtime.InteropServices;
 
 [assembly: PythonModule("zlib", typeof(IronPython.Zlib.ZlibModule))]
 
             int err = zst.deflateInit(level);
             if(err != Z_OK)
             {
-                throw new ZStreamException();
+                throw MakeError();
             }
 
             err = zst.deflate(FlushStrategy.Z_FINISH);
             if(err != Z_STREAM_END)
             {
                 zst.deflateEnd();
-                throw new ZStreamException();
+                throw MakeError();
             }
 
             err = zst.deflateEnd();
             if(err == Z_OK)
                 return Latin1.GetString(output, 0, (int)zst.total_out);
             else
-                throw new ZStreamException();
+                throw MakeError();
         }
 
         #endregion
             int err = zst.inflateInit(wbits);
             if(err != Z_OK)
             {
-                throw new ZStreamException();
+                throw MakeError();
             }
 
             do
                     if(err == Z_BUF_ERROR && zst.avail_out > 0)
                     {
                         zst.inflateEnd();
-                        throw new ZStreamException();
+                        throw MakeError();
                     }
                     else if(err == Z_OK || (err == Z_BUF_ERROR && zst.avail_out == 0))
                     {
                     else
                     {
                         zst.inflateEnd();
-                        throw new ZStreamException();
+                        throw MakeError();
                     }
                 }
 
             err = zst.inflateEnd();
             if(err != Z_OK)
             {
-                throw new ZStreamException();
+                throw MakeError();
             }
 
             if(outputOffset + outputBuffer.Length - zst.avail_out > output.Length)
 
         #endregion
 
-        public static readonly PythonType/*!*/ ZlibErrorType = DynamicHelpers.GetPythonTypeFromType(typeof(ZStreamException));
-        public static readonly PythonType/*!*/ error = ZlibErrorType;
+        [SpecialName]
+        public static void PerformModuleReload(PythonContext context, PythonDictionary dict)
+        {
+            error = context.EnsureModuleException("zlib.error", PythonExceptions.Exception, dict, "error", "zlib");
+        }
+
+        public static PythonType error;
+        internal static Exception MakeError(params object[] args)
+        {
+            return PythonOps.CreateThrowable(error, args);
+        }
 
         internal static System.Text.Encoding Latin1 = System.Text.Encoding.GetEncoding("iso-8859-1");
     }