def trim(self, stream): return () def get_header_list(self, values): return zip(self.headers, values) @staticmethod def get_content_headers(headers): content_type = None content_length = None errors = [] for name,value in headers: if type_rx.match(name): if value: content_type = value else: errors.append(('invalid header',name,value)) elif length_rx.match(name): try: content_length = int(value) except ValueError: errors.append(('invalid header',name,value)) return content_type, content_length, errors register_record_type(re.compile('^filedesc://'), ArcRecord)
if newlines == 0: break else: #print 'line', line, newlines newlines = 0 errors.append(('trailing data after content', line)) line = stream.readline() if newlines > 0: errors+=('less than two terminating newlines at end of record, missing', newlines) return errors register_record_type(version_rx, WarcRecord) def make_response(id, date, url, content, request_id): headers = [ (WarcRecord.TYPE, WarcRecord.RESPONSE), (WarcRecord.ID, id), (WarcRecord.DATE, date), (WarcRecord.URL, url), ] if request_id: headers.append((WarcRecord.CONCURRENT_TO, request_id)) record=WarcRecord(headers=headers, content=content) return record