[wwwsearch-commits] r27804 - in wwwsearch/mechanize/trunk: mechanize test
jjlee at codespeak.net
jjlee at codespeak.net
Sun May 28 23:17:48 CEST 2006
Author: jjlee
Date: Sun May 28 23:17:47 2006
New Revision: 27804
Modified:
wwwsearch/mechanize/trunk/mechanize/_opener.py
wwwsearch/mechanize/trunk/test/test_urllib2.py
Log:
Get rid of dir()-replacement :-)
Modified: wwwsearch/mechanize/trunk/mechanize/_opener.py
==============================================================================
--- wwwsearch/mechanize/trunk/mechanize/_opener.py (original)
+++ wwwsearch/mechanize/trunk/mechanize/_opener.py Sun May 28 23:17:47 2006
@@ -20,34 +20,6 @@
import sets
set = sets.Set
-def methnames(obj):
- """Return method names of class instance.
-
- dir(obj) doesn't work across Python versions, this does.
-
- """
- return methnames_of_instance_as_dict(obj).keys()
-
-def methnames_of_instance_as_dict(inst):
- names = {}
- names.update(methnames_of_class_as_dict(inst.__class__))
- for methname in dir(inst):
- candidate = getattr(inst, methname)
- if callable(candidate):
- names[methname] = None
- return names
-
-def methnames_of_class_as_dict(klass):
- names = {}
- for methname in dir(klass):
- candidate = getattr(klass, methname)
- if callable(candidate):
- names[methname] = None
- for baseclass in klass.__bases__:
- names.update(methnames_of_class_as_dict(baseclass))
- return names
-
-
class OpenerDirector(urllib2.OpenerDirector):
def __init__(self):
urllib2.OpenerDirector.__init__(self)
@@ -81,7 +53,7 @@
for handler in self.handlers:
added = False
- for meth in methnames(handler):
+ for meth in dir(handler):
if meth in ["redirect_request", "do_open", "proxy_open"]:
# oops, coincidental match
continue
Modified: wwwsearch/mechanize/trunk/test/test_urllib2.py
==============================================================================
--- wwwsearch/mechanize/trunk/test/test_urllib2.py (original)
+++ wwwsearch/mechanize/trunk/test/test_urllib2.py Sun May 28 23:17:47 2006
@@ -1079,36 +1079,6 @@
else:
self.assert_(False)
- def _methnames(self, *objs):
- from mechanize._opener import methnames
- r = []
- for i in range(len(objs)):
- obj = objs[i]
- names = methnames(obj)
- names.sort()
- # special methods vary over Python versions
- names = filter(lambda mn: mn[0:2] != "__" , names)
- r.append(names)
- return r
-
- def test_methnames(self):
- a, b, c, d = A(), B(), C(), D()
- a, b, c, d = self._methnames(a, b, c, d)
- self.assert_(a == ["a"])
- self.assert_(b == ["a", "b"])
- self.assert_(c == ["a", "c"])
- self.assert_(d == ["a", "b", "c", "d"])
-
- a, b, c, d = A(), B(), C(), D()
- a.x = lambda self: None
- b.y = lambda self: None
- d.z = lambda self: None
- a, b, c, d = self._methnames(a, b, c, d)
- self.assert_(a == ["a", "x"])
- self.assert_(b == ["a", "b", "y"])
- self.assert_(c == ["a", "c"])
- self.assert_(d == ["a", "b", "c", "d", "z"])
-
if __name__ == "__main__":
unittest.main()
More information about the wwwsearch-commits
mailing list