[Zope3-checkins] SVN: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py Rearranged properties and methods to make public API more visible and

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Jul 27 10:20:54 EDT 2005


Log message for revision 37486:
  Rearranged properties and methods to make public API more visible and 
  separate properties and methods.
  

Changed:
  U   Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py

-=-
Modified: Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py	2005-07-27 14:20:41 UTC (rev 37485)
+++ Zope3/branches/testbrowser-integration/src/zope/app/testing/testbrowser/browser.py	2005-07-27 14:20:53 UTC (rev 37486)
@@ -17,36 +17,70 @@
 """
 __docformat__ = "reStructuredText"
 import re
+import mechanize
 import zope.interface
 
 from zope.app.testing.testbrowser import interfaces
 
+
 class Browser(object):
     """A Test Browser based on ``mechanize``."""
     zope.interface.implements(interfaces.IBrowser)
 
     def __init__(self, url=None, mech_browser=None):
         if mech_browser is None:
-            import mechanize
             mech_browser = mechanize.Browser()
-
         self.mech_browser = mech_browser
+        
         if url is not None:
             self.open(url)
 
-    def open(self, url, data=None):
+    @property
+    def url(self):
         """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        self.mech_browser.open(url, data)
+        return self.mech_browser.geturl()
 
-    def addHeader(self, key, value):
+    @property
+    def isHtml(self):
         """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        self.mech_browser.addheaders.append( (key, value) )
+        return self.mech_browser.viewing_html()
 
     @property
-    def url(self):
+    def title(self):
         """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        return self.mech_browser.geturl()
+        return self.mech_browser.title()
 
+    @property
+    def controls(self):
+        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
+        return ControlsMapping(self)
+
+    @property
+    def forms(self):
+        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
+        return FormsMapping(self)
+
+    @property
+    def contents(self):
+        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
+        response = self.mech_browser.response()
+        old_location = response.tell()
+        response.seek(0)
+        for line in iter(lambda: response.readline().strip(), ''):
+            pass
+        contents = response.read()
+        response.seek(old_location)
+        return contents
+
+    @property
+    def headers(self):
+        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
+        return self.mech_browser.response().info()
+
+    def open(self, url, data=None):
+        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
+        self.mech_browser.open(url, data)
+
     def reload(self):
         """See zope.app.testing.testbrowser.interfaces.IBrowser"""
         self.mech_browser.reload()
@@ -57,16 +91,10 @@
         self.mech_browser.back(self, count)
         self._changed()
 
-    @property
-    def isHtml(self):
+    def addHeader(self, key, value):
         """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        return self.mech_browser.viewing_html()
+        self.mech_browser.addheaders.append( (key, value) )
 
-    @property
-    def title(self):
-        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        return self.mech_browser.title()
-
     def click(self, text=None, url=None, id=None, name=None, coord=(1,1)):
         """See zope.app.testing.testbrowser.interfaces.IBrowser"""
         form, control = self._findControl(text, id, name, type='submit')
@@ -95,6 +123,13 @@
                                           url_regex=url_regex)
         self._changed()
 
+    def getControl(self, text):
+        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
+        form, control = self._findControl(text, text, text)
+        if control is None:
+            raise ValueError('could not locate control: ' + text)
+        return Control(control)
+
     def _findControl(self, text, id, name, type=None, form=None):
         for control_form, control in self._controls:
             if form is None or control_form == form:
@@ -131,40 +166,6 @@
                     self.__controls.append( (form, control) )
         return self.__controls
 
-    @property
-    def controls(self):
-        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        return ControlsMapping(self)
-
-    @property
-    def forms(self):
-        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        return FormsMapping(self)
-
-    def getControl(self, text):
-        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        form, control = self._findControl(text, text, text)
-        if control is None:
-            raise ValueError('could not locate control: ' + text)
-        return Control(control)
-
-    @property
-    def contents(self):
-        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        response = self.mech_browser.response()
-        old_location = response.tell()
-        response.seek(0)
-        for line in iter(lambda: response.readline().strip(), ''):
-            pass
-        contents = response.read()
-        response.seek(old_location)
-        return contents
-
-    @property
-    def headers(self):
-        """See zope.app.testing.testbrowser.interfaces.IBrowser"""
-        return self.mech_browser.response().info()
-
     def _changed(self):
         self.__controls = None
 



More information about the Zope3-Checkins mailing list