| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 053a67a commit 1bf2058
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,7 @@ internal class ExceptionClassObject : ClassObject { | |||
| 31 | 31 | internal ExceptionClassObject(Type tp) : base(tp) { | |
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | - #if (PYTHON25 || PYTHON26) | ||
| 34 | + #if (PYTHON25 || PYTHON26 || PYTHON27) | ||
| 35 | 35 | internal static Exception ToException(IntPtr ob) { | |
| 36 | 36 | CLRObject co = GetManagedObject(ob) as CLRObject; | |
| 37 | 37 | if (co == null) { | |
@@ -114,24 +114,27 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) | |||
| 114 | 114 | ||
| 115 | 115 | return Runtime.PyObject_GenericGetAttr(ob, key); | |
| 116 | 116 | } | |
| 117 | - #endif | ||
| 117 | + #endif // (PYTHON25 || PYTHON26 || PYTHON27) | ||
| 118 | 118 | } | |
| 119 | 119 | ||
| 120 | 120 | /// <summary> | |
| 121 | 121 | /// Encapsulates the Python exception APIs. | |
| 122 | 122 | /// </summary> | |
| 123 | + /// <remarks> | ||
| 124 | + /// Readability of the Exceptions class improvements as we look toward version 2.7 ... | ||
| 125 | + /// </remarks> | ||
| 123 | 126 | ||
| 124 | 127 | public class Exceptions { | |
| 125 | 128 | ||
| 129 | + internal static IntPtr warnings_module; | ||
| 130 | + internal static IntPtr exceptions_module; | ||
| 131 | + | ||
| 126 | 132 | private Exceptions() {} | |
| 127 | 133 | ||
| 128 | 134 | //=================================================================== | |
| 129 | 135 | // Initialization performed on startup of the Python runtime. | |
| 130 | 136 | //=================================================================== | |
| 131 | 137 | ||
| 132 | - internal static IntPtr warnings_module; | ||
| 133 | - internal static IntPtr exceptions_module; | ||
| 134 | - | ||
| 135 | 138 | internal static void Initialize() { | |
| 136 | 139 | exceptions_module = Runtime.PyImport_ImportModule("exceptions"); | |
| 137 | 140 | Exceptions.ErrorCheck(exceptions_module); | |
@@ -200,10 +203,20 @@ internal unsafe static void ErrorOccurredCheck(IntPtr pointer) { | |||
| 200 | 203 | // this-at-home hackery) delegates to the managed exception and | |
| 201 | 204 | // obeys the conventions of both Python and managed exceptions. | |
| 202 | 205 | ||
| 206 | + /// <remarks> | ||
| 207 | + /// Conditionally initialized variables! | ||
| 208 | + /// </remarks> | ||
| 203 | 209 | static IntPtr ns_exc; // new-style class for System.Exception | |
| 204 | 210 | static IntPtr os_exc; // old-style class for System.Exception | |
| 205 | 211 | static Hashtable cache; | |
| 206 | 212 | ||
| 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> | ||
| 207 | 220 | internal static void SetupExceptionHack() { | |
| 208 | 221 | ns_exc = ClassManager.GetClass(typeof(Exception)).pyHandle; | |
| 209 | 222 | cache = new Hashtable(); | |
@@ -546,63 +559,79 @@ internal static IntPtr RaiseTypeError(string message) { | |||
| 546 | 559 | return IntPtr.Zero; | |
| 547 | 560 | } | |
| 548 | 561 | ||
| 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) | ||
| 554 | 568 | public static IntPtr BaseException; | |
| 555 | 569 | #endif | |
| 556 | - public static IntPtr DeprecationWarning; | ||
| 557 | - public static IntPtr EOFError; | ||
| 558 | - public static IntPtr EnvironmentError; | ||
| 559 | 570 | 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) | ||
| 563 | 573 | public static IntPtr GeneratorExit; | |
| 564 | 574 | #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; | ||
| 565 | 584 | public static IntPtr IOError; | |
| 585 | + public static IntPtr OSError; | ||
| 566 | 586 | public static IntPtr ImportError; | |
| 567 | - #if (PYTHON25 || PYTHON26) | ||
| 568 | - public static IntPtr ImportWarning; | ||
| 569 | - #endif | ||
| 570 | - public static IntPtr IndentationError; | ||
| 571 | 587 | public static IntPtr IndexError; | |
| 572 | 588 | public static IntPtr KeyError; | |
| 573 | 589 | public static IntPtr KeyboardInterrupt; | |
| 574 | - public static IntPtr LookupError; | ||
| 575 | 590 | public static IntPtr MemoryError; | |
| 576 | 591 | public static IntPtr NameError; | |
| 577 | - public static IntPtr NotImplementedError; | ||
| 578 | - public static IntPtr OSError; | ||
| 579 | 592 | public static IntPtr OverflowError; | |
| 580 | - public static IntPtr PendingDeprecationWarning; | ||
| 581 | - public static IntPtr ReferenceError; | ||
| 582 | 593 | public static IntPtr RuntimeError; | |
| 583 | - public static IntPtr RuntimeWarning; | ||
| 584 | - public static IntPtr StandardError; | ||
| 585 | - public static IntPtr StopIteration; | ||
| 594 | + public static IntPtr NotImplementedError; | ||
| 586 | 595 | public static IntPtr SyntaxError; | |
| 587 | - public static IntPtr SyntaxWarning; | ||
| 596 | + public static IntPtr IndentationError; | ||
| 597 | + public static IntPtr TabError; | ||
| 598 | + public static IntPtr ReferenceError; | ||
| 588 | 599 | public static IntPtr SystemError; | |
| 589 | 600 | public static IntPtr SystemExit; | |
| 590 | - public static IntPtr TabError; | ||
| 591 | 601 | public static IntPtr TypeError; | |
| 592 | 602 | public static IntPtr UnboundLocalError; | |
| 593 | - public static IntPtr UnicodeDecodeError; | ||
| 594 | - public static IntPtr UnicodeEncodeError; | ||
| 595 | 603 | public static IntPtr UnicodeError; | |
| 604 | + public static IntPtr UnicodeEncodeError; | ||
| 605 | + public static IntPtr UnicodeDecodeError; | ||
| 596 | 606 | public static IntPtr UnicodeTranslateError; | |
| 597 | - #if (PYTHON25 || PYTHON26) | ||
| 598 | - public static IntPtr UnicodeWarning; | ||
| 599 | - #endif | ||
| 600 | - public static IntPtr UserWarning; | ||
| 601 | 607 | public static IntPtr ValueError; | |
| 602 | - public static IntPtr Warning; | ||
| 603 | - //public static IntPtr WindowsError; | ||
| 604 | 608 | 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 | ||
| 605 | 615 | ||
| 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 | ||
| 606 | 635 | } | |
| 607 | 636 | ||
| 608 | 637 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments