parameters: (value)
return_statement: return ctype
docstring: maintype "/" subtype *( ";" parameter )
  
      The maintype and substype are tokens.  Theoretically they could
      be checked against the official IANA list + x-token, but we
      don't do that.
docstring_summary: maintype "/" subtype *( ";" parameter )
docstring_tokens: maintype / subtype * ( ; parameter )
function: def parse_content_type_header(value):
      """ maintype "/" subtype *( ";" parameter )
  
      The maintype and substype are tokens.  Theoretically they could
      be checked against the official IANA list + x-token, but we
      don't do that.
      """
      ctype = ContentType()
      recover = False
      if not value:
          ctype.defects.append(errors.HeaderMissingRequiredValue(
              "Missing content type specification"))
          return ctype
      try:
          token, value = get_token(value)
      except errors.HeaderParseError:
          ctype.defects.append(errors.InvalidHeaderDefect(
              "Expected content maintype but found {!r}".format(value)))
          _find_mime_parameters(ctype, value)
          return ctype
      ctype.append(token)
      # XXX: If we really want to follow the formal grammar we should make
      # mantype and subtype specialized TokenLists here.  Probably not worth it.
      if not value or value[0] != '/':
          ctype.defects.append(errors.InvalidHeaderDefect(
              "Invalid content type"))
          if value:
              _find_mime_parameters(ctype, value)
          return ctype
      ctype.maintype = token.value.strip().lower()
      ctype.append(ValueTerminal('/', 'content-type-separator'))
      value = value[1:]
      try:
          token, value = get_token(value)
      except errors.HeaderParseError:
          ctype.defects.append(errors.InvalidHeaderDefect(
              "Expected content subtype but found {!r}".format(value)))
          _find_mime_parameters(ctype, value)
          return ctype
      ctype.append(token)
      ctype.subtype = token.value.strip().lower()
      if not value:
          return ctype
      if value[0] != ';':
          ctype.defects.append(errors.InvalidHeaderDefect(
              "Only parameters are valid after content type, but "
              "found {!r}".format(value)))
          # The RFC requires that a syntactically invalid content-type be treated
          # as text/plain.  Perhaps we should postel this, but we should probably
          # only do that if we were checking the subtype value against IANA.
          del ctype.maintype, ctype.subtype
          _find_mime_parameters(ctype, value)
          return ctype
      ctype.append(ValueTerminal(';', 'parameter-separator'))
      ctype.append(parse_mime_parameters(value[1:]))
      return ctype
function_tokens: def parse_content_type_header ( value ) : ctype = ContentType ( ) recover = False if not value : ctype . defects . append ( errors . HeaderMissingRequiredValue ( "Missing content type specification" ) ) return ctype try : token , value = get_token ( value ) except errors . HeaderParseError : ctype . defects . append ( errors . InvalidHeaderDefect ( "Expected content maintype but found {!r}" . format ( value ) ) ) _find_mime_parameters ( ctype , value ) return ctype ctype . append ( token ) # XXX: If we really want to follow the formal grammar we should make # mantype and subtype specialized TokenLists here.  Probably not worth it. if not value or value [ 0 ] != '/' : ctype . defects . append ( errors . InvalidHeaderDefect ( "Invalid content type" ) ) if value : _find_mime_parameters ( ctype , value ) return ctype ctype . maintype = token . value . strip ( ) . lower ( ) ctype . append ( ValueTerminal ( '/' , 'content-type-separator' ) ) value = value [ 1 : ] try : token , value = get_token ( value ) except errors . HeaderParseError : ctype . defects . append ( errors . InvalidHeaderDefect ( "Expected content subtype but found {!r}" . format ( value ) ) ) _find_mime_parameters ( ctype , value ) return ctype ctype . append ( token ) ctype . subtype = token . value . strip ( ) . lower ( ) if not value : return ctype if value [ 0 ] != ';' : ctype . defects . append ( errors . InvalidHeaderDefect ( "Only parameters are valid after content type, but " "found {!r}" . format ( value ) ) ) # The RFC requires that a syntactically invalid content-type be treated # as text/plain.  Perhaps we should postel this, but we should probably # only do that if we were checking the subtype value against IANA. del ctype . maintype , ctype . subtype _find_mime_parameters ( ctype , value ) return ctype ctype . append ( ValueTerminal ( ';' , 'parameter-separator' ) ) ctype . append ( parse_mime_parameters ( value [ 1 : ] ) ) return ctype