1. Adam Knight
  2. sphinx-contrib

Commits

Adam Knight  committed bce9ac7 Draft

Standardized on IETF site for documentation (where possible).
Added additional HTTP status codes from other RFCs.
Updated handling of HTTP status codes to be able to specify their own references when needed (while using the existing RFC 2616 math handler as the default).
Updated link to MS for code 449.

  • Participants
  • Parent commits a8b5880
  • Branches default

Comments (0)

Files changed (1)

File httpdomain/sphinxcontrib/httpdomain.py

View file
         return '{0}#{1}{2}'.format(self.base_url, self.anchor, self.section)
 
 
-class RFC2616Ref(DocRef):
-
-    def __init__(self, section):
-        url = 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec{0:d}.html'
-        url = url.format(int(section))
-        super(RFC2616Ref, self).__init__(url, 'sec', section)
-
-
-
-
 class IETFRef(DocRef):
 
     def __init__(self, rfc, section=None):
             super(IETFRef, self).__init__(url, '', '')
 
 
+# Convenience reference
+class RFC2616Ref(IETFRef):
+
+    def __init__(self, section):
+        super(RFC2616Ref, self).__init__(2616, section)
+
+
+# Convenience reference + some section math
+class RFC2616StatusCodeRef(IETFRef):
+    
+    def __init__(self, code):
+        section = '%d.%d' % (code // 100, 1 + code % 100)
+        super(RFC2616StatusCodeRef, self).__init__(2616, '10.' + section)
+
+
 class EventSourceRef(DocRef):
 
     def __init__(self, section):
     205: 'Reset Content',
     206: 'Partial Content',
     207: 'Multi Status',
-    226: 'IM Used',              # see RFC 3229
+    226: ('IM Used', IETFRef(3229)),
     300: 'Multiple Choices',
     301: 'Moved Permanently',
     302: 'Found',
     415: 'Unsupported Media Type',
     416: 'Requested Range Not Satisfiable',
     417: 'Expectation Failed',
-    418: "I'm a teapot",        # see RFC 2324
+    418: ("I'm a teapot", IETFRef(2324)),
     422: 'Unprocessable Entity',
     423: 'Locked',
     424: 'Failed Dependency',
     426: 'Upgrade Required',
-    449: 'Retry With',           # proprietary MS extension
+    428: ('Precondition Required', IETFRef(6585, 3)),
+    429: ('Too Many Requests', IETFRef(6585, 4)),
+    431: ('Request Header Fields Too Large', IETFRef(6585, 5)),
+    449: ('Retry With', DocRef(
+        'http://msdn.microsoft.com/en-us/library/dd891478.aspx',
+        '', '')), # proprietary MS extension
     500: 'Internal Server Error',
     501: 'Not Implemented',
     502: 'Bad Gateway',
     504: 'Gateway Timeout',
     505: 'HTTP Version Not Supported',
     507: 'Insufficient Storage',
-    510: 'Not Extended'
+    510: 'Not Extended',
+    511: ('Network Authentication Required', IETFRef(6585, 6)),
 }
 
 http_sig_param_re = re.compile(r'\((?:(?P<type>[^:)]+):)?(?P<name>[\w_]+)\)',
             prb = inliner.problematic(rawtext, rawtext, msg)
             return [prb], [msg]
     nodes.reference(rawtext)
-    if code == 226:
-        url = 'http://www.ietf.org/rfc/rfc3229.txt'
-    if code == 418:
-        url = 'http://www.ietf.org/rfc/rfc2324.txt'
-    if code == 449:
-        url = 'http://msdn.microsoft.com/en-us/library' \
-              '/dd891478(v=prot.10).aspx'
-    elif code in HTTP_STATUS_CODES:
-        url = 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html' \
-              '#sec10.' + ('%d.%d' % (code // 100, 1 + code % 100))
-    else:
-        url = ''
+    
+    ref=None
+    if isinstance(status, tuple):
+        status, ref = status
+    if not ref:
+        ref = RFC2616StatusCodeRef(code)
+    url = repr(ref)
+    
     set_classes(options)
     node = nodes.reference(rawtext, '%d %s' % (code, status),
                            refuri=url, **options)