| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html><head><title>Python: module pydispatch.saferef</title> |
| 3 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 4 | </head><body bgcolor="#f0f0f8"> |
| 5 | |
| 6 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
| 7 | <tr bgcolor="#7799ee"> |
| 8 | <td valign=bottom> <br> |
| 9 | <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="pydispatch.html"><font color="#ffffff">pydispatch</font></a>.saferef</strong></big></big></font></td |
| 10 | ><td align=right valign=bottom |
| 11 | ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/mcfletch/OpenGL-dev/pydispatcher/pydispatch/saferef.py">/home/mcfletch/OpenGL-dev/pydispatcher/pydispatch/saferef.py</a></font></td></tr></table> |
| 12 | <p><tt>Refactored "safe reference" from dispatcher.py</tt></p> |
| 13 | <p> |
| 14 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 15 | <tr bgcolor="#aa55cc"> |
| 16 | <td colspan=3 valign=bottom> <br> |
| 17 | <font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
| 18 | |
| 19 | <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
| 20 | <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="sys.html">sys</a><br> |
| 21 | </td><td width="25%" valign=top><a href="traceback.html">traceback</a><br> |
| 22 | </td><td width="25%" valign=top><a href="weakref.html">weakref</a><br> |
| 23 | </td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
| 24 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 25 | <tr bgcolor="#ee77aa"> |
| 26 | <td colspan=3 valign=bottom> <br> |
| 27 | <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
| 28 | |
| 29 | <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
| 30 | <td width="100%"><dl> |
| 31 | <dt><font face="helvetica, arial"><a href="builtins.html#object">object</a> |
| 32 | </font></dt><dd> |
| 33 | <dl> |
| 34 | <dt><font face="helvetica, arial"><a href="pydispatch.saferef.html#BoundMethodWeakref">BoundMethodWeakref</a> |
| 35 | </font></dt></dl> |
| 36 | </dd> |
| 37 | </dl> |
| 38 | <p> |
| 39 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 40 | <tr bgcolor="#ffc8d8"> |
| 41 | <td colspan=3 valign=bottom> <br> |
| 42 | <font color="#000000" face="helvetica, arial"><a name="BoundMethodWeakref">class <strong>BoundMethodWeakref</strong></a>(<a href="builtins.html#object">object</a>)</font></td></tr> |
| 43 | |
| 44 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 45 | <td colspan=2><tt><a href="#BoundMethodWeakref">BoundMethodWeakref</a>(target, onDelete=None, *arguments, **named)<br> |
| 46 | <br> |
| 47 | 'Safe' and reusable weak references to instance methods<br> |
| 48 | <br> |
| 49 | <a href="#BoundMethodWeakref">BoundMethodWeakref</a> objects provide a mechanism for<br> |
| 50 | referencing a bound method without requiring that the<br> |
| 51 | method <a href="builtins.html#object">object</a> itself (which is normally a transient<br> |
| 52 | <a href="builtins.html#object">object</a>) is kept alive. Instead, the <a href="#BoundMethodWeakref">BoundMethodWeakref</a><br> |
| 53 | <a href="builtins.html#object">object</a> keeps weak references to both the <a href="builtins.html#object">object</a> and the<br> |
| 54 | function which together define the instance method.<br> |
| 55 | <br> |
| 56 | Attributes:<br> |
| 57 | key -- the identity key for the reference, calculated<br> |
| 58 | by the class's calculateKey method applied to the<br> |
| 59 | target instance method<br> |
| 60 | deletionMethods -- sequence of callable objects taking<br> |
| 61 | single argument, a reference to this <a href="builtins.html#object">object</a> which<br> |
| 62 | will be called when *either* the target <a href="builtins.html#object">object</a> or<br> |
| 63 | target function is garbage collected (i.e. when<br> |
| 64 | this <a href="builtins.html#object">object</a> becomes invalid). These are specified<br> |
| 65 | as the onDelete parameters of safeRef calls.<br> |
| 66 | weakSelf -- weak reference to the target <a href="builtins.html#object">object</a><br> |
| 67 | weakFunc -- weak reference to the target function<br> |
| 68 | <br> |
| 69 | Class Attributes:<br> |
| 70 | _allInstances -- class attribute pointing to all live<br> |
| 71 | <a href="#BoundMethodWeakref">BoundMethodWeakref</a> objects indexed by the class's<br> |
| 72 | <a href="#BoundMethodWeakref-calculateKey">calculateKey</a>(target) method applied to the target<br> |
| 73 | objects. This weak value dictionary is used to<br> |
| 74 | short-circuit creation so that multiple references<br> |
| 75 | to the same (<a href="builtins.html#object">object</a>, function) pair produce the<br> |
| 76 | same <a href="#BoundMethodWeakref">BoundMethodWeakref</a> instance.<br> </tt></td></tr> |
| 77 | <tr><td> </td> |
| 78 | <td width="100%">Methods defined here:<br> |
| 79 | <dl><dt><a name="BoundMethodWeakref-__bool__"><strong>__bool__</strong></a> = <a href="#BoundMethodWeakref-__nonzero__">__nonzero__</a>(self)</dt></dl> |
| 80 | |
| 81 | <dl><dt><a name="BoundMethodWeakref-__call__"><strong>__call__</strong></a>(self)</dt><dd><tt>Return a strong reference to the bound method<br> |
| 82 | <br> |
| 83 | If the target cannot be retrieved, then will<br> |
| 84 | return None, otherwise returns a bound instance<br> |
| 85 | method for our <a href="builtins.html#object">object</a> and function.<br> |
| 86 | <br> |
| 87 | Note:<br> |
| 88 | You may call this method any number of times,<br> |
| 89 | as it does not invalidate the reference.</tt></dd></dl> |
| 90 | |
| 91 | <dl><dt><a name="BoundMethodWeakref-__cmp__"><strong>__cmp__</strong></a>(self, other)</dt><dd><tt>Compare with another reference</tt></dd></dl> |
| 92 | |
| 93 | <dl><dt><a name="BoundMethodWeakref-__init__"><strong>__init__</strong></a>(self, target, onDelete=None)</dt><dd><tt>Return a weak-reference-like instance for a bound method<br> |
| 94 | <br> |
| 95 | target -- the instance-method target for the weak<br> |
| 96 | reference, must have <im_self> and <im_func> attributes<br> |
| 97 | and be reconstructable via:<br> |
| 98 | target.<im_func>.__get__( target.<im_self> )<br> |
| 99 | which is true of built-in instance methods.<br> |
| 100 | onDelete -- optional callback which will be called<br> |
| 101 | when this weak reference ceases to be valid<br> |
| 102 | (i.e. either the <a href="builtins.html#object">object</a> or the function is garbage<br> |
| 103 | collected). Should take a single argument,<br> |
| 104 | which will be passed a pointer to this <a href="builtins.html#object">object</a>.</tt></dd></dl> |
| 105 | |
| 106 | <dl><dt><a name="BoundMethodWeakref-__nonzero__"><strong>__nonzero__</strong></a>(self)</dt><dd><tt>Whether we are still a valid reference</tt></dd></dl> |
| 107 | |
| 108 | <dl><dt><a name="BoundMethodWeakref-__repr__"><strong>__repr__</strong></a> = <a href="#BoundMethodWeakref-__str__">__str__</a>(self)</dt></dl> |
| 109 | |
| 110 | <dl><dt><a name="BoundMethodWeakref-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>Give a friendly representation of the <a href="builtins.html#object">object</a></tt></dd></dl> |
| 111 | |
| 112 | <hr> |
| 113 | Class methods defined here:<br> |
| 114 | <dl><dt><a name="BoundMethodWeakref-calculateKey"><strong>calculateKey</strong></a>(target)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">type</a></font></font></dt><dd><tt>Calculate the reference key for this reference<br> |
| 115 | <br> |
| 116 | Currently this is a two-tuple of the id()'s of the<br> |
| 117 | target <a href="builtins.html#object">object</a> and the target function respectively.</tt></dd></dl> |
| 118 | |
| 119 | <hr> |
| 120 | Static methods defined here:<br> |
| 121 | <dl><dt><a name="BoundMethodWeakref-__new__"><strong>__new__</strong></a>(cls, target, onDelete=None, *arguments, **named)</dt><dd><tt>Create new instance or return current instance<br> |
| 122 | <br> |
| 123 | Basically this method of construction allows us to<br> |
| 124 | short-circuit creation of references to already-<br> |
| 125 | referenced instance methods. The key corresponding<br> |
| 126 | to the target is calculated, and if there is already<br> |
| 127 | an existing reference, that is returned, with its<br> |
| 128 | deletionMethods attribute updated. Otherwise the<br> |
| 129 | new instance is created and registered in the table<br> |
| 130 | of already-referenced methods.</tt></dd></dl> |
| 131 | |
| 132 | <hr> |
| 133 | Data descriptors defined here:<br> |
| 134 | <dl><dt><strong>__dict__</strong></dt> |
| 135 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 136 | </dl> |
| 137 | <dl><dt><strong>__weakref__</strong></dt> |
| 138 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 139 | </dl> |
| 140 | </td></tr></table></td></tr></table><p> |
| 141 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 142 | <tr bgcolor="#eeaa77"> |
| 143 | <td colspan=3 valign=bottom> <br> |
| 144 | <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> |
| 145 | |
| 146 | <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> |
| 147 | <td width="100%"><dl><dt><a name="-safeRef"><strong>safeRef</strong></a>(target, onDelete=None)</dt><dd><tt>Return a *safe* weak reference to a callable target<br> |
| 148 | <br> |
| 149 | target -- the <a href="builtins.html#object">object</a> to be weakly referenced, if it's a<br> |
| 150 | bound method reference, will create a <a href="#BoundMethodWeakref">BoundMethodWeakref</a>,<br> |
| 151 | otherwise creates a simple weakref.<br> |
| 152 | onDelete -- if provided, will have a hard reference stored<br> |
| 153 | to the callable to be called after the safe reference<br> |
| 154 | goes out of scope with the reference <a href="builtins.html#object">object</a>, (either a<br> |
| 155 | weakref or a <a href="#BoundMethodWeakref">BoundMethodWeakref</a>) as argument.</tt></dd></dl> |
| 156 | </td></tr></table><p> |
| 157 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 158 | <tr bgcolor="#55aa55"> |
| 159 | <td colspan=3 valign=bottom> <br> |
| 160 | <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| 161 | |
| 162 | <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
| 163 | <td width="100%"><strong>__cached__</strong> = '/home/mcfletch/OpenGL-dev/pydispatcher/pydispatch/__pycache__/saferef.cpython-310.pyc'<br> |
| 164 | <strong>__file__</strong> = '/home/mcfletch/OpenGL-dev/pydispatcher/pydispatch/saferef.py'<br> |
| 165 | <strong>__loader__</strong> = <_frozen_importlib_external.SourceFileLoader object><br> |
| 166 | <strong>__name__</strong> = 'pydispatch.saferef'<br> |
| 167 | <strong>__package__</strong> = 'pydispatch'<br> |
| 168 | <strong>__spec__</strong> = ModuleSpec(name='pydispatch.saferef', loader=<_f...h/OpenGL-dev/pydispatcher/pydispatch/saferef.py')<br> |
| 169 | <strong>im_func</strong> = '__func__'<br> |
| 170 | <strong>im_self</strong> = '__self__'</td></tr></table> |
| 171 | </body></html> |