[Zope3-checkins] SVN: Zope3/trunk/src/mechanize/_ make our private copy of mechanize match the patch that I submitted to the

Benji York benji at zope.com
Thu Jun 22 09:50:43 EDT 2006


Log message for revision 68790:
  make our private copy of mechanize match the patch that I submitted to the
  mechanize project
  

Changed:
  U   Zope3/trunk/src/mechanize/_mechanize.py
  U   Zope3/trunk/src/mechanize/_opener.py

-=-
Modified: Zope3/trunk/src/mechanize/_mechanize.py
===================================================================
--- Zope3/trunk/src/mechanize/_mechanize.py	2006-06-22 13:06:30 UTC (rev 68789)
+++ Zope3/trunk/src/mechanize/_mechanize.py	2006-06-22 13:50:42 UTC (rev 68790)
@@ -45,6 +45,18 @@
     def clear(self):
         del self._history[:]
     def close(self):
+        """
+            If nothing has been added, .close should work.
+
+                >>> history = History()
+                >>> history.close()
+
+            Under some circumstances response can be None, in that case
+            this method should not raise an exception.
+
+                >>> history.add(None, None)
+                >>> history.close()
+        """
         for request, response in self._history:
             if response is not None:
                 response.close()

Modified: Zope3/trunk/src/mechanize/_opener.py
===================================================================
--- Zope3/trunk/src/mechanize/_opener.py	2006-06-22 13:06:30 UTC (rev 68789)
+++ Zope3/trunk/src/mechanize/_opener.py	2006-06-22 13:50:42 UTC (rev 68790)
@@ -29,6 +29,26 @@
     return methnames_of_instance_as_dict(obj).keys()
 
 def methnames_of_instance_as_dict(inst):
+    """
+    It is possible for an attribute to be present in the results of dir(inst),
+    but for getattr(inst, attr_name) to raise an Attribute error, that should
+    be handled gracefully.
+
+        >>> class BadAttr(object):
+        ...     def error(self):
+        ...         raise AttributeError
+        ...     error = property(error)
+
+        >>> inst = BadAttr()
+        >>> 'error' in dir(inst)
+        True
+        >>> inst.error
+        Traceback (most recent call last):
+        ...
+        AttributeError
+
+        >>> result = methnames_of_instance_as_dict(inst) # no exception
+    """
     names = {}
     names.update(methnames_of_class_as_dict(inst.__class__))
     for methname in dir(inst):
@@ -41,6 +61,27 @@
     return names
 
 def methnames_of_class_as_dict(klass):
+    """
+    It is possible for an attribute to be present in the results of dir(inst),
+    but for getattr(inst, attr_name) to raise an Attribute error, that should
+    be handled gracefully.
+
+        >>> class BadClass(object):
+        ...     def error(self):
+        ...         raise AttributeError
+        ...     error = property(error)
+        ...     __bases__ = []
+
+        >>> klass = BadClass()
+        >>> 'error' in dir(klass)
+        True
+        >>> klass.error
+        Traceback (most recent call last):
+        ...
+        AttributeError
+
+        >>> result = methnames_of_class_as_dict(klass) # no exception
+    """
     names = {}
     for methname in dir(klass):
         try:



More information about the Zope3-Checkins mailing list