title: Writing a thin object proxy by implementing the __get__ descriptor
body: <p>I'm trying to create a think proxy using the <a href="http://docs.python.org/reference/datamodel.html#object.__get__" rel="nofollow"><code>__get__</code></a> descriptor  over a certain type of data so that it can be used conveniently by client code (best shown with an example):</p>
  
  <pre><code>class Value(object):
      def __init__(self, val):
          self.val = val
      def __get__(self, instance, owner):
          return self.val
  
  class Container(object):
      x = Value(1)
      y = [ Value(2), Value(3) ]
  
  c = Container()
  assert c.x == 1
  assert c.y[0] == 2 # fails.
  </code></pre>
  
  <p>Now, I mostly see why it fails, so I'm wondering if theres a better way to achieve my goal which is wrap up the data so that when the client accesses it they simply have to access the Value object directly (in reality, the <code>__get__</code> method would do something with <code>self.val</code> before returning it)</p>
  
  <h2>Details</h2>
  
  <p>The actual case I'm trying to tackle is utility code to assist in writing <a href="http://code.google.com/p/selenium/wiki/PageObjects" rel="nofollow">PageObjects</a> &amp; PageElements for selenium test cases. What I want to provide is a clean and simple way for test authors to write PageObjects of the form:</p>
  
  <pre><code>class MyLogin(PageObject):
      username_text_box = PageElement(By.ID, "username")
      password_text_box = PageElement(By.ID, "password")
      submit_button = PageElement(By.CLASS_NAME, "login-button")
  
  driver = webdriver.Firefox()
  driver.get("http://mypage.com")
  login_page = MyLogin(driver)
  login_page.username_text_box.send_keys("username01")
  login_page.password_text_box.send_keys("XXXX")
  login_page.submit_button.click()
  </code></pre>
  
  <p>I'm trying to encapsulate the business of fetching the actual <a href="http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html" rel="nofollow">WebElement</a> inside the PageElement class and I want to allow the client to have access to the WebElement once they access the PageElement Object. Being able to have lists, dictionaries assists in making the PageObject instance clearer and to group related PageElements.</p>