def parse_header(line): if line: name, value = line.split(':', 1) name = name.strip().lower() value = value.strip() type = get_type(name) return name, type.decode(value) return None, None
def get_header(self, name): name = name.lower() datatype = get_type(name) value = self.soup_message.get_header(name) if value is None: return datatype.get_default() try: return datatype.decode(value) except ValueError: log_warning('malformed header: %s: %s' % (name, value), domain='itools.web') return datatype.get_default()
def read_headers(file): entity_headers = {} # Setup line = file.readline().strip() while not line: line = file.readline().strip() # Go while line: name, value = line.split(':', 1) name = name.strip().lower() datatype = get_type(name) value = value.strip() try: value = datatype.decode(value) except Exception: log_warning("Failed to parse the '%s' header" % name, domain='itools.web') else: entity_headers[name] = value # Next line = file.readline().strip() return entity_headers
def set_header(self, name, value): datatype = get_type(name) value = datatype.encode(value) self.soup_message.set_header(name, value)