Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>class Proxy(object): """Proxy class wraps any other class, and adds functionality to remember and report all messages called. Limitations include that proxy blocks all direct subclass calls to: messages, number_of_times_called, was_called, _obj, and _message_counts. These calls must be made directly like my_proxy_instance._obj.messages. """ def __init__(self, target_object): print 'initializing a proxy for ' + target_object.__class__.__name__ # WRITE CODE HERE self._message_counts = Counter(); #initialize '_obj' attribute last. Trust me on this! self._obj = target_object # WRITE CODE HERE def __getattr__(self, attr_name): print 'getting an attribute: "' + attr_name + '" from "' + self._obj.__class__.__name__ + '"' self._message_counts[attr_name] += 1 print self._message_counts return object.__getattribute__(self._obj, attr_name) #def __getattribute__(self, attr_name): # print "intercepted!~ " + attr_name # object.__getattribute__(self, attr_name) def __setattr__(self, attr_name, value): if((attr_name == '_obj') | (attr_name == '_message_counts')): # special proxy attributes. print 'setting the PROXY attribute: "' + attr_name + '"' object.__setattr__(self, attr_name, value) else: print 'setting the REAL attribute: "' + attr_name + '"' self._message_counts[attr_name+"="] += 1 object.__setattr__(self._obj, attr_name, value) def messages(self): return self._message_counts.keys() def number_of_times_called(self, attr_name): return self._message_counts[attr_name] def was_called(self, attr_name): return attr_name in self._message_counts </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload