Пример #1
0
    def range(self):
        value = self._get_header_by_wsgi_name('HTTP_RANGE')

        if value:
            if ',' in value:
                msg = 'The value must be a continuous byte range.'
                raise InvalidHeader(msg, value, 'range')

            try:
                first, last = value.split('-')

                if first:
                    return (int(first), int(last or -1))
                elif last:
                    return (-int(last), -1)
                else:
                    msg = 'The value is missing offsets.'
                    raise InvalidHeader(msg, value, 'range')

            except ValueError:
                href = 'http://goo.gl/zZ6Ey'
                href_text = 'HTTP/1.1 Range Requests'
                msg = ('The string given could not be parsed. It must be '
                       'formatted according to RFC 2616.')
                raise InvalidHeader(msg,
                                    value,
                                    'range',
                                    href=href,
                                    href_text=href_text)

        return None
Пример #2
0
 def date(self):
     http_date = self._get_header_by_wsgi_name('HTTP_DATE')
     try:
         return util.http_date_to_dt(http_date)
     except ValueError:
         msg = ('The value could not be parsed. It must be formatted '
                'according to RFC 1123.')
         raise InvalidHeader(msg, http_date, 'date')
Пример #3
0
    def content_length(self):
        value = self._get_header_by_wsgi_name('HTTP_CONTENT_LENGTH')

        if value:
            try:
                value_as_int = int(value)
            except ValueError:
                msg = 'The value of the header must be a number.'
                raise InvalidHeader(msg, value, 'content-length')

            if value_as_int < 0:
                msg = 'The value of the header must be a positive number.'
                raise InvalidHeader(msg, value, 'content-length')
            else:
                return value_as_int

        return None