Skip to content

Commit e9695d2

Browse files
committed
fix + tests
1 parent 3a64844 commit e9695d2

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Lib/test/test_urllib2.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,23 @@ class NonHandler(object):
577577
self.assertRaises(TypeError,
578578
OpenerDirector().add_handler, NonHandler())
579579

580+
def test_no_protocol_methods(self):
581+
# test the case that methods starts with handler type without the protocol
582+
# like open*() or _open*().
583+
# These methods should be ignored
584+
585+
o = OpenerDirector()
586+
meth_spec = [
587+
["open"],
588+
["_open"],
589+
["error"]
590+
]
591+
592+
add_ordered_mock_handlers(o, meth_spec)
593+
594+
self.assertEqual(len(o.handle_open), 0)
595+
self.assertEqual(len(o.handle_error), 0)
596+
580597
def test_badly_named_methods(self):
581598
# test work-around for three methods that accidentally follow the
582599
# naming conventions for handler methods

Lib/urllib/request.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ def add_handler(self, handler):
415415
continue
416416

417417
i = meth.find("_")
418+
if i < 1:
419+
continue
418420
protocol = meth[:i]
419421
condition = meth[i+1:]
420422

0 commit comments

Comments
 (0)