GNUnet  0.20.0
httpdomain.httpdomain.HTTPXRefStatusRole Class Reference
Inheritance diagram for httpdomain.httpdomain.HTTPXRefStatusRole:
[legend]
Collaboration diagram for httpdomain.httpdomain.HTTPXRefStatusRole:
[legend]

Public Member Functions

def result_nodes (self, document, env, node, is_ref)
 

Detailed Description

Definition at line 437 of file httpdomain.py.

Member Function Documentation

◆ result_nodes()

def httpdomain.httpdomain.HTTPXRefStatusRole.result_nodes (   self,
  document,
  env,
  node,
  is_ref 
)

Definition at line 439 of file httpdomain.py.

439  def result_nodes(self, document, env, node, is_ref):
440  def get_code_status(text):
441  if text.isdigit():
442  code = int(text)
443  return code, HTTP_STATUS_CODES.get(code)
444  else:
445  try:
446  code, status = re.split(r'\s', text.strip(), 1)
447  code = int(code)
448  except ValueError:
449  return None, None
450  known_status = HTTP_STATUS_CODES.get(code)
451  if known_status is None:
452  return code, None
453  elif known_status.lower() != status.lower():
454  return code, None
455  else:
456  return code, status
457 
458  def report_unknown_code():
459  if not config['http_strict_mode']:
460  return [nodes.emphasis(text, text)], []
461  reporter = document.reporter
462  msg = reporter.error('%d is unknown HTTP status code' % code,
463  line=node.line)
464  prb = nodes.problematic(text, text)
465  return [prb], [msg]
466 
467  def report_invalid_code():
468  if not config['http_strict_mode']:
469  return [nodes.emphasis(text, text)], []
470  reporter = document.reporter
471  msg = reporter.error(
472  'HTTP status code must be an integer (e.g. `200`) or '
473  'start with an integer (e.g. `200 OK`); %r is invalid' %
474  text,
475  line=node.line
476  )
477  prb = nodes.problematic(text, text)
478  return [prb], [msg]
479 
480  text = node[0][0]
481  rawsource = node[0].rawsource
482  config = env.domains['http'].env.config
483 
484  code, status = get_code_status(text)
485  if code is None:
486  return report_invalid_code()
487  elif status is None:
488  return report_unknown_code()
489  elif code == 226:
490  url = 'http://www.ietf.org/rfc/rfc3229.txt'
491  elif code == 418:
492  url = 'http://www.ietf.org/rfc/rfc2324.txt'
493  elif code == 429:
494  url = 'http://tools.ietf.org/html/rfc6585#section-4'
495  elif code == 449:
496  url = 'http://msdn.microsoft.com/en-us/library/dd891478(v=prot.10).aspx'
497  elif code == 451:
498  url = 'http://www.ietf.org/rfc/rfc7725.txt'
499  elif code in WEBDAV_STATUS_CODES:
500  url = 'http://tools.ietf.org/html/rfc4918#section-11.%d' % (WEBDAV_STATUS_CODES.index(code) + 1)
501  elif code in HTTP_STATUS_CODES:
502  url = 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html' \
503  '#sec10.' + ('%d.%d' % (code // 100, 1 + code % 100))
504  else:
505  url = ''
506  node = nodes.reference(rawsource, '%d %s' % (code, status), refuri=url)
507  return [node], []
508 
509 

References consensus-simulation.int.


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