Back to index

python3.2  3.2.2
Public Member Functions
test.test_urllib2.MiscTests Class Reference

List of all members.

Public Member Functions

def test_build_opener
def opener_has_handler

Detailed Description

Definition at line 1309 of file test_urllib2.py.


Member Function Documentation

def test.test_urllib2.MiscTests.opener_has_handler (   self,
  opener,
  handler_class 
)

Definition at line 1348 of file test_urllib2.py.

01348 
01349     def opener_has_handler(self, opener, handler_class):
01350         self.assertTrue(any(h.__class__ == handler_class
01351                             for h in opener.handlers))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1311 of file test_urllib2.py.

01311 
01312     def test_build_opener(self):
01313         class MyHTTPHandler(urllib.request.HTTPHandler): pass
01314         class FooHandler(urllib.request.BaseHandler):
01315             def foo_open(self): pass
01316         class BarHandler(urllib.request.BaseHandler):
01317             def bar_open(self): pass
01318 
01319         build_opener = urllib.request.build_opener
01320 
01321         o = build_opener(FooHandler, BarHandler)
01322         self.opener_has_handler(o, FooHandler)
01323         self.opener_has_handler(o, BarHandler)
01324 
01325         # can take a mix of classes and instances
01326         o = build_opener(FooHandler, BarHandler())
01327         self.opener_has_handler(o, FooHandler)
01328         self.opener_has_handler(o, BarHandler)
01329 
01330         # subclasses of default handlers override default handlers
01331         o = build_opener(MyHTTPHandler)
01332         self.opener_has_handler(o, MyHTTPHandler)
01333 
01334         # a particular case of overriding: default handlers can be passed
01335         # in explicitly
01336         o = build_opener()
01337         self.opener_has_handler(o, urllib.request.HTTPHandler)
01338         o = build_opener(urllib.request.HTTPHandler)
01339         self.opener_has_handler(o, urllib.request.HTTPHandler)
01340         o = build_opener(urllib.request.HTTPHandler())
01341         self.opener_has_handler(o, urllib.request.HTTPHandler)
01342 
01343         # Issue2670: multiple handlers sharing the same base class
01344         class MyOtherHTTPHandler(urllib.request.HTTPHandler): pass
01345         o = build_opener(MyHTTPHandler, MyOtherHTTPHandler)
01346         self.opener_has_handler(o, MyHTTPHandler)
01347         self.opener_has_handler(o, MyOtherHTTPHandler)

Here is the call graph for this function:


The documentation for this class was generated from the following file: