Commits

ariovistus committed 549210d

Edited online

Comments (0)

Files changed (1)

 ===Authors===
 >Kirk McDonald
 ===See also===
-[[http://docs.python.org/api/api.html|The Python/C API]]
+[[http://docs.python.org/api/api.html|The Python/C API]]\\
+[[http://ariovistus.bitbucket.org/pyd/pydobject.html|The Pyd API]]
 ===Table of Contents===
 <<toc PydObject>>
 
 ==PydObject==
-{{{
-#!d
-this(PyObject* o);
-}}}
-    Wrap around a passed PyObject*. 
-* **o**: The PyObject to wrap. Always an owned reference.
-{{{
-#!d
-this(PyObject_BorrowedRef* o);
-}}}
-    Wrap around a borrowed PyObject*. 
-* **o**: The PyObject to wrap. PydObjects always own their references, so Py_INCREF will be called.
-{{{
-#!d
-this();
-}}}
-The default constructor constructs an instance of the Py_None PydObject.
-PyObject_BorrowedRef* ptr();
-    Returns a borrowed reference to the PyObject.
-{{{
-#!d
-bool hasattr(string attr_name);
-}}}
-    Same as hasattr(this, attr_name) in Python.
-{{{
-#!d
-bool hasattr(PydObject attr_name);
-}}}
-    Same as hasattr(this, attr_name) in Python.
-{{{
-#!d
-PydObject getattr(string attr_name);
-}}}
-    Same as getattr(this, attr_name) in Python.
-{{{
-#!d
-PydObject getattr(PydObject attr_name);
-}}}
-    Same as getattr(this, attr_name) in Python.
-{{{
-#!d
-void setattr(string attr_name, PydObject v);
-}}}
-    Same as setattr(this, attr_name, v) in Python.
-{{{
-#!d
-void setattr(PydObject attr_name, PydObject v);
-}}}
-    Same as setattr(this, attr_name, v) in Python.
-{{{
-#!d
-void delattr(string attr_name);
-}}}
-    Same as del this.attr_name in Python.
-{{{
-#!d
-void delattr(PydObject attr_name);
-}}}
-    Same as del this.attr_name in Python.
-{{{
-#!d
-int opCmp(Object rhs);
-}}}
-    Exposes Python object comparison to D. Same as cmp(this, rhs) in Python. 
-{{{
-#!d
-bool opEquals(Object rhs); 
-}}}
-Exposes Python object equality check to D. 
-{{{
-#!d
-PydObject repr();
-}}}
-Same as repr(this) in Python. 
-{{{
-#!d
-PydObject str(); 
-}}}
-Same as str(this) in Python. 
-{{{
-#!d
-string toString(); 
-}}}
-Allows use of PydObject in writef via %s 
-{{{
-#!d
-PydObject unicode(); 
-}}}
-Same as unicode(this) in Python. 
-{{{
-#!d
-bool isInstance(PydObject cls); 
-}}}
-Same as isinstance(this, cls) in Python. 
-{{{
-#!d
-bool isSubclass(PydObject cls); 
-}}}
-Same as issubclass(this, cls) in Python. Only works if this is a class. 
-{{{
-#!d
-bool callable(); 
-}}}
-Same as callable(this) in Python. 
-{{{
-#!d
-PydObject unpackCall(PydObject args=null);
-}}}
-Calls the PydObject with the PyTuple args.
-Params:
-* **args**: Should be a PydTuple of the arguments to pass. Omit to call with no arguments.
-Returns: Whatever the function PydObject returns.
-{{{
-#!d
-PydObject unpackCall(PydObject args, PydObject kw);
-}}}
- Calls the PydObject with positional and keyword arguments.
-
-* **args**: Positional arguments. Should be a PydTuple. Pass an empty PydTuple for no positional arguments.
-* **kw**: Keyword arguments. Should be a PydDict.
-Returns: Whatever the function PydObject returns. 
-{{{
-#!d
-PydObject opCall(T ...) (T t);
-}}}
-Calls the PydObject with any convertible D items.
-{{{
-#!d
-PydObject methodUnpack(string name, PydObject args=null)
-}}}
-??
-{{{
-#!d
-PydObject methodUnpack(string name, PydObject args, PydObject kw);
-}}}
-??
-{{{
-#!d
-PydObject method(T ...) (string name, T t);
-}}}
-Calls a method of the object with any convertible D items.
-{{{
-#!d
-hash_t hash()
-}}}
-Same as _hash(this) in Python.
-{{{
-#!d
-T toDItem(T)();
-}}}
-Converts this PydObject to instance of T, if possible.
-{{{
-#!d
-bool toBool(); 
-}}}
-Same as "not not this" in Python. 
-{{{
-#!d
-bool not(); 
-}}}
-Same as "not this" in Python. 
-{{{
-#!d
-PydObject type(); 
-}}}
-Gets the type of this PydObject. Same as type(this) in Python.
-
-Returns: The type PydObject of this PydObject. 
-{{{
-#!d
-Py_ssize_t length();
-Py_ssize_t size();
-}}}
-The length of this PydObject. Same as len(this) in Python. 
-{{{
-#!d
-PydObject dir(); 
-}}}
-Same as dir(this) in Python. 
-===Indexing=== 
-<<Anchor(Indexing)>>
-{{{
-#!d
-PydObject opIndex(PydObject key);
-PydObject opIndex(string key);
-PydObject opIndex(int i);
-}}}
-Equivalent to o[key] in Python. 
-{{{
-#!d
-void opIndexAssign(T,S)(T value, S key)
-}}}
-Equivalent to o[key] = value in Python.
-* **T**: Any convertible D type.
-* **S**: Any convertible D type.
-{{{
-#!d
-void delItem(PydObject key); 
-void delItem(string key);
-void delItem(int key);
-}}}
-Equivalent to del o[key] in Python. 
-{{{
-#!d
-PydObject opSlice(Py_ssize_t i1, Py_ssize_t i2);
-}}}
-Equivalent to o[i1:i2] in Python.
-{{{
-#!d
-PydObject opSlice();
-}}}
-Equivalent to o[:] in Python. 
-{{{
-#!d
-void opSliceAssign(PydObject v, Py_ssize_t i1, Py_ssize_t i2);
-}}}
-Equivalent to o[i1:i2] = v in Python.
-{{{
-#!d
-void opSliceAssign(PydObject v);
-}}}
-Equivalent to o[:] = v in Python. 
-{{{
-#!d
-void delSlice(Py_ssize_t i1, Py_ssize_t i2);
-}}}
-Equivalent to del o[i1:i2] in Python.
-{{{
-#!d
-void delSlice(); 
-}}}
-Equivalent to del o[:] in Python.
-===Iteration===
-{{{
-#!d
-int opApply(int delegate(ref PydObject) dg);
-}}}
-Iterates over the items in a collection, be they the items in a sequence, keys in a dictionary, or some other iteration defined for the PydObject's type. 
-{{{
-#!d
-int opApply(int delegate(ref PydObject, ref PydObject) dg);
-}}}
-Iterate over (key, value) pairs in a dictionary. If the PydObject is not a dict, this simply does nothing. (It iterates over no items.) You should not attempt to modify the dictionary while iterating through it, with the exception of modifying values. Adding or removing items while iterating through it is an especially bad idea.
-
 ===Arithmetic===
+The following operators are supported for T a convertible D type and me a python object that supports the corresponding operator overload.
 {{{
 #!d
 PydObject me, p;
 p = -me;
 p = ~me;
 }}}
-All supported for T a convertible D type and me a python object that supports the corresponding operator overload.
 
-{{{
-#!d
-PydObject floorDiv(PydObject o); 
-}}}
-"classic" integer division
-{{{
-#!d
-PydObject trueDiv(PydObject o);
-}}}
-floating point division (?)
-{{{
-#!d
-PydObject divmod(PydObject o);
-}}}
-Equivalent to divmod(this, o)
-{{{
-#!d
-PydObject pow(PydObject o1, PydObject o2=null)
-}}}
-Equivalent to pow(this, o1[, o2]);
-{{{
-#!d
-PydObject abs();
-}}}
-Equivalent to abs(this)
 ===In-place Arithmetic===
-
+The following in-place operators supported for T a convertible D type and me a python object that supports the corresponding operator overload.
 {{{
 #!d
 PydObject me, p;
 p = me |= t;
 p = me ~= t; // same as me += t in python 
 }}}
-All supported for T a convertible D type and me a python object that supports the corresponding operator overload.
+
 
 === Type Conversion===
 {{{
 C_longlong toLongLong();
 double toDouble();
 cdouble toComplex();
-}}}
-===Sequence methods===
-{{{
-#!d
-Py_ssize_t count(PydObject v);
-Py_ssize_t index(PydObject v);
+T toDItem!(T)(T t);
 }}}
 
-{{{
-#!d
-PydObject asList();
-}}}
-Converts any iterable PydObject to a list 
-{{{
-#!d
-PydObject asTuple();
-}}}
-Converts any iterable PydObject to a tuple
-{{{
-#!d
-void insert(int i, PydObject item);
-}}}
-Equivalent to thislist.insert(i,item)
-{{{
-#!d
-void append(PydObject item)
-}}}
-Equivalent to thislist.append(item)
-{{{
-#!d
-void sort();
-}}}
-Equivalent to thislist.sort()
-{{{
-#!d
-void reverse()
-}}}
-Equivalent to thislist.reverse()
-===Mapping Methods===
-{{{
-#!d
-PydObject me;
-T p;
-bool f;
 
-f = p in me; 
-f = me.hasKey(p);
-}}}
-Equivalent to 'f = p in me' in python. T can be PydObject or string.
-{{{
-#!d
-PydObject keys();
-}}}
-Equivalent to thismapping.keys()
-{{{
-#!d
-PydObject values();
-}}}
-Equivalent to thismapping.values()
-
-{{{
-#!d
-PydObject items();
-}}}
-Equivalent to thismapping.items()
-{{{
-#!d
-void clear();
-}}}
-Equivalent to thisdict.clear()
-{{{
-#!d
-PydObject copy();
-}}}
-Equivalent to thisdict.copy()
-{{{
-#!d
-void merge(PydObject o, bool override_=true);
-}}}
-Equivalent to thisdict.merge(o, override_)
-{{{
-#!d
-PydObject getdict();
-}}}
-Equivalent to thismodule.getdict() 
-