PydObject

Wrapper class for a Python/C API PyObject.

Nearly all of these member functions may throw a PythonException if the underlying Python API raises a Python exception.

class PydObject {}

Constructors

this
this(PyObject* o)

Wrap an owned PyObject*. This should typically only be used in conjuction with functions in the deimos API that return PyObject* (they return new references). Otherwise, wrap the incoming PyObject* with borrowed.

this
this(Borrowed!PyObject* o)

Own a borrowed PyObject* and wrap it.

this
this()

Constructs an instance of the Py_None PydObject.

Destructor

~this
~this()

Destructor. Calls Py_DECREF on PyObject reference.

Members

Classes

BufferView
class BufferView

exposes a lowish-level wrapper of the new-style buffer interface

Functions

abs
PydObject abs()

Equivalent to abs(this) for numbers, and this.abs() otherwise.

append
void append(PydObject item)

Equivalent to 'this.append(item)' in python.

as_float
PydObject as_float()

Converts any Python number to float.

as_int
PydObject as_int()

Converts any Python number to int.

as_list
PydObject as_list()

Converts any iterable PydObject to a list

as_long
PydObject as_long()

Converts any Python number to long.

as_tuple
PydObject as_tuple()

Converts any iterable PydObject to a tuple

buffer_view
BufferView buffer_view()

Get a BufferView of this object. Will fail if this does not support the new buffer interface.

buffer_view
BufferView buffer_view(int flags)

Get a BufferView of this object without probing for capabilities. Will fail if this does not support the new buffer interface.

bytes
PydObject bytes()

Equivalent to bytes(this) in Python.

callable
bool callable()

Equivalent to callable(this) in Python.

clear
void clear()

For dicts, wraps PyDict_Clear. Otherwise forwards to method.

copy
PydObject copy()

For dicts, wraps PyDict_Copy. Otherwise forwards to method.

count
Py_ssize_t count(PydObject v)

Equivalent to 'this.count(v)' in Python.

del_item
void del_item(PydObject key)

Equivalent to del o_key in Python.

del_item
void del_item(string key)

Equivalent to del o['_key'] in Python. Usually only makes sense for mappings.

del_item
void del_item(int i)

Equivalent to del o_i in Python. Usually only makes sense for sequences.

del_slice
void del_slice(Py_ssize_t i1, Py_ssize_t i2)

Equivalent to del o[_i1:_i2] in Python.

del_slice
void del_slice()

Equivalent to del o[:] in Python.

delattr
void delattr(string attr_name)

Equivalent to del this.attr_name in Python.

delattr
void delattr(PydObject attr_name)

Equivalent to del this.attr_name in Python.

dir
PydObject dir()

Equivalent to dir(this) in Python.

divmod
PydObject divmod(PydObject o)

Equivalent to divmod(this, o) for numbers, and this.divmod(o) otherwise.

floor_div
PydObject floor_div(PydObject o)

Forwards to PyNumber_FloorDivide for numbers, and method otherwise.

getattr
PydObject getattr(string attr_name)

Equivalent to getattr(this, attr_name) in Python.

getattr
PydObject getattr(PydObject attr_name)

Equivalent to getattr(this, attr_name) in Python.

getdict
PydObject getdict()

For module objects, wraps PyModule_GetDict (essentially a dir() operation in Python). Otherwise forwards to method.

has_key
bool has_key(string key)
bool has_key(PydObject key)

Equivalent to 'key in this' in Python.

hasattr
bool hasattr(string attr_name)

Equivalent to hasattr(this, attr_name) in Python.

hasattr
bool hasattr(PydObject attr_name)

Equivalent to hasattr(this, attr_name) in Python.

hash
hash_t hash()

Equivalent to hash(this) in Python.

index
Py_ssize_t index(PydObject v)

Equivalent to 'this.index(v)' in Python

insert
void insert(int i, PydObject item)

Equivalent to 'this.insert(i,item)' in python.

isinstance
bool isinstance(PydObject cls)

Equivalent to isinstance(this, cls) in Python.

issubclass
bool issubclass(PydObject cls)

Equivalent to issubclass(this, cls) in Python. Only works if this is a class.

items
PydObject items()

Equivalent to 'this.items()' in Python.

keys
PydObject keys()

Equivalent to 'this.keys()' in Python.

length
Py_ssize_t length()

The length of this PydObject. Equivalent to _len(this) in Python.

merge
void merge(PydObject o, bool override_)

For dicts, wraps PyDict_Merge. Otherwise forwards to method.

method
PydObject method(string name, T t)

Calls a method of the object with any convertible D items.

method_unpack
PydObject method_unpack(string name, PydObject args)

Calls the PydObject method with args.

method_unpack
PydObject method_unpack(string name, PydObject args, PydObject kw)

Calls the PydObject method with positional and keyword arguments.

not
bool not()

Equivalent to "not this" in Python.

opApply
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.

opApply
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.

opBinary
PydObject opBinary(T o)

Forwards to appropriate Python binary operator overload.

opBinaryRight
bool opBinaryRight(T v)
bool opBinaryRight(T key)

Equivalent to "v in this" in Python.

opCall
PydObject opCall(T t)

Calls the PydObject with any convertible D items.

opCmp
int opCmp(Object o)

Exposes Python object comparison to D. Equivalent to cmp(this, rhs) in Python.

opDispatch
auto opDispatch(T ts)

Forwards to method.

opEquals
bool opEquals(Object o)

Exposes Python object equality check to D.

opIndex
PydObject opIndex(PydObject key)

Equivalent to o_key in Python.

opIndex
PydObject opIndex(string key)

Equivalent to o['_key'] in Python; usually only makes sense for mappings.

opIndex
PydObject opIndex(Py_ssize_t i)

Equivalent to o_i in Python; usually only makes sense for sequences.

opIndexAssign
void opIndexAssign(T value, S key)

Equivalent to o_key = _value in Python.

opOpAssign
PydObject opOpAssign(T o)

Forwards to appropriate python in-place operator overload.

opSlice
PydObject opSlice(Py_ssize_t i1, Py_ssize_t i2)

Equivalent to o[_i1:_i2] in Python.

opSlice
PydObject opSlice()

Equivalent to o[:] in Python.

opSliceAssign
void opSliceAssign(PydObject v, Py_ssize_t i1, Py_ssize_t i2)

Equivalent to o[_i1:_i2] = _v in Python.

opSliceAssign
void opSliceAssign(PydObject v)

Equivalent to o[:] = _v in Python.

opUnary
PydObject opUnary()

Forwards to appropriate Python unary operator overload.

pow
PydObject pow(PydObject exp, PydObject mod)

Equivalent to pow(this, exp, mod) for numbers, and this.pow(exp,mod) otherwise.

repr
PydObject repr()

Equivalent to repr(this) in Python.

reverse
void reverse()

Equivalent to 'this.reverse()' in Python.

setattr
void setattr(string attr_name, PydObject v)

Equivalent to setattr(this, attr_name, v) in Python.

setattr
void setattr(PydObject attr_name, PydObject v)

Equivalent to setattr(this, attr_name, v) in Python.

size
Py_ssize_t size()

Equivalent to length()

sort
void sort()

Equivalent to 'this.sort()' in Python.

str
PydObject str()

Equivalent to str(this) in Python.

toString
string toString()

Allows use of PydObject in writeln via %s

to_d
T to_d()

Convert this object to instance of T.

true_div
PydObject true_div(PydObject o)

Forwards to PyNumber_TrueDivide for numbers, and method otherwise.

type
PydObject type()

Gets the type of this PydObject. Equivalent to type(this) in Python.

unicode
PydObject unicode()

Equivalent to unicode(this) in Python.

unpack_call
PydObject unpack_call(PydObject args)

Calls the PydObject with args.

unpack_call
PydObject unpack_call(PydObject args, PydObject kw)

Calls the PydObject with positional and keyword arguments.

values
PydObject values()

Equivalent to 'this.values()' in Python.

Properties

opDispatch
auto opDispatch [@property getter]

Forwards to getattr

opDispatch
T opDispatch [@property setter]

Forwards to setattr

ptr
Borrowed!PyObject* ptr [@property getter]

Returns a borrowed reference to the PyObject.

Variables

m_ptr
PyObject* m_ptr;
Undocumented in source.

See Also

Meta

Date

Date: June 18, 2006