Determine the best content type to use for the request.

    :param ctypes: A list of the available content types.

    :returns: A tuple of the best match content type and the
              parameters for that content type.
511522
def best_match(requested, allowed):
    

    requested = [parse_ctype(ctype) for ctype in quoted_split(requested, ',')]

    best_q = -1
    best_ctype = ''
    best_params = {}
    best_match = '*/*'

    # Walk the list of content types
    for ctype in allowed:
        # Compare to the accept list
        for ctype_mask, params in requested:
            try:
                q = float(params.get('q', 1.0))
            except ValueError:
                # Bad quality value
                continue

            if q < best_q:
                # Not any better
                continue
            elif best_q == q:
                # Base on the best match
                if best_match.count('*') <= ctype_mask.count('*'):
                    continue

            # OK, see if we have a match
            if _match_mask(ctype_mask, ctype):
                best_q = q
                best_ctype = ctype
                best_params = params
                best_match = ctype_mask

    # Return the best match
    return best_ctype, best_params
500940
def choose_type(cls, content_type):
        """"""
        return cls.type_cls.SUBDIR if content_type in cls.subdir_types \
            else cls.type_cls.FILE
556786
def _get_content_type(self, filename):
        
        mntype = mimetypes.guess_type(filename)[0]
        filename, fileExtension = os.path.splitext(filename)
        if mntype is None and\
            fileExtension.lower() == ".csv":
            mntype = "text/csv"
        elif mntype is None and \
            fileExtension.lower() == ".sd":
            mntype = "File/sd"
        elif mntype is None:
            #mntype = 'application/octet-stream'
            mntype= "File/%s" % fileExtension.replace('.', '')
        return mntype
336482
def ctype_for_encoding(self, encoding):
        """"""
        if encoding in self.typecodes:
            return self.typecodes[encoding]
        elif encoding[0:1] == b'^' and encoding[1:] in self.typecodes:
            return POINTER(self.typecodes[encoding[1:]])
        elif encoding[0:1] == b'^' and encoding[1:] in [CGImageEncoding,
                                                        NSZoneEncoding]:
            return c_void_p
        elif encoding[0:1] == b'r' and encoding[1:] in self.typecodes:
            return self.typecodes[encoding[1:]]
        elif encoding[0:2] == b'r^' and encoding[2:] in self.typecodes:
            return POINTER(self.typecodes[encoding[2:]])
        else:
            raise Exception('unknown encoding for %s: %s'
                            % (self.name, encoding))
712227
def select_header_content_type(self, content_types):
        
        if not content_types:
            return 'application/json'

        content_types = [x.lower() for x in content_types]

        if 'application/json' in content_types or '*/*' in content_types:
            return 'application/json'
        else:
            return content_types[0]
952960
def get_content_type(self):
        
        extension = self.path_params.get('_extension')
        for ext, mime in self.EXTENSION_MAP:
            if ext == extension:
                return mime
        # Else: use the Accept headers
        if self.response.vary is None:
            self.response.vary = ['Accept']
        else:
            self.response.vary.append('Accept')
        types = [mime for ext, mime in self.EXTENSION_MAP]
        ct = self.request.accept.best_match(types)
        # No best match found. The specification allows us to either return a
        # 406 or just use another format in this case.
        # We pick the default format, though that may become a configurable
        # behavior in the future.
        if not ct:
            ct = types[0]
        return ct
1081911
def content_type(self, content_type):
        
        allowed_values = ["application/json", "text/html", "text/plain", "application/x-www-form-urlencoded", ""]  # noqa: E501
        if content_type not in allowed_values:
            raise ValueError(
                "Invalid value for `content_type` ({0}), must be one of {1}"  # noqa: E501
                .format(content_type, allowed_values)
            )

        self._content_type = content_type
482473
def _get_content_type(url):
        """"""
        scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
        if not scheme in ('http', 'https', 'ftp', 'ftps'):
            ## FIXME: some warning or something?
            ## assertion error?
            return ''
        req = Urllib2HeadRequest(url, headers={'Host': netloc})
        resp = urlopen(req)
        try:
            if hasattr(resp, 'code') and resp.code != 200 and scheme not in ('ftp', 'ftps'):
                ## FIXME: doesn't handle redirects
                return ''
            return resp.info().get('content-type', '')
        finally:
            resp.close()
1188493
def _get_ctypes(self):
        
        ctypes = []
        for related_object in self.model._meta.get_all_related_objects():
            model = getattr(related_object, 'related_model', related_object.model)
            ctypes.append(ContentType.objects.get_for_model(model).pk)
            if model.__subclasses__():
                for child in model.__subclasses__():
                    ctypes.append(ContentType.objects.get_for_model(child).pk)
        return ctypes
496419
def get_content_type(self) -> str:
        
        assert self.absolute_path is not None
        mime_type, encoding = mimetypes.guess_type(self.absolute_path)
        # per RFC 6713, use the appropriate type for a gzip compressed file
        if encoding == "gzip":
            return "application/gzip"
        # As of 2015-07-21 there is no bzip2 encoding defined at
        # http://www.iana.org/assignments/media-types/media-types.xhtml
        # So for that (and any other encoding), use octet-stream.
        elif encoding is not None:
            return "application/octet-stream"
        elif mime_type is not None:
            return mime_type
        # if mime_type not detected, use application/octet-stream
        else:
            return "application/octet-stream"
263422
def mimetype_params(self):
        

        def on_update(d):
            self.headers["Content-Type"] = dump_options_header(self.mimetype, d)

        d = parse_options_header(self.headers.get("content-type", ""))[1]
        return CallbackDict(d, on_update)
548332
def ctypes_parameter(self):
        
        if self._ctypes_parameter is None:
            #Essentially, we just need to check if we are an array that doesn't have explicitly
            #defined bounds. Assumed-shape arrays have to be 'pointer' or 'allocatable'. However,
            #the deffered/assumed shape arrays always use ':' as the array dimension.
            if self.dimension is not None and ":" in self.dimension:
                result = [self._get_ctypes_name()]
                result.extend([self._get_ctypes_name(i+1) for i in range(self.D)])
                if self.direction == "(inout)" and ("allocatable" in self.modifiers or
                                                    "pointer" in self.modifiers):
                    result.append("{}_o".format(self.name))
                self._ctypes_parameter = result
            elif self.dtype == "logical":
                self._ctypes_parameter = [self._get_ctypes_name()]
            elif hasattr(self, "parameters"):
                #This is the handler for the function return types that are simple
                self._ctypes_parameter = [self.name + "_f"]
            else:
                #Nothing special, just return the standard name.
                self._ctypes_parameter = [self.name]

        return self._ctypes_parameter
437716
def _py_ctype(parameter):
    
    ctype = parameter.ctype
    if ctype is None:
        raise ValueError("Can't bind ctypes py_parameter for parameter"
                         " {}".format(parameter.definition()))
    return ctype.lower()
137158
def _parse_content_type(content_type: Optional[str]) -> Tuple[Optional[str], str]:
    
    if not content_type:
        return None, "utf-8"
    else:
        type_, parameters = cgi.parse_header(content_type)
        encoding = parameters.get("charset", "utf-8")
        return type_, encoding
736768
def _get_type(stype):
    ''' 
    '''
    stype = stype.lower()
    if stype == 'str':
        return str
    if stype == 'unicode':
        if PY2:
            return unicode
        else:
            return str
    if stype == 'int':
        return int
    if stype == 'float':
        return float
    if stype == 'bool':
        return bool
    raise AppConfigValueException('Unsuported type given: {0}'.format(stype))
516718
def get_content_type(name, content):
    
    if hasattr(content, "content_type"):
        content_type = content.content_type
    else:
        mime_type, encoding = mimetypes.guess_type(name)
        content_type = mime_type
    return content_type
1339246
def parse_content_type(headers: MutableMapping) -> Tuple[Optional[str], str]:
    
    content_type = headers.get("content-type")
    if not content_type:
        return None, "utf-8"
    else:
        type_, parameters = cgi.parse_header(content_type)
        encoding = parameters.get("charset", "utf-8")
        return type_, encoding