def __init__(self, content=None, mimetype=None): self.data = None self.__iter = None self.fd = BytesIO() self.headers = Headers() self.trailer = Headers() self.transfer_codec = None self.content_codec = None self.mimetype = mimetype or b'text/plain; charset=UTF-8' self.set(content)
def __init__(self, protocol=None, headers=None, body=None): u"""Initiates a new Message to hold information about the message. :param protocol: the requested protocol :type protocol: str|tuple :param headers: the request headers :type headers: dict or :class:`Headers` :param body: the request body :type body: any """ self.__protocol = Protocol(protocol or (1, 1)) self.__headers = Headers(headers or {}) self.__body = Body(body or b'')
def parse_trailers(self): # TODO: the code is exactly the same as parse_headers but # we have to make sure no invalid header fields are send (only values told in Trailer header allowed) if self.buffer.startswith(self.line_end): self.buffer = self.buffer[len(self.line_end):] return False # no trailers trailer_end = self.line_end + self.line_end if trailer_end not in self.buffer: # not received yet return NOT_RECEIVED_YET trailers, self.buffer = self.buffer.split(trailer_end, 1) self.trailers = Headers() try: self.trailers.parse(bytes(trailers)) except InvalidHeader as exc: exc = InvalidHeader(_(u'Invalid trailers: %r'), Unicode(exc)) raise BAD_REQUEST(Unicode(exc)) self.merge_trailer_into_header() return False
def trailer(self): return Headers((key, self.headers[key]) for key in self.headers.values('Trailer') if key in self.headers)