Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
always be processed, but be at a lower priority than a complete
matching type.
See also: RFC 2616 section 14.1, and
"""
if _is_string(accept_header):
accept_list = parse_accept_header(accept_header)
else:
accept_list = accept_header
if _is_string(content_types):
content_types = [content_types]
server_ctlist = [content_type(ct) for ct in content_types]
del ct
#print 'AC', repr(accept_list)
#print 'SV', repr(server_ctlist)
best = None # (content_type, qvalue, accept_parms, matchlen)
for server_ct in server_ctlist:
best_for_this = None
for client_ct, qvalue, aargs in accept_list:
if ignore_wildcard and client_ct.is_universal_wildcard():
continue # */* being ignored
matchlen = 0 # how specifically this one matches (0 is a non-match)
if client_ct.is_universal_wildcard():
matchlen = 1 # */* is a 1
def parse_mt_only(s, start):
mt, k = parse_media_type(s, start, with_parameters=False)
ct = content_type()
ct.major = mt[0]
ct.minor = mt[1]
return ct, k
"""
return self.major == 'multipart' or self.major == 'message'
def is_xml(self):
"""Returns True if this media type is XML-based.
Note this does not consider text/html to be XML, but
application/xhtml+xml is.
"""
return self.minor == 'xml' or self.minor.endswith('+xml')
# Some common media types
content_formdata = content_type('multipart/form-data')
content_urlencoded = content_type('application/x-www-form-urlencoded')
content_byteranges = content_type('multipart/byteranges') # RFC 2616 sect 14.16
content_opaque = content_type('application/octet-stream')
content_html = content_type('text/html')
content_xhtml = content_type('application/xhtml+xml')
def acceptable_content_type( accept_header, content_types, ignore_wildcard=True ):
"""Determines if the given content type is acceptable to the user agent.
The accept_header should be the value present in the HTTP
"Accept:" header. In mod_python this is typically obtained from
the req.http_headers_in table; in WSGI it is environ["Accept"];
other web frameworks may provide other methods of obtaining it.
Optionally the accept_header parameter can be pre-parsed, as
returned from the parse_accept_header() function in this module.
The content_types argument should either be a single MIME media
def is_composite(self):
"""Is this media type composed of multiple parts.
"""
return self.major == 'multipart' or self.major == 'message'
def is_xml(self):
"""Returns True if this media type is XML-based.
Note this does not consider text/html to be XML, but
application/xhtml+xml is.
"""
return self.minor == 'xml' or self.minor.endswith('+xml')
# Some common media types
content_formdata = content_type('multipart/form-data')
content_urlencoded = content_type('application/x-www-form-urlencoded')
content_byteranges = content_type('multipart/byteranges') # RFC 2616 sect 14.16
content_opaque = content_type('application/octet-stream')
content_html = content_type('text/html')
content_xhtml = content_type('application/xhtml+xml')
def acceptable_content_type( accept_header, content_types, ignore_wildcard=True ):
"""Determines if the given content type is acceptable to the user agent.
The accept_header should be the value present in the HTTP
"Accept:" header. In mod_python this is typically obtained from
the req.http_headers_in table; in WSGI it is environ["Accept"];
other web frameworks may provide other methods of obtaining it.
Optionally the accept_header parameter can be pre-parsed, as
returned from the parse_accept_header() function in this module.
def is_composite(self):
"""Is this media type composed of multiple parts.
"""
return self.major == 'multipart' or self.major == 'message'
def is_xml(self):
"""Returns True if this media type is XML-based.
Note this does not consider text/html to be XML, but
application/xhtml+xml is.
"""
return self.minor == 'xml' or self.minor.endswith('+xml')
# Some common media types
content_formdata = content_type('multipart/form-data')
content_urlencoded = content_type('application/x-www-form-urlencoded')
content_byteranges = content_type('multipart/byteranges') # RFC 2616 sect 14.16
content_opaque = content_type('application/octet-stream')
content_html = content_type('text/html')
content_xhtml = content_type('application/xhtml+xml')
def acceptable_content_type( accept_header, content_types, ignore_wildcard=True ):
"""Determines if the given content type is acceptable to the user agent.
The accept_header should be the value present in the HTTP
"Accept:" header. In mod_python this is typically obtained from
the req.http_headers_in table; in WSGI it is environ["Accept"];
other web frameworks may provide other methods of obtaining it.
Optionally the accept_header parameter can be pre-parsed, as
def is_xml(self):
"""Returns True if this media type is XML-based.
Note this does not consider text/html to be XML, but
application/xhtml+xml is.
"""
return self.minor == 'xml' or self.minor.endswith('+xml')
# Some common media types
content_formdata = content_type('multipart/form-data')
content_urlencoded = content_type('application/x-www-form-urlencoded')
content_byteranges = content_type('multipart/byteranges') # RFC 2616 sect 14.16
content_opaque = content_type('application/octet-stream')
content_html = content_type('text/html')
content_xhtml = content_type('application/xhtml+xml')
def acceptable_content_type( accept_header, content_types, ignore_wildcard=True ):
"""Determines if the given content type is acceptable to the user agent.
The accept_header should be the value present in the HTTP
"Accept:" header. In mod_python this is typically obtained from
the req.http_headers_in table; in WSGI it is environ["Accept"];
other web frameworks may provide other methods of obtaining it.
Optionally the accept_header parameter can be pre-parsed, as
returned from the parse_accept_header() function in this module.
The content_types argument should either be a single MIME media
type string, or a sequence of them. It represents the set of
content types that the caller (server) is willing to send.
return self.major == 'multipart' or self.major == 'message'
def is_xml(self):
"""Returns True if this media type is XML-based.
Note this does not consider text/html to be XML, but
application/xhtml+xml is.
"""
return self.minor == 'xml' or self.minor.endswith('+xml')
# Some common media types
content_formdata = content_type('multipart/form-data')
content_urlencoded = content_type('application/x-www-form-urlencoded')
content_byteranges = content_type('multipart/byteranges') # RFC 2616 sect 14.16
content_opaque = content_type('application/octet-stream')
content_html = content_type('text/html')
content_xhtml = content_type('application/xhtml+xml')
def acceptable_content_type( accept_header, content_types, ignore_wildcard=True ):
"""Determines if the given content type is acceptable to the user agent.
The accept_header should be the value present in the HTTP
"Accept:" header. In mod_python this is typically obtained from
the req.http_headers_in table; in WSGI it is environ["Accept"];
other web frameworks may provide other methods of obtaining it.
Optionally the accept_header parameter can be pre-parsed, as
returned from the parse_accept_header() function in this module.
The content_types argument should either be a single MIME media
type string, or a sequence of them. It represents the set of