home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Include / abstract.h next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  23.9 KB  |  818 lines  |  [TEXT/R*ch]

  1. #ifndef Py_ABSTRACTOBJECT_H
  2. #define Py_ABSTRACTOBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7. /***********************************************************
  8. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  9. The Netherlands.
  10.  
  11.                         All Rights Reserved
  12.  
  13. Permission to use, copy, modify, and distribute this software and its 
  14. documentation for any purpose and without fee is hereby granted, 
  15. provided that the above copyright notice appear in all copies and that
  16. both that copyright notice and this permission notice appear in 
  17. supporting documentation, and that the names of Stichting Mathematisch
  18. Centrum or CWI not be used in advertising or publicity pertaining to
  19. distribution of the software without specific, written prior permission.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  22. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  23. FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  24. FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  25. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  26. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  27. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28.  
  29. ******************************************************************/
  30.  
  31. /* Abstract Object Interface (many thanks to Jim Fulton) */
  32.  
  33. /*
  34.    PROPOSAL: A Generic Python Object Interface for Python C Modules
  35.  
  36. Problem
  37.  
  38.   Python modules written in C that must access Python objects must do
  39.   so through routines whose interfaces are described by a set of
  40.   include files.  Unfortunately, these routines vary according to the
  41.   object accessed.  To use these routines, the C programmer must check
  42.   the type of the object being used and must call a routine based on
  43.   the object type.  For example, to access an element of a sequence,
  44.   the programmer must determine whether the sequence is a list or a
  45.   tuple:
  46.  
  47.     if(is_tupleobject(o))
  48.       e=gettupleitem(o,i)
  49.     else if(is_listitem(o))
  50.       e=getlistitem(o,i)
  51.  
  52.   If the programmer wants to get an item from another type of object
  53.   that provides sequence behavior, there is no clear way to do it
  54.   correctly.  
  55.  
  56.   The persistent programmer may peruse object.h and find that the
  57.   _typeobject structure provides a means of invoking up to (currently
  58.   about) 41 special operators.  So, for example, a routine can get an
  59.   item from any object that provides sequence behavior. However, to
  60.   use this mechanism, the programmer must make their code dependent on
  61.   the current Python implementation.
  62.  
  63.   Also, certain semantics, especially memory management semantics, may
  64.   differ by the type of object being used.  Unfortunately, these
  65.   semantics are not clearly described in the current include files.
  66.   An abstract interface providing more consistent semantics is needed. 
  67.  
  68. Proposal
  69.  
  70.   I propose the creation of a standard interface (with an associated
  71.   library of routines and/or macros) for generically obtaining the
  72.   services of Python objects.  This proposal can be viewed as one
  73.   components of a Python C interface consisting of several components.
  74.  
  75.   From the viewpoint of of C access to Python services, we have (as
  76.   suggested by Guido in off-line discussions):
  77.  
  78.   - "Very high level layer": two or three functions that let you exec or
  79.     eval arbitrary Python code given as a string in a module whose name is
  80.     given, passing C values in and getting C values out using
  81.     mkvalue/getargs style format strings.  This does not require the user
  82.     to declare any variables of type "PyObject *".  This should be enough
  83.     to write a simple application that gets Python code from the user,
  84.     execs it, and returns the output or errors.  (Error handling must also
  85.     be part of this API.)
  86.  
  87.   - "Abstract objects layer": which is the subject of this proposal.
  88.     It has many functions operating on objects, and lest you do many
  89.     things from C that you can also write in Python, without going
  90.     through the Python parser.
  91.  
  92.   - "Concrete objects layer": This is the public type-dependent
  93.     interface provided by the standard built-in types, such as floats,
  94.     strings, and lists.  This interface exists and is currently
  95.     documented by the collection of include files provides with the
  96.     Python distributions.
  97.  
  98.   From the point of view of Python accessing services provided by C
  99.   modules: 
  100.  
  101.   - "Python module interface": this interface consist of the basic
  102.     routines used to define modules and their members.  Most of the
  103.     current extensions-writing guide deals with this interface.
  104.  
  105.   - "Built-in object interface": this is the interface that a new
  106.     built-in type must provide and the mechanisms and rules that a
  107.     developer of a new built-in type must use and follow.
  108.  
  109.   This proposal is a "first-cut" that is intended to spur
  110.   discussion. See especially the lists of notes.
  111.  
  112.   The Python C object interface will provide four protocols: object,
  113.   numeric, sequence, and mapping.  Each protocol consists of a
  114.   collection of related operations.  If an operation that is not
  115.   provided by a particular type is invoked, then a standard exception,
  116.   NotImplementedError is raised with a operation name as an argument.
  117.   In addition, for convenience this interface defines a set of
  118.   constructors for building objects of built-in types.  This is needed
  119.   so new objects can be returned from C functions that otherwise treat
  120.   objects generically.
  121.  
  122. Memory Management
  123.  
  124.   For all of the functions described in this proposal, if a function
  125.   retains a reference to a Python object passed as an argument, then the
  126.   function will increase the reference count of the object.  It is
  127.   unnecessary for the caller to increase the reference count of an
  128.   argument in anticipation of the object's retention.
  129.  
  130.   All Python objects returned from functions should be treated as new
  131.   objects.  Functions that return objects assume that the caller will
  132.   retain a reference and the reference count of the object has already
  133.   been incremented to account for this fact.  A caller that does not
  134.   retain a reference to an object that is returned from a function
  135.   must decrement the reference count of the object (using
  136.   DECREF(object)) to prevent memory leaks.
  137.  
  138.   Note that the behavior mentioned here is different from the current
  139.   behavior for some objects (e.g. lists and tuples) when certain
  140.   type-specific routines are called directly (e.g. setlistitem).  The
  141.   proposed abstraction layer will provide a consistent memory
  142.   management interface, correcting for inconsistent behavior for some
  143.   built-in types.
  144.  
  145. Protocols
  146.  
  147. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
  148.  
  149. /*  Object Protocol: */
  150.  
  151.      /* Implemented elsewhere:
  152.  
  153.      int PyObject_Print(PyObject *o, FILE *fp, int flags);
  154.  
  155.          Print an object, o, on file, fp.  Returns -1 on
  156.      error.  The flags argument is used to enable certain printing
  157.      options. The only option currently supported is Py_Print_RAW. 
  158.  
  159.          (What should be said about Py_Print_RAW?)    
  160.  
  161.        */
  162.  
  163.      /* Implemented elsewhere:
  164.  
  165.      int PyObject_HasAttrString(PyObject *o, char *attr_name);
  166.  
  167.          Returns 1 if o has the attribute attr_name, and 0 otherwise.
  168.      This is equivalent to the Python expression:
  169.      hasattr(o,attr_name). 
  170.  
  171.      This function always succeeds.
  172.  
  173.        */
  174.  
  175.      /* Implemented elsewhere:
  176.  
  177.      PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name);
  178.  
  179.      Retrieve an attributed named attr_name form object o.
  180.      Returns the attribute value on success, or NULL on failure.
  181.      This is the equivalent of the Python expression: o.attr_name.
  182.  
  183.        */
  184.  
  185.      /* Implemented elsewhere:
  186.  
  187.      int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
  188.  
  189.          Returns 1 if o has the attribute attr_name, and 0 otherwise.
  190.      This is equivalent to the Python expression:
  191.      hasattr(o,attr_name). 
  192.  
  193.      This function always succeeds.
  194.  
  195.        */
  196.  
  197.      /* Implemented elsewhere:
  198.  
  199.      PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
  200.  
  201.      Retrieve an attributed named attr_name form object o.
  202.      Returns the attribute value on success, or NULL on failure.
  203.      This is the equivalent of the Python expression: o.attr_name.
  204.  
  205.        */
  206.  
  207.  
  208.      /* Implemented elsewhere:
  209.  
  210.      int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v);
  211.  
  212.      Set the value of the attribute named attr_name, for object o,
  213.      to the value, v. Returns -1 on failure.  This is
  214.      the equivalent of the Python statement: o.attr_name=v.
  215.  
  216.        */
  217.  
  218.      /* Implemented elsewhere:
  219.  
  220.      int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
  221.  
  222.      Set the value of the attribute named attr_name, for object o,
  223.      to the value, v. Returns -1 on failure.  This is
  224.      the equivalent of the Python statement: o.attr_name=v.
  225.  
  226.        */
  227.  
  228.      /* implemented as a macro:
  229.  
  230.      int PyObject_DelAttrString(PyObject *o, char *attr_name);
  231.  
  232.      Delete attribute named attr_name, for object o. Returns
  233.      -1 on failure.  This is the equivalent of the Python
  234.      statement: del o.attr_name.
  235.  
  236.        */
  237. #define  PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL)
  238.  
  239.      /* implemented as a macro:
  240.  
  241.      int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
  242.  
  243.      Delete attribute named attr_name, for object o. Returns -1
  244.      on failure.  This is the equivalent of the Python
  245.      statement: del o.attr_name.
  246.  
  247.        */
  248. #define  PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL)
  249.  
  250.      int PyObject_Cmp Py_PROTO((PyObject *o1, PyObject *o2, int *result));
  251.  
  252.        /*
  253.      Compare the values of o1 and o2 using a routine provided by
  254.      o1, if one exists, otherwise with a routine provided by o2.
  255.      The result of the comparison is returned in result.  Returns
  256.      -1 on failure.  This is the equivalent of the Python
  257.      statement: result=cmp(o1,o2).
  258.  
  259.        */
  260.  
  261.      /* Implemented elsewhere:
  262.  
  263.      int PyObject_Compare(PyObject *o1, PyObject *o2);
  264.  
  265.      Compare the values of o1 and o2 using a routine provided by
  266.      o1, if one exists, otherwise with a routine provided by o2.
  267.      Returns the result of the comparison on success.  On error,
  268.      the value returned is undefined. This is equivalent to the
  269.      Python expression: cmp(o1,o2).
  270.  
  271.        */
  272.  
  273.      /* Implemented elsewhere:
  274.  
  275.      PyObject *PyObject_Repr(PyObject *o);
  276.  
  277.      Compute the string representation of object, o.  Returns the
  278.      string representation on success, NULL on failure.  This is
  279.      the equivalent of the Python expression: repr(o).
  280.  
  281.      Called by the repr() built-in function and by reverse quotes.
  282.  
  283.        */
  284.  
  285.      /* Implemented elsewhere:
  286.  
  287.      PyObject *PyObject_Str(PyObject *o);
  288.  
  289.      Compute the string representation of object, o.  Returns the
  290.      string representation on success, NULL on failure.  This is
  291.      the equivalent of the Python expression: str(o).)
  292.  
  293.      Called by the str() built-in function and by the print
  294.      statement.
  295.  
  296.        */
  297.  
  298.      int PyCallable_Check Py_PROTO((PyObject *o));
  299.  
  300.        /*
  301.      Determine if the object, o, is callable.  Return 1 if the
  302.      object is callable and 0 otherwise.
  303.  
  304.      This function always succeeds.
  305.  
  306.        */
  307.  
  308.  
  309.      
  310.      PyObject *PyObject_CallObject Py_PROTO((PyObject *callable_object,
  311.                          PyObject *args));
  312.  
  313.        /*
  314.  
  315.      Call a callable Python object, callable_object, with
  316.      arguments given by the tuple, args.  If no arguments are
  317.      needed, then args may be NULL.  Returns the result of the
  318.      call on success, or NULL on failure.  This is the equivalent
  319.      of the Python expression: apply(o,args).
  320.  
  321.        */
  322.  
  323.      PyObject *PyObject_CallFunction Py_PROTO((PyObject *callable_object,
  324.                            char *format, ...));
  325.  
  326.        /*
  327.      Call a callable Python object, callable_object, with a
  328.      variable number of C arguments. The C arguments are described
  329.      using a mkvalue-style format string. The format may be NULL,
  330.      indicating that no arguments are provided.  Returns the
  331.      result of the call on success, or NULL on failure.  This is
  332.      the equivalent of the Python expression: apply(o,args).
  333.  
  334.        */
  335.  
  336.  
  337.      PyObject *PyObject_CallMethod Py_PROTO((PyObject *o, char *m,
  338.                          char *format, ...));
  339.  
  340.        /*
  341.      Call the method named m of object o with a variable number of
  342.      C arguments.  The C arguments are described by a mkvalue
  343.      format string.  The format may be NULL, indicating that no
  344.      arguments are provided. Returns the result of the call on
  345.      success, or NULL on failure.  This is the equivalent of the
  346.      Python expression: o.method(args).
  347.  
  348.          Note that Special method names, such as "__add__",
  349.      "__getitem__", and so on are not supported. The specific
  350.      abstract-object routines for these must be used.
  351.  
  352.        */
  353.  
  354.  
  355.      /* Implemented elsewhere:
  356.  
  357.      long PyObject_Hash(PyObject *o);
  358.  
  359.          Compute and return the hash, hash_value, of an object, o.  On
  360.      failure, return -1.  This is the equivalent of the Python
  361.      expression: hash(o).
  362.  
  363.        */
  364.  
  365.  
  366.      /* Implemented elsewhere:
  367.  
  368.      int PyObject_IsTrue(PyObject *o);
  369.  
  370.      Returns 1 if the object, o, is considered to be true, and
  371.      0 otherwise. This is equivalent to the Python expression:
  372.      not not o
  373.  
  374.      This function always succeeds.
  375.      
  376.        */
  377.  
  378.      PyObject *PyObject_Type Py_PROTO((PyObject *o));
  379.  
  380.        /*
  381.      On success, returns a type object corresponding to the object
  382.      type of object o. On failure, returns NULL.  This is
  383.      equivalent to the Python expression: type(o).
  384.        */
  385.  
  386.      int PyObject_Length Py_PROTO((PyObject *o));
  387.  
  388.        /*
  389.          Return the length of object o.  If the object, o, provides
  390.      both sequence and mapping protocols, the sequence length is
  391.      returned. On error, -1 is returned.  This is the equivalent
  392.      to the Python expression: len(o).
  393.  
  394.        */
  395.  
  396.      PyObject *PyObject_GetItem Py_PROTO((PyObject *o, PyObject *key));
  397.  
  398.        /*
  399.      Return element of o corresponding to the object, key, or NULL
  400.      on failure. This is the equivalent of the Python expression:
  401.      o[key].
  402.  
  403.        */
  404.  
  405.      int PyObject_SetItem Py_PROTO((PyObject *o, PyObject *key, PyObject *v));
  406.  
  407.        /*
  408.      Map the object, key, to the value, v.  Returns
  409.      -1 on failure.  This is the equivalent of the Python
  410.      statement: o[key]=v.
  411.        */
  412.  
  413.  
  414. /*  Number Protocol:*/
  415.  
  416.      int PyNumber_Check Py_PROTO((PyObject *o));
  417.  
  418.        /*
  419.          Returns 1 if the object, o, provides numeric protocols, and
  420.      false otherwise. 
  421.  
  422.      This function always succeeds.
  423.  
  424.        */
  425.  
  426.      PyObject *PyNumber_Add Py_PROTO((PyObject *o1, PyObject *o2));
  427.  
  428.        /*
  429.      Returns the result of adding o1 and o2, or null on failure.
  430.      This is the equivalent of the Python expression: o1+o2.
  431.  
  432.  
  433.        */
  434.  
  435.      PyObject *PyNumber_Subtract Py_PROTO((PyObject *o1, PyObject *o2));
  436.  
  437.        /*
  438.      Returns the result of subtracting o2 from o1, or null on
  439.      failure.  This is the equivalent of the Python expression:
  440.      o1-o2.
  441.  
  442.        */
  443.  
  444.      PyObject *PyNumber_Multiply Py_PROTO((PyObject *o1, PyObject *o2));
  445.  
  446.        /*
  447.      Returns the result of multiplying o1 and o2, or null on
  448.      failure.  This is the equivalent of the Python expression:
  449.      o1*o2.
  450.  
  451.  
  452.        */
  453.  
  454.      PyObject *PyNumber_Divide Py_PROTO((PyObject *o1, PyObject *o2));
  455.  
  456.        /*
  457.      Returns the result of dividing o1 by o2, or null on failure.
  458.      This is the equivalent of the Python expression: o1/o2.
  459.  
  460.  
  461.        */
  462.  
  463.      PyObject *PyNumber_Remainder Py_PROTO((PyObject *o1, PyObject *o2));
  464.  
  465.        /*
  466.      Returns the remainder of dividing o1 by o2, or null on
  467.      failure.  This is the equivalent of the Python expression:
  468.      o1%o2.
  469.  
  470.  
  471.        */
  472.  
  473.      PyObject *PyNumber_Divmod Py_PROTO((PyObject *o1, PyObject *o2));
  474.  
  475.        /*
  476.      See the built-in function divmod.  Returns NULL on failure.
  477.      This is the equivalent of the Python expression:
  478.      divmod(o1,o2).
  479.  
  480.  
  481.        */
  482.  
  483.      PyObject *PyNumber_Power Py_PROTO((PyObject *o1, PyObject *o2, PyObject *o3));
  484.  
  485.        /*
  486.      See the built-in function pow.  Returns NULL on failure.
  487.      This is the equivalent of the Python expression:
  488.      pow(o1,o2,o3), where o3 is optional.
  489.  
  490.        */
  491.  
  492.      PyObject *PyNumber_Negative Py_PROTO((PyObject *o));
  493.  
  494.        /*
  495.      Returns the negation of o on success, or null on failure.
  496.      This is the equivalent of the Python expression: -o.
  497.  
  498.        */
  499.  
  500.      PyObject *PyNumber_Positive Py_PROTO((PyObject *o));
  501.  
  502.        /*
  503.          Returns the (what?) of o on success, or NULL on failure.
  504.      This is the equivalent of the Python expression: +o.
  505.  
  506.        */
  507.  
  508.      PyObject *PyNumber_Absolute Py_PROTO((PyObject *o));
  509.  
  510.        /*
  511.      Returns the absolute value of o, or null on failure.  This is
  512.      the equivalent of the Python expression: abs(o).
  513.  
  514.        */
  515.  
  516.      PyObject *PyNumber_Invert Py_PROTO((PyObject *o));
  517.  
  518.        /*
  519.      Returns the bitwise negation of o on success, or NULL on
  520.      failure.  This is the equivalent of the Python expression:
  521.      ~o.
  522.  
  523.  
  524.        */
  525.  
  526.      PyObject *PyNumber_Lshift Py_PROTO((PyObject *o1, PyObject *o2));
  527.  
  528.        /*
  529.      Returns the result of left shifting o1 by o2 on success, or
  530.      NULL on failure.  This is the equivalent of the Python
  531.      expression: o1 << o2.
  532.  
  533.  
  534.        */
  535.  
  536.      PyObject *PyNumber_Rshift Py_PROTO((PyObject *o1, PyObject *o2));
  537.  
  538.        /*
  539.      Returns the result of right shifting o1 by o2 on success, or
  540.      NULL on failure.  This is the equivalent of the Python
  541.      expression: o1 >> o2.
  542.  
  543.        */
  544.  
  545.      PyObject *PyNumber_And Py_PROTO((PyObject *o1, PyObject *o2));
  546.  
  547.        /*
  548.      Returns the result of "anding" o2 and o2 on success and NULL
  549.      on failure. This is the equivalent of the Python
  550.      expression: o1 and o2.
  551.  
  552.  
  553.        */
  554.  
  555.      PyObject *PyNumber_Xor Py_PROTO((PyObject *o1, PyObject *o2));
  556.  
  557.        /*
  558.      Returns the bitwise exclusive or of o1 by o2 on success, or
  559.      NULL on failure.  This is the equivalent of the Python
  560.      expression: o1^o2.
  561.  
  562.  
  563.        */
  564.  
  565.      PyObject *PyNumber_Or Py_PROTO((PyObject *o1, PyObject *o2));
  566.  
  567.        /*
  568.      Returns the result or o1 and o2 on success, or NULL on
  569.      failure.  This is the equivalent of the Python expression: 
  570.      o1 or o2.
  571.  
  572.        */
  573.  
  574.      /* Implemented elsewhere:
  575.  
  576.      int PyNumber_Coerce(PyObject *o1, PyObject *o2);
  577.  
  578.          On success, returns a tuple containing o1 and o2 converted to
  579.      a common numeric type, or None if no conversion is possible.
  580.      Returns -1 on failure. This is equivalent to the Python
  581.      expression: coerce(o1,o2).
  582.  
  583.        */
  584.  
  585.      PyObject *PyNumber_Int Py_PROTO((PyObject *o));
  586.  
  587.        /*
  588.      Returns the o converted to an integer object on success, or
  589.      NULL on failure.  This is the equivalent of the Python
  590.      expression: int(o).
  591.  
  592.        */
  593.  
  594.      PyObject *PyNumber_Long Py_PROTO((PyObject *o));
  595.  
  596.        /*
  597.      Returns the o converted to a long integer object on success,
  598.      or NULL on failure.  This is the equivalent of the Python
  599.      expression: long(o).
  600.  
  601.        */
  602.  
  603.      PyObject *PyNumber_Float Py_PROTO((PyObject *o));
  604.  
  605.        /*
  606.      Returns the o converted to a float object on success, or NULL
  607.      on failure.  This is the equivalent of the Python expression:
  608.      float(o).
  609.        */
  610.      
  611.  
  612. /*  Sequence protocol:*/
  613.  
  614.      int PySequence_Check Py_PROTO((PyObject *o));
  615.  
  616.        /*
  617.          Return 1 if the object provides sequence protocol, and zero
  618.      otherwise.  
  619.  
  620.      This function always succeeds.
  621.  
  622.        */
  623.  
  624.      PyObject *PySequence_Concat Py_PROTO((PyObject *o1, PyObject *o2));
  625.  
  626.        /*
  627.      Return the concatination of o1 and o2 on success, and NULL on
  628.      failure.   This is the equivalent of the Python
  629.      expression: o1+o2.
  630.  
  631.        */
  632.  
  633.      PyObject *PySequence_Repeat Py_PROTO((PyObject *o, int count));
  634.  
  635.        /*
  636.      Return the result of repeating sequence object o count times,
  637.      or NULL on failure.  This is the equivalent of the Python
  638.      expression: o1*count.
  639.  
  640.        */
  641.  
  642.      PyObject *PySequence_GetItem Py_PROTO((PyObject *o, int i));
  643.  
  644.        /*
  645.      Return the ith element of o, or NULL on failure. This is the
  646.      equivalent of the Python expression: o[i].
  647.  
  648.        */
  649.  
  650.      PyObject *PySequence_GetSlice Py_PROTO((PyObject *o, int i1, int i2));
  651.  
  652.        /*
  653.      Return the slice of sequence object o between i1 and i2, or
  654.      NULL on failure. This is the equivalent of the Python
  655.      expression: o[i1:i2].
  656.  
  657.        */
  658.  
  659.      int PySequence_SetItem Py_PROTO((PyObject *o, int i, PyObject *v));
  660.  
  661.        /*
  662.      Assign object v to the ith element of o.  Returns
  663.      -1 on failure.  This is the equivalent of the Python
  664.      statement: o[i]=v.
  665.  
  666.        */
  667.  
  668.      int PySequence_SetSlice Py_PROTO((PyObject *o, int i1, int i2, PyObject *v));
  669.  
  670.        /*
  671.          Assign the sequence object, v, to the slice in sequence
  672.      object, o, from i1 to i2.  Returns -1 on failure. This is the
  673.      equivalent of the Python statement: o[i1:i2]=v.
  674.        */
  675.  
  676.      PyObject *PySequence_Tuple Py_PROTO((PyObject *o));
  677.  
  678.        /*
  679.      Returns the o as a tuple on success, and NULL on failure.
  680.      This is equivalent to the Python expression: tuple(o)
  681.        */
  682.  
  683.      int PySequence_Count Py_PROTO((PyObject *o, PyObject *value));
  684.  
  685.        /*
  686.          Return the number of occurrences on value on o, that is,
  687.      return the number of keys for which o[key]==value.  On
  688.      failure, return -1.  This is equivalent to the Python
  689.      expression: o.count(value).
  690.        */
  691.  
  692.      int PySequence_In Py_PROTO((PyObject *o, PyObject *value));
  693.  
  694.        /*
  695.      Determine if o contains value.  If an item in o is equal to
  696.      X, return 1, otherwise return 0.  On error, return -1.  This
  697.      is equivalent to the Python expression: value in o.
  698.        */
  699.  
  700.      int PySequence_Index Py_PROTO((PyObject *o, PyObject *value));
  701.  
  702.        /*
  703.      Return the first index for which o[i]=value.  On error,
  704.      return -1.    This is equivalent to the Python
  705.      expression: o.index(value).
  706.        */
  707.  
  708. /*  Mapping protocol:*/
  709.  
  710.      int PyMapping_Check Py_PROTO((PyObject *o));
  711.  
  712.        /*
  713.          Return 1 if the object provides mapping protocol, and zero
  714.      otherwise.  
  715.  
  716.      This function always succeeds.
  717.        */
  718.  
  719.      int PyMapping_Length Py_PROTO((PyObject *o));
  720.  
  721.        /*
  722.          Returns the number of keys in object o on success, and -1 on
  723.      failure.  For objects that do not provide sequence protocol,
  724.      this is equivalent to the Python expression: len(o).
  725.        */
  726.  
  727.      int PyMapping_DelItemString Py_PROTO((PyObject *o, char *key));
  728.  
  729.        /*
  730.      Remove the mapping for object, key, from the object *o.
  731.      Returns -1 on failure.  This is equivalent to
  732.      the Python statement: del o[key].
  733.        */
  734.  
  735.      int PyMapping_DelItem Py_PROTO((PyObject *o, PyObject *key));
  736.  
  737.        /*
  738.      Remove the mapping for object, key, from the object *o.
  739.      Returns -1 on failure.  This is equivalent to
  740.      the Python statement: del o[key].
  741.        */
  742.  
  743.      int PyMapping_HasKeyString Py_PROTO((PyObject *o, char *key));
  744.  
  745.        /*
  746.      On success, return 1 if the mapping object has the key, key,
  747.      and 0 otherwise.  This is equivalent to the Python expression:
  748.      o.has_key(key). 
  749.  
  750.      This function always succeeds.
  751.        */
  752.  
  753.      int PyMapping_HasKey Py_PROTO((PyObject *o, PyObject *key));
  754.  
  755.        /*
  756.      Return 1 if the mapping object has the key, key,
  757.      and 0 otherwise.  This is equivalent to the Python expression:
  758.      o.has_key(key). 
  759.  
  760.      This function always succeeds.
  761.  
  762.        */
  763.  
  764.      /* Implemented as macro:
  765.  
  766.      PyObject *PyMapping_Keys(PyObject *o);
  767.  
  768.          On success, return a list of the keys in object o.  On
  769.      failure, return NULL. This is equivalent to the Python
  770.      expression: o.keys().
  771.        */
  772. #define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)
  773.  
  774.      /* Implemented as macro:
  775.  
  776.      PyObject *PyMapping_Values(PyObject *o);
  777.  
  778.          On success, return a list of the values in object o.  On
  779.      failure, return NULL. This is equivalent to the Python
  780.      expression: o.values().
  781.        */
  782. #define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL)
  783.  
  784.      /* Implemented as macro:
  785.  
  786.      PyObject *PyMapping_Items(PyObject *o);
  787.  
  788.          On success, return a list of the items in object o, where
  789.      each item is a tuple containing a key-value pair.  On
  790.      failure, return NULL. This is equivalent to the Python
  791.      expression: o.items().
  792.  
  793.        */
  794. #define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL)
  795.  
  796.      PyObject *PyMapping_GetItemString Py_PROTO((PyObject *o, char *key));
  797.  
  798.        /*
  799.      Return element of o corresponding to the object, key, or NULL
  800.      on failure. This is the equivalent of the Python expression:
  801.      o[key].
  802.        */
  803.  
  804.      int PyMapping_SetItemString Py_PROTO((PyObject *o, char *key,
  805.                        PyObject *value));
  806.  
  807.        /*
  808.      Map the object, key, to the value, v.  Returns 
  809.      -1 on failure.  This is the equivalent of the Python
  810.      statement: o[key]=v.
  811.       */
  812.  
  813.  
  814. #ifdef __cplusplus
  815. }
  816. #endif
  817. #endif /* Py_ABSTRACTOBJECT_H */
  818.