@@ -608,23 +608,39 @@ OpenerDirector Objects
608608
609609 *handler * should be an instance of :class: `BaseHandler `. The following methods
610610 are searched, and added to the possible chains (note that HTTP errors are a
611- special case).
611+ special case). Note that, in the following, *protocol * should be replaced
612+ with the actual protocol to handle, for example :meth: `http_response ` would
613+ be the HTTP protocol response handler. Also *type * should be replaced with
614+ the actual HTTP code, for example :meth: `http_error_404 ` would handle HTTP
615+ 404 errors.
612616
613- * :meth: `protocol_open ` --- signal that the handler knows how to open *protocol *
617+ * :meth: `<protocol>_open ` --- signal that the handler knows how to open *protocol *
614618 URLs.
615619
616- * :meth: `http_error_type ` --- signal that the handler knows how to handle HTTP
620+ See |protocol_open |_ for more information.
621+
622+ * :meth: `http_error_\< type\> ` --- signal that the handler knows how to handle HTTP
617623 errors with HTTP error code *type *.
618624
619- * :meth: `protocol_error ` --- signal that the handler knows how to handle errors
625+ See |http_error_nnn |_ for more information.
626+
627+ * :meth: `<protocol>_error ` --- signal that the handler knows how to handle errors
620628 from (non-\ ``http ``) *protocol *.
621629
622- * :meth: `protocol_request ` --- signal that the handler knows how to pre-process
630+ * :meth: `<protocol>_request ` --- signal that the handler knows how to pre-process
623631 *protocol * requests.
624632
625- * :meth: `protocol_response ` --- signal that the handler knows how to
633+ See |protocol_request |_ for more information.
634+
635+ * :meth: `<protocol>_response ` --- signal that the handler knows how to
626636 post-process *protocol * responses.
627637
638+ See |protocol_response |_ for more information.
639+
640+ .. |protocol_open | replace :: :meth: `BaseHandler.<protocol>_open `
641+ .. |http_error_nnn | replace :: :meth: `BaseHandler.http_error_\< nnn\> `
642+ .. |protocol_request | replace :: :meth: `BaseHandler.<protocol>_request `
643+ .. |protocol_response | replace :: :meth: `BaseHandler.<protocol>_response `
628644
629645.. method :: OpenerDirector.open(url, data=None[, timeout])
630646
@@ -643,7 +659,7 @@ OpenerDirector Objects
643659 Handle an error of the given protocol. This will call the registered error
644660 handlers for the given protocol with the given arguments (which are protocol
645661 specific). The HTTP protocol is a special case which uses the HTTP response
646- code to determine the specific error handler; refer to the :meth: `http_error_\* `
662+ code to determine the specific error handler; refer to the :meth: `http_error_\< type \> `
647663 methods of the handler classes.
648664
649665 Return values and exceptions raised are the same as those of :func: `urlopen `.
@@ -653,25 +669,25 @@ OpenerDirector objects open URLs in three stages:
653669The order in which these methods are called within each stage is determined by
654670sorting the handler instances.
655671
656- #. Every handler with a method named like :meth: `protocol_request ` has that
672+ #. Every handler with a method named like :meth: `<protocol>_request ` has that
657673 method called to pre-process the request.
658674
659- #. Handlers with a method named like :meth: `protocol_open ` are called to handle
675+ #. Handlers with a method named like :meth: `<protocol>_open ` are called to handle
660676 the request. This stage ends when a handler either returns a non-\ :const: `None `
661677 value (ie. a response), or raises an exception (usually
662678 :exc: `~urllib.error.URLError `). Exceptions are allowed to propagate.
663679
664680 In fact, the above algorithm is first tried for methods named
665681 :meth: `default_open `. If all such methods return :const: `None `, the algorithm
666- is repeated for methods named like :meth: `protocol_open `. If all such methods
682+ is repeated for methods named like :meth: `<protocol>_open `. If all such methods
667683 return :const: `None `, the algorithm is repeated for methods named
668684 :meth: `unknown_open `.
669685
670686 Note that the implementation of these methods may involve calls of the parent
671687 :class: `OpenerDirector ` instance's :meth: `~OpenerDirector.open ` and
672688 :meth: `~OpenerDirector.error ` methods.
673689
674- #. Every handler with a method named like :meth: `protocol_response ` has that
690+ #. Every handler with a method named like :meth: `<protocol>_response ` has that
675691 method called to post-process the response.
676692
677693
@@ -700,7 +716,7 @@ The following attribute and methods should only be used by classes derived from
700716.. note ::
701717
702718 The convention has been adopted that subclasses defining
703- :meth: `protocol_request ` or :meth: `protocol_response ` methods are named
719+ :meth: `<protocol>_request ` or :meth: `<protocol>_response ` methods are named
704720 :class: `\* Processor `; all others are named :class: `\* Handler `.
705721
706722
@@ -725,7 +741,8 @@ The following attribute and methods should only be used by classes derived from
725741 This method will be called before any protocol-specific open method.
726742
727743
728- .. method :: BaseHandler.protocol_open(req)
744+ .. _protocol_open :
745+ .. method :: BaseHandler.<protocol>_open(req)
729746 :noindex:
730747
731748 This method is *not * defined in :class: `BaseHandler `, but subclasses should
@@ -762,7 +779,8 @@ The following attribute and methods should only be used by classes derived from
762779 :func: `urlopen `.
763780
764781
765- .. method :: BaseHandler.http_error_nnn(req, fp, code, msg, hdrs)
782+ .. _http_error_nnn :
783+ .. method :: BaseHandler.http_error_<nnn>(req, fp, code, msg, hdrs)
766784
767785 *nnn * should be a three-digit HTTP error code. This method is also not defined
768786 in :class: `BaseHandler `, but will be called, if it exists, on an instance of a
@@ -774,7 +792,8 @@ The following attribute and methods should only be used by classes derived from
774792 :meth: `http_error_default `.
775793
776794
777- .. method :: BaseHandler.protocol_request(req)
795+ .. _protocol_request :
796+ .. method :: BaseHandler.<protocol>_request(req)
778797 :noindex:
779798
780799 This method is *not * defined in :class: `BaseHandler `, but subclasses should
@@ -785,7 +804,8 @@ The following attribute and methods should only be used by classes derived from
785804 :class: `Request ` object.
786805
787806
788- .. method :: BaseHandler.protocol_response(req, response)
807+ .. _protocol_response :
808+ .. method :: BaseHandler.<protocol>_response(req, response)
789809 :noindex:
790810
791811 This method is *not * defined in :class: `BaseHandler `, but subclasses should
@@ -873,10 +893,10 @@ ProxyHandler Objects
873893--------------------
874894
875895
876- .. method :: ProxyHandler.protocol_open (request)
896+ .. method :: ProxyHandler.<protocol>_open (request)
877897 :noindex:
878898
879- The :class: `ProxyHandler ` will have a method :meth: `protocol_open ` for every
899+ The :class: `ProxyHandler ` will have a method :meth: `<protocol>_open ` for every
880900 *protocol * which has a proxy in the *proxies * dictionary given in the
881901 constructor. The method will modify requests to go through the proxy, by
882902 calling ``request.set_proxy() ``, and call the next handler in the chain to
@@ -1132,7 +1152,7 @@ HTTPErrorProcessor Objects
11321152 For 200 error codes, the response object is returned immediately.
11331153
11341154 For non-200 error codes, this simply passes the job on to the
1135- :meth: `protocol_error_code ` handler methods, via :meth: `OpenerDirector.error `.
1155+ :meth: `http_error_ \< type \> ` handler methods, via :meth: `OpenerDirector.error `.
11361156 Eventually, :class: `HTTPDefaultErrorHandler ` will raise an
11371157 :exc: `~urllib.error.HTTPError ` if no other handler handles the error.
11381158
0 commit comments