1. masklinn
  2. py.js

Source

py.js / doc / utility.rst

Diff from to

File doc/utility.rst

 
 They are prefixed with ``PY_``.
 
-.. function:: py.PY_call(callable[, args][, kwargs])
-
-    Call an arbitrary python-level callable from javascript.
-
-    :param callable: A ``py.js`` callable object (broadly speaking,
-                     either a class or an object with a ``__call__``
-                     method)
-
-    :param args: javascript Array of :class:`py.object`, used as
-                 positional arguments to ``callable``
-
-    :param kwargs: javascript Object mapping names to
-                   :class:`py.object`, used as named arguments to
-                   ``callable``
-
-    :returns: nothing or :class:`py.object`
-
 .. function:: py.PY_parseArgs(arguments, format)
 
     Arguments parser converting from the :ref:`user-defined calling
     :param Function fn: the javascript function to wrap
     :returns: a callable py.js object
 
+Object Protocol
+---------------
+
+.. function:: py.PY_hasAttr(o, attr_name)
+
+    Returns ``true`` if ``o`` has the attribute ``attr_name``,
+    otherwise returns ``false``. Equivalent to Python's ``hasattr(o,
+    attr_name)``
+
+    :param o: A :class:`py.object`
+    :param attr_name: a javascript ``String``
+    :rtype: ``Boolean``
+
+.. function:: py.PY_getAttr(o, attr_name)
+
+    Retrieve an attribute ``attr_name`` from the object ``o``. Returns
+    the attribute value on success, raises ``AttributeError`` on
+    failure. Equivalent to the python expression ``o.attr_name``.
+
+    :param o: A :class:`py.object`
+    :param attr_name: a javascript ``String``
+    :returns: A :class:`py.object`
+    :raises: ``AttributeError``
+
+.. function:: py.PY_str(o)
+
+    Computes a string representation of ``o``, returns the string
+    representation. Equivalent to ``str(o)``
+
+    :param o: A :class:`py.object`
+    :returns: :class:`py.str`
+
+.. function:: py.PY_isInstance(inst, cls)
+
+    Returns ``true`` if ``inst`` is an instance of ``cls``, ``false``
+    otherwise.
+
+.. function:: py.PY_isSubclass(derived, cls)
+
+    Returns ``true`` if ``derived`` is ``cls`` or a subclass thereof.
+
+.. function:: py.PY_call(callable[, args][, kwargs])
+
+    Call an arbitrary python-level callable from javascript.
+
+    :param callable: A ``py.js`` callable object (broadly speaking,
+                     either a class or an object with a ``__call__``
+                     method)
+
+    :param args: javascript Array of :class:`py.object`, used as
+                 positional arguments to ``callable``
+
+    :param kwargs: javascript Object mapping names to
+                   :class:`py.object`, used as named arguments to
+                   ``callable``
+
+    :returns: nothing or :class:`py.object`
+
+.. function:: py.PY_isTrue(o)
+
+    Returns ``true`` if the object is considered truthy, ``false``
+    otherwise. Equivalent to ``bool(o)``.
+
+    :param o: A :class:`py.object`
+    :rtype: Boolean
+
+.. function:: py.PY_not(o)
+
+    Inverse of :func:`py.PY_isTrue`.
+
+.. function:: py.PY_size(o)
+
+    If ``o`` is a sequence or mapping, returns its length. Otherwise,
+    raises ``TypeError``.
+
+    :param o: A :class:`py.object`
+    :returns: ``Number``
+    :raises: ``TypeError`` if the object doesn't have a length
+
+Number Protocol
+---------------
+
+.. function:: py.PY_add(o1, o2)
+
+    Returns the result of adding ``o1`` and ``o2``, equivalent to
+    ``o1 + o2``.
+
+    :param o1: :class:`py.object`
+    :param o2: :class:`py.object`
+    :returns: :class:`py.object`
+
+.. function:: py.PY_subtract(o1, o2)
+
+    Returns the result of subtracting ``o2`` from ``o1``, equivalent
+    to ``o1 - o2``.
+
+    :param o1: :class:`py.object`
+    :param o2: :class:`py.object`
+    :returns: :class:`py.object`
+
+.. function:: py.PY_multiply(o1, o2)
+
+    Returns the result of multiplying ``o1`` by ``o2``, equivalent to
+    ``o1 * o2``.
+
+    :param o1: :class:`py.object`
+    :param o2: :class:`py.object`
+    :returns: :class:`py.object`
+
+.. function:: py.PY_divide(o1, o2)
+
+    Returns the result of dividing ``o1`` by ``o2``, equivalent to
+    ``o1 / o2``.
+
+    :param o1: :class:`py.object`
+    :param o2: :class:`py.object`
+    :returns: :class:`py.object`
+
+.. function:: py.PY_negative(o)
+
+    Returns the negation of ``o``, equivalent to ``-o``.
+
+    :param o: :class:`py.object`
+    :returns: :class:`py.object`
+
+.. function:: py.PY_positive(o)
+
+    Returns the "positive" of ``o``, equivalent to ``+o``.
+
+    :param o: :class:`py.object`
+    :returns: :class:`py.object`
+
 .. [#kwonly] Python 2, which py.js currently implements, does not
              support Python-level keyword-only parameters (it can be
              done through the C-API), but it seemed neat and easy