Пример #1
0
def compose_content_type(content_type, charset=None):
    if charset is None:
        return content_type
    charset = compat.python2http(charset)
    if charset in ('iso-8859-1', 'us-ascii'):
        return content_type
    return "%s; charset=%s" % (content_type, charset)
Пример #2
0
def compose_accepted_charsets(charsets):
    results = []
    if isinstance(charsets, (list, tuple)):
        charsets = dict([(n, DEFAULT_PRIORITY) for n in charsets])
    for name, priority in charsets.items():
        if priority is None:
            priority = DEFAULT_PRIORITY
        priority = max(0.0, min(1.0, float(priority)))
        charset = compat.python2http(name)
        results.append("%s; q=%f" % (charset, priority))
    return ", ".join(results)
Пример #3
0
 def _update_headers(self):
     if self._mime_type:
         value = self._mime_type.lower()
         if self._encoding:
             charset = compat.python2http(self._encoding.lower())
             if charset not in ["iso-8859-1", "us-ascii"]:
                 value += "; charset=" + charset
         self._set_header("content-type", value)
     if self._language:
         value = self._language.lower()
         if value != "en":
             self._set_header("content-language", self._language.lower())
     if self._server.identity:
         self._set_header("server", self._server.identity)
Пример #4
0
    def __init__(self, *args, **kwargs):
        self.allowed_mime_types = ("*/*")
        self.allowed_languages = ("*")
        self.allowed_encodings = ("*")

        mime_types = kwargs.pop('allowed_mime_types', None)
        if mime_types is not None:
            self.allowed_mime_types = mime_types

        languages = kwargs.pop('allowed_languages', None)
        if languages is not None:
            self.allowed_languages = languages

        encodings = kwargs.pop('allowed_encodings', None)

        if encodings is not None:
            self.allowed_encodings = tuple([compat.python2http(e)
                                            for e in encodings])

        HTTPError.__init__(self, *args, **kwargs)