Esempio n. 1
0
            public object LightThrowTarget(CallSite site, object self, CodeContext context)
            {
                if (self != null && self.GetType() == typeof(PythonModule))
                {
                    var res = ((PythonModule)self).GetAttributeNoThrow(context, _name);
                    if (res == OperationFailed.Value)
                    {
                        return(LightExceptions.Throw(
                                   PythonOps.AttributeErrorForObjectMissingAttribute(self, _name)
                                   ));
                    }
                    return(res);
                }

                return(Update(site, self, context));
            }
Esempio n. 2
0
            public object LightThrowTarget(CallSite site, object instance, CodeContext context)
            {
                OldInstance oi = instance as OldInstance;

                if (oi != null)
                {
                    object res;
                    if (oi.TryGetBoundCustomMember(context, _name, out res))
                    {
                        return(res);
                    }
                    return(LightExceptions.Throw(PythonOps.AttributeError("{0} instance has no attribute '{1}'", oi._class.Name, _name)));
                }

                return(((CallSite <Func <CallSite, object, CodeContext, object> >)site).Update(site, instance, context));
            }
Esempio n. 3
0
        public object next()
        {
            // Python's language policy on generators is that attempting to access after it's closed (returned)
            // just continues to throw StopIteration exceptions.
            if (Closed)
            {
                return(LightExceptions.Throw(new StopIterationException()));
            }

            object res = NextWorker();

            if (res == OperationFailed.Value)
            {
                return(LightExceptions.Throw(new StopIterationException()));
            }

            return(res);
        }
Esempio n. 4
0
        private object @throw(object type, object value, object traceback, bool finalizing)
        {
            // The Pep342 explicitly says "The type argument must not be None".
            // According to CPython 2.5's implementation, a null type argument should:
            // - throw a TypeError exception (just as Raise(None) would) *outside* of the generator's body
            //   (so the generator can't catch it).
            // - not update any other generator state (so future calls to Next() will still work)
            if (type == null)
            {
                // Create the appropriate exception and throw it.
                throw PythonOps.MakeExceptionTypeError(null, true);
            }

            // Set fields which will then be used by CheckThrowable.
            // We create the actual exception from inside the generator so that if the exception's __init__
            // throws, the traceback matches that which we get from CPython2.5.
            _excInfo = new object[] { type, value, traceback };
            Debug.Assert(_sendValue == null);

            // Pep explicitly says that Throw on a closed generator throws the exception,
            // and not a StopIteration exception. (This is different than Next()).
            if (Closed)
            {
                // this will throw the exception that we just set the fields for.
                var throwable = CheckThrowable();
                if (throwable != null)
                {
                    return(throwable);
                }
            }
            if (finalizing)
            {
                // we are running on the finalizer thread - things can be already collected
                return(LightExceptions.Throw(PythonOps.StopIteration()));
            }
            if (!((IEnumerator)this).MoveNext())
            {
                return(LightExceptions.Throw(PythonOps.StopIteration()));
            }
            return(CurrentValue);
        }
Esempio n. 5
0
            public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
            {
                var        ex = Expression.New(typeof(MissingMemberException));
                Expression body;

                if (Name == "foo")
                {
                    body = target.Expression;
                }
                else if (_supportsLightEx)
                {
                    body = LightExceptions.Throw(ex, typeof(object));
                }
                else
                {
                    body = Expression.Throw(ex, typeof(object));
                }

                return(new DynamicMetaObject(
                           body,
                           BindingRestrictions.GetTypeRestriction(target.Expression, target.Value.GetType())
                           ));
            }
Esempio n. 6
0
 public static object a2b_qp(object data, object header)
 {
     return(LightExceptions.Throw(new NotImplementedException()));
 }
Esempio n. 7
0
 public static object LightThrowingCallInvalidOp()
 {
     return(LightExceptions.Throw(new InvalidOperationException()));
 }
Esempio n. 8
0
 public static object LightThrowingCall()
 {
     return(LightExceptions.Throw(new Exception()));
 }