@@ -152,131 +152,5 @@ public override IntPtr type_subscript(IntPtr idx)
152152 }
153153 return Exceptions . RaiseTypeError ( "unsubscriptable object" ) ;
154154 }
155-
156-
157- /// <summary>
158- /// Implements __getitem__ for reflected classes and value types.
159- /// </summary>
160- public static IntPtr mp_subscript ( IntPtr ob , IntPtr idx )
161- {
162- //ManagedType self = GetManagedObject(ob);
163- IntPtr tp = Runtime . PyObject_TYPE ( ob ) ;
164- var cls = ( ClassBase ) GetManagedObject ( tp ) ;
165-
166- if ( cls . indexer == null || ! cls . indexer . CanGet )
167- {
168- Exceptions . SetError ( Exceptions . TypeError , "unindexable object" ) ;
169- return IntPtr . Zero ;
170- }
171-
172- // Arg may be a tuple in the case of an indexer with multiple
173- // parameters. If so, use it directly, else make a new tuple
174- // with the index arg (method binders expect arg tuples).
175- IntPtr args = idx ;
176- var free = false ;
177-
178- if ( ! Runtime . PyTuple_Check ( idx ) )
179- {
180- args = Runtime . PyTuple_New ( 1 ) ;
181- Runtime . XIncref ( idx ) ;
182- Runtime . PyTuple_SetItem ( args , 0 , idx ) ;
183- free = true ;
184- }
185-
186- IntPtr value ;
187-
188- try
189- {
190- value = cls . indexer . GetItem ( ob , args ) ;
191- }
192- finally
193- {
194- if ( free )
195- {
196- Runtime . XDecref ( args ) ;
197- }
198- }
199- return value ;
200- }
201-
202-
203- /// <summary>
204- /// Implements __setitem__ for reflected classes and value types.
205- /// </summary>
206- public static int mp_ass_subscript ( IntPtr ob , IntPtr idx , IntPtr v )
207- {
208- //ManagedType self = GetManagedObject(ob);
209- IntPtr tp = Runtime . PyObject_TYPE ( ob ) ;
210- var cls = ( ClassBase ) GetManagedObject ( tp ) ;
211-
212- if ( cls . indexer == null || ! cls . indexer . CanSet )
213- {
214- Exceptions . SetError ( Exceptions . TypeError , "object doesn't support item assignment" ) ;
215- return - 1 ;
216- }
217-
218- // Arg may be a tuple in the case of an indexer with multiple
219- // parameters. If so, use it directly, else make a new tuple
220- // with the index arg (method binders expect arg tuples).
221- IntPtr args = idx ;
222- var free = false ;
223-
224- if ( ! Runtime . PyTuple_Check ( idx ) )
225- {
226- args = Runtime . PyTuple_New ( 1 ) ;
227- Runtime . XIncref ( idx ) ;
228- Runtime . PyTuple_SetItem ( args , 0 , idx ) ;
229- free = true ;
230- }
231-
232- // Get the args passed in.
233- var i = Runtime . PyTuple_Size ( args ) ;
234- IntPtr defaultArgs = cls . indexer . GetDefaultArgs ( args ) ;
235- var numOfDefaultArgs = Runtime . PyTuple_Size ( defaultArgs ) ;
236- var temp = i + numOfDefaultArgs ;
237- IntPtr real = Runtime . PyTuple_New ( temp + 1 ) ;
238- for ( var n = 0 ; n < i ; n ++ )
239- {
240- IntPtr item = Runtime . PyTuple_GetItem ( args , n ) ;
241- Runtime . XIncref ( item ) ;
242- Runtime . PyTuple_SetItem ( real , n , item ) ;
243- }
244-
245- // Add Default Args if needed
246- for ( var n = 0 ; n < numOfDefaultArgs ; n ++ )
247- {
248- IntPtr item = Runtime . PyTuple_GetItem ( defaultArgs , n ) ;
249- Runtime . XIncref ( item ) ;
250- Runtime . PyTuple_SetItem ( real , n + i , item ) ;
251- }
252- // no longer need defaultArgs
253- Runtime . XDecref ( defaultArgs ) ;
254- i = temp ;
255-
256- // Add value to argument list
257- Runtime . XIncref ( v ) ;
258- Runtime . PyTuple_SetItem ( real , i , v ) ;
259-
260- try
261- {
262- cls . indexer . SetItem ( ob , real ) ;
263- }
264- finally
265- {
266- Runtime . XDecref ( real ) ;
267-
268- if ( free )
269- {
270- Runtime . XDecref ( args ) ;
271- }
272- }
273-
274- if ( Exceptions . ErrorOccurred ( ) )
275- {
276- return - 1 ;
277- }
278-
279- return 0 ;
280- }
281155 }
282156}
0 commit comments