PYTHON_OBJECT

The PYTHON_OBJECT class is the root of the entire Python/Eiffel interoperability shadow class hierarchy. It defines functions for the basic interaction between shadow classes, Python objects, and the Python/C API.

class interface PYTHON_OBJECT
   -- base for all Eiffel-to-Python binding objects; provides bindings
   -- for the basic PythonObject features
creation
   make_from_borrowed_reference (new_python_object_pointer: POINTER)
      -- uses the given object pointer and increases the reference 
      -- count of the given python object.  Used in cases where the 
      -- Python C api does not automatically increase the reference 
      -- count.  Terminology ("borrowed reference" vs "new reference") 
      -- is taken from the Python C Api documentation
      require
         new_python_object_pointer.is_not_null
   make_from_new_reference (new_python_object_pointer: POINTER)
      -- uses the given object pointer without increasing reference 
      -- count of the python object.  Used because several Python C 
      -- api calls generate a new object with a reference count of 
      -- 1, and we don't want to increase that or we get too many 
      -- false references
      require
         new_python_object_pointer.is_not_null
   make_from_python_object (object: PYTHON_OBJECT)
      -- uses the existing python_object_pointer of python_object 
      require
         object /= Void
feature(s) from PYTHON_OBJECT
   python_object_pointer: POINTER
feature(s) from PYTHON_OBJECT
   --  reference counting and initialization
   make_from_borrowed_reference (new_python_object_pointer: POINTER)
      -- uses the given object pointer and increases the reference 
      -- count of the given python object.  Used in cases where the 
      -- Python C api does not automatically increase the reference 
      -- count.  Terminology ("borrowed reference" vs "new reference") 
      -- is taken from the Python C Api documentation
      require
         new_python_object_pointer.is_not_null
   make_from_new_reference (new_python_object_pointer: POINTER)
      -- uses the given object pointer without increasing reference 
      -- count of the python object.  Used because several Python C 
      -- api calls generate a new object with a reference count of 
      -- 1, and we don't want to increase that or we get too many 
      -- false references
      require
         new_python_object_pointer.is_not_null
   make_from_python_object (object: PYTHON_OBJECT)
      -- uses the existing python_object_pointer of python_object 
      require
         object /= Void
   reference_count: INTEGER
   increase_reference_count
   decrease_reference_count
   dispose
      --  Action to be executed just before garbage collection 
      --  reclaims an object.
feature(s) from PYTHON_OBJECT
   --  attributes
   has_attr_string (attribute_name: STRING): BOOLEAN
   has_attr (attribute_name: PYTHON_OBJECT): BOOLEAN
   get_attr_string (attribute_name: STRING): PYTHON_OBJECT
      require
         has_attr_string(attribute_name)
   get_attr (attribute_name: PYTHON_OBJECT): PYTHON_OBJECT
      require
         has_attr(attribute_name)
   set_attr_string (attribute_name: STRING; new_value: PYTHON_OBJECT)
      ensure
         last_python_integer_result_ok
   set_attr (attribute_name: PYTHON_OBJECT; new_value: PYTHON_OBJECT)
      ensure
         last_python_integer_result_ok
   del_attr_string (attribute_name: STRING)
      ensure
         last_python_integer_result_ok
   del_attr (attribute_name: PYTHON_OBJECT)
      ensure
         last_python_integer_result_ok
feature(s) from PYTHON_OBJECT
   --  Predefined attributes
   attr_from_string (attribute_name: STRING): PYTHON_OBJECT
      -- gets an attribute given the string.  Differs from 
      -- get_attr_string in that if the attribute is not present, a 
      -- "None" object is created and returned
   dict: PYTHON_DICTIONARY
   methods: PYTHON_LIST
   members: PYTHON_LIST
   owning_class: PYTHON_OBJECT
   bases: PYTHON_TUPLE
   name: STRING
feature(s) from PYTHON_OBJECT
   --  comparison
   is_equal (other: like Current): BOOLEAN
      --  Is `other' attached to an object considered equal to 
      --  current object ?
      require
         other_not_void: other /= Void
      ensure
         consistent: standard_is_equal(other) implies Result;
         symmetric: Result implies other.is_equal(Current)
   cmp (object: like Current): INTEGER
      ensure
         Result /= - 2
   compare (object: like Current): INTEGER
      --  If current object equal to `other', 0;
      --  if smaller,  -1; if greater, 1.
      require
         other_exists: object /= Void
      ensure
         equal_zero: Result = 0 = is_equal(object);
         smaller_negative: Result = - 1 = Current < object;
         greater_positive: Result = 1 = Current > object
   three_way_comparison (object: like Current): INTEGER
      --  If current object equal to `other', 0;
      --  if smaller,  -1; if greater, 1.
      require
         other_exists: object /= Void
      ensure
         equal_zero: Result = 0 = is_equal(object);
         smaller_negative: Result = - 1 = Current < object;
         greater_positive: Result = 1 = Current > object
   infix "<" (other: like Current): BOOLEAN
      --  Is `Current' strictly less than `other'?
      require
         other_exists: other /= Void
      ensure
         asymmetric: Result implies not (other < Current)
feature(s) from PYTHON_OBJECT
   --  string representation
   to_string: STRING
   repr: PYTHON_OBJECT
      -- representation of the python object.  I think this should be "make_from_new_reference",
      -- but for some reason this caused garbage collection errors. 
      -- Be careful with repr.
   str: PYTHON_OBJECT
feature(s) from PYTHON_OBJECT
   --  identification   
   equals_one (value: INTEGER): BOOLEAN
      -- is the value equal to one?
   is_module: BOOLEAN
   is_file: BOOLEAN
   is_float: BOOLEAN
   is_long: BOOLEAN
   is_integer: BOOLEAN
   is_number: BOOLEAN
   is_dictionary: BOOLEAN
   is_mapping: BOOLEAN
   is_callable: BOOLEAN
   is_sequence: BOOLEAN
   is_string: BOOLEAN
   is_list: BOOLEAN
   is_tuple: BOOLEAN
   is_none: BOOLEAN
   is_true: BOOLEAN
feature(s) from PYTHON_OBJECT
   -- misc
   call_args_from_args (args: PYTHON_TUPLE): PYTHON_TUPLE
      -- creates an empty tuple of arguments if "args" is Void; 
      -- simplifies calls of no-arg methods
   call_object (args: PYTHON_TUPLE): PYTHON_OBJECT
      require
         is_callable
   python_type: PYTHON_OBJECT
   length: INTEGER
      ensure
         last_python_integer_result_ok
   get_item (key: PYTHON_OBJECT): PYTHON_OBJECT
   set_item (key, new_value: PYTHON_OBJECT)
      ensure
         last_python_integer_result_ok
   del_item (key: PYTHON_OBJECT)
      ensure
         last_python_integer_result_ok
invariant
   reference_count >= 0;
end of PYTHON_OBJECT