@@ -153,162 +153,5 @@ public override IntPtr type_subscript(IntPtr idx)
153153 }
154154 return Exceptions . RaiseTypeError ( "unsubscriptable object" ) ;
155155 }
156-
157-
158- /// <summary>
159- /// Implements __getitem__ for reflected classes and value types.
160- /// </summary>
161- public static IntPtr mp_subscript ( IntPtr ob , IntPtr idx )
162- {
163- //ManagedType self = GetManagedObject(ob);
164- IntPtr tp = Runtime . PyObject_TYPE ( ob ) ;
165- var cls = ( ClassBase ) GetManagedObject ( tp ) ;
166-
167- if ( cls . indexer == null || ! cls . indexer . CanGet )
168- {
169- Exceptions . SetError ( Exceptions . TypeError , "unindexable object" ) ;
170- return IntPtr . Zero ;
171- }
172-
173- // Arg may be a tuple in the case of an indexer with multiple
174- // parameters. If so, use it directly, else make a new tuple
175- // with the index arg (method binders expect arg tuples).
176- IntPtr args = idx ;
177- var free = false ;
178-
179- if ( ! Runtime . PyTuple_Check ( idx ) )
180- {
181- args = Runtime . PyTuple_New ( 1 ) ;
182- Runtime . XIncref ( idx ) ;
183- Runtime . PyTuple_SetItem ( args , 0 , idx ) ;
184- free = true ;
185- }
186-
187- IntPtr value ;
188-
189- try
190- {
191- value = cls . indexer . GetItem ( ob , args ) ;
192- }
193- finally
194- {
195- if ( free )
196- {
197- Runtime . XDecref ( args ) ;
198- }
199- }
200- return value ;
201- }
202-
203-
204- /// <summary>
205- /// Implements __setitem__ for reflected classes and value types.
206- /// </summary>
207- public static int mp_ass_subscript ( IntPtr ob , IntPtr idx , IntPtr v )
208- {
209- //ManagedType self = GetManagedObject(ob);
210- IntPtr tp = Runtime . PyObject_TYPE ( ob ) ;
211- var cls = ( ClassBase ) GetManagedObject ( tp ) ;
212-
213- if ( cls . indexer == null || ! cls . indexer . CanSet )
214- {
215- Exceptions . SetError ( Exceptions . TypeError , "object doesn't support item assignment" ) ;
216- return - 1 ;
217- }
218-
219- // Arg may be a tuple in the case of an indexer with multiple
220- // parameters. If so, use it directly, else make a new tuple
221- // with the index arg (method binders expect arg tuples).
222- IntPtr args = idx ;
223- var free = false ;
224-
225- if ( ! Runtime . PyTuple_Check ( idx ) )
226- {
227- args = Runtime . PyTuple_New ( 1 ) ;
228- Runtime . XIncref ( idx ) ;
229- Runtime . PyTuple_SetItem ( args , 0 , idx ) ;
230- free = true ;
231- }
232-
233- // Get the args passed in.
234- var i = Runtime . PyTuple_Size ( args ) ;
235- IntPtr defaultArgs = cls . indexer . GetDefaultArgs ( args ) ;
236- var numOfDefaultArgs = Runtime . PyTuple_Size ( defaultArgs ) ;
237- var temp = i + numOfDefaultArgs ;
238- IntPtr real = Runtime . PyTuple_New ( temp + 1 ) ;
239- for ( var n = 0 ; n < i ; n ++ )
240- {
241- IntPtr item = Runtime . PyTuple_GetItem ( args , n ) ;
242- Runtime . XIncref ( item ) ;
243- Runtime . PyTuple_SetItem ( real , n , item ) ;
244- }
245-
246- // Add Default Args if needed
247- for ( var n = 0 ; n < numOfDefaultArgs ; n ++ )
248- {
249- IntPtr item = Runtime . PyTuple_GetItem ( defaultArgs , n ) ;
250- Runtime . XIncref ( item ) ;
251- Runtime . PyTuple_SetItem ( real , n + i , item ) ;
252- }
253- // no longer need defaultArgs
254- Runtime . XDecref ( defaultArgs ) ;
255- i = temp ;
256-
257- // Add value to argument list
258- Runtime . XIncref ( v ) ;
259- Runtime . PyTuple_SetItem ( real , i , v ) ;
260-
261- try
262- {
263- cls . indexer . SetItem ( ob , real ) ;
264- }
265- finally
266- {
267- Runtime . XDecref ( real ) ;
268-
269- if ( free )
270- {
271- Runtime . XDecref ( args ) ;
272- }
273- }
274-
275- if ( Exceptions . ErrorOccurred ( ) )
276- {
277- return - 1 ;
278- }
279-
280- return 0 ;
281- }
282-
283-
284- /// <summary>
285- /// This is a hack. Generally, no managed class is considered callable
286- /// from Python - with the exception of System.Delegate. It is useful
287- /// to be able to call a System.Delegate instance directly, especially
288- /// when working with multicast delegates.
289- /// </summary>
290- public static IntPtr tp_call ( IntPtr ob , IntPtr args , IntPtr kw )
291- {
292- //ManagedType self = GetManagedObject(ob);
293- IntPtr tp = Runtime . PyObject_TYPE ( ob ) ;
294- var cb = ( ClassBase ) GetManagedObject ( tp ) ;
295-
296- if ( cb . type != typeof ( Delegate ) )
297- {
298- Exceptions . SetError ( Exceptions . TypeError , "object is not callable" ) ;
299- return IntPtr . Zero ;
300- }
301-
302- var co = ( CLRObject ) GetManagedObject ( ob ) ;
303- var d = co . inst as Delegate ;
304- BindingFlags flags = BindingFlags . Public |
305- BindingFlags . NonPublic |
306- BindingFlags . Instance |
307- BindingFlags . Static ;
308-
309- MethodInfo method = d . GetType ( ) . GetMethod ( "Invoke" , flags ) ;
310- var binder = new MethodBinder ( method ) ;
311- return binder . Invoke ( ob , args , kw ) ;
312- }
313156 }
314157}
0 commit comments