Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.

Commit 0a1bd74

Browse files
author
Barton Cline
committed
PYTHON27 option added and readability of the Exceptions class improvements as we look toward version 2.7 ...
1 parent e31c32c commit 0a1bd74

1 file changed

Lines changed: 67 additions & 38 deletions

File tree

pythonnet/src/runtime/exceptions.cs

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class ExceptionClassObject : ClassObject {
3131
internal ExceptionClassObject(Type tp) : base(tp) {
3232
}
3333

34-
#if (PYTHON25 || PYTHON26)
34+
#if (PYTHON25 || PYTHON26 || PYTHON27)
3535
internal static Exception ToException(IntPtr ob) {
3636
CLRObject co = GetManagedObject(ob) as CLRObject;
3737
if (co == null) {
@@ -114,24 +114,27 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
114114

115115
return Runtime.PyObject_GenericGetAttr(ob, key);
116116
}
117-
#endif
117+
#endif // (PYTHON25 || PYTHON26 || PYTHON27)
118118
}
119119

120120
/// <summary>
121121
/// Encapsulates the Python exception APIs.
122122
/// </summary>
123+
/// <remarks>
124+
/// Readability of the Exceptions class improvements as we look toward version 2.7 ...
125+
/// </remarks>
123126

124127
public class Exceptions {
125128

129+
internal static IntPtr warnings_module;
130+
internal static IntPtr exceptions_module;
131+
126132
private Exceptions() {}
127133

128134
//===================================================================
129135
// Initialization performed on startup of the Python runtime.
130136
//===================================================================
131137

132-
internal static IntPtr warnings_module;
133-
internal static IntPtr exceptions_module;
134-
135138
internal static void Initialize() {
136139
exceptions_module = Runtime.PyImport_ImportModule("exceptions");
137140
Exceptions.ErrorCheck(exceptions_module);
@@ -200,10 +203,20 @@ internal unsafe static void ErrorOccurredCheck(IntPtr pointer) {
200203
// this-at-home hackery) delegates to the managed exception and
201204
// obeys the conventions of both Python and managed exceptions.
202205

206+
/// <remarks>
207+
/// Conditionally initialized variables!
208+
/// </remarks>
203209
static IntPtr ns_exc; // new-style class for System.Exception
204210
static IntPtr os_exc; // old-style class for System.Exception
205211
static Hashtable cache;
206212

213+
/// <remarks>
214+
/// the lines
215+
/// // XXX - hack to raise a compatible old-style exception ;(
216+
/// if (Runtime.wrap_exceptions) {
217+
/// CallOneOfTheseMethods();
218+
///
219+
/// </remarks>
207220
internal static void SetupExceptionHack() {
208221
ns_exc = ClassManager.GetClass(typeof(Exception)).pyHandle;
209222
cache = new Hashtable();
@@ -546,63 +559,79 @@ internal static IntPtr RaiseTypeError(string message) {
546559
return IntPtr.Zero;
547560
}
548561

549-
550-
public static IntPtr ArithmeticError;
551-
public static IntPtr AssertionError;
552-
public static IntPtr AttributeError;
553-
#if (PYTHON25 || PYTHON26)
562+
// 2010-11-16: Arranged in python (2.6 & 2.7) source header file order
563+
/* Predefined exceptions are
564+
puplic static variables on the Exceptions class filled in from
565+
the python class using reflection in Initialize() looked up by
566+
name, not posistion. */
567+
#if (PYTHON25 || PYTHON26 || PYTHON27)
554568
public static IntPtr BaseException;
555569
#endif
556-
public static IntPtr DeprecationWarning;
557-
public static IntPtr EOFError;
558-
public static IntPtr EnvironmentError;
559570
public static IntPtr Exception;
560-
public static IntPtr FloatingPointError;
561-
public static IntPtr FutureWarning;
562-
#if (PYTHON25 || PYTHON26)
571+
public static IntPtr StopIteration;
572+
#if (PYTHON25 || PYTHON26 || PYTHON27)
563573
public static IntPtr GeneratorExit;
564574
#endif
575+
public static IntPtr StandardError;
576+
public static IntPtr ArithmeticError;
577+
public static IntPtr LookupError;
578+
579+
public static IntPtr AssertionError;
580+
public static IntPtr AttributeError;
581+
public static IntPtr EOFError;
582+
public static IntPtr FloatingPointError;
583+
public static IntPtr EnvironmentError;
565584
public static IntPtr IOError;
585+
public static IntPtr OSError;
566586
public static IntPtr ImportError;
567-
#if (PYTHON25 || PYTHON26)
568-
public static IntPtr ImportWarning;
569-
#endif
570-
public static IntPtr IndentationError;
571587
public static IntPtr IndexError;
572588
public static IntPtr KeyError;
573589
public static IntPtr KeyboardInterrupt;
574-
public static IntPtr LookupError;
575590
public static IntPtr MemoryError;
576591
public static IntPtr NameError;
577-
public static IntPtr NotImplementedError;
578-
public static IntPtr OSError;
579592
public static IntPtr OverflowError;
580-
public static IntPtr PendingDeprecationWarning;
581-
public static IntPtr ReferenceError;
582593
public static IntPtr RuntimeError;
583-
public static IntPtr RuntimeWarning;
584-
public static IntPtr StandardError;
585-
public static IntPtr StopIteration;
594+
public static IntPtr NotImplementedError;
586595
public static IntPtr SyntaxError;
587-
public static IntPtr SyntaxWarning;
596+
public static IntPtr IndentationError;
597+
public static IntPtr TabError;
598+
public static IntPtr ReferenceError;
588599
public static IntPtr SystemError;
589600
public static IntPtr SystemExit;
590-
public static IntPtr TabError;
591601
public static IntPtr TypeError;
592602
public static IntPtr UnboundLocalError;
593-
public static IntPtr UnicodeDecodeError;
594-
public static IntPtr UnicodeEncodeError;
595603
public static IntPtr UnicodeError;
604+
public static IntPtr UnicodeEncodeError;
605+
public static IntPtr UnicodeDecodeError;
596606
public static IntPtr UnicodeTranslateError;
597-
#if (PYTHON25 || PYTHON26)
598-
public static IntPtr UnicodeWarning;
599-
#endif
600-
public static IntPtr UserWarning;
601607
public static IntPtr ValueError;
602-
public static IntPtr Warning;
603-
//public static IntPtr WindowsError;
604608
public static IntPtr ZeroDivisionError;
609+
//#ifdef MS_WINDOWS
610+
//public static IntPtr WindowsError;
611+
//#endif
612+
//#ifdef __VMS
613+
//public static IntPtr VMSError;
614+
//#endif
605615

616+
//PyAPI_DATA(PyObject *) PyExc_BufferError;
617+
618+
//PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
619+
//PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst;
620+
621+
622+
/* Predefined warning categories */
623+
public static IntPtr Warning;
624+
public static IntPtr UserWarning;
625+
public static IntPtr DeprecationWarning;
626+
public static IntPtr PendingDeprecationWarning;
627+
public static IntPtr SyntaxWarning;
628+
public static IntPtr RuntimeWarning;
629+
public static IntPtr FutureWarning;
630+
#if (PYTHON25 || PYTHON26 || PYTHON27)
631+
public static IntPtr ImportWarning;
632+
public static IntPtr UnicodeWarning;
633+
//PyAPI_DATA(PyObject *) PyExc_BytesWarning;
634+
#endif
606635
}
607636

608637

0 commit comments

Comments
 (0)