def fn(self): doc = listparser._to_bytes("""<?xml version="1.0"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:rss="http://purl.org/rss/1.0/"> <foaf:Agent><foaf:name>á</foaf:name><foaf:weblog> <foaf:Document rdf:about="http://domain/"><rdfs:seeAlso> <rss:channel rdf:about="http://domain/feed" /> </rdfs:seeAlso></foaf:Document></foaf:weblog></foaf:Agent> </rdf:RDF>""") idoc = listparser.Injector(listparser.BytesStrIO(doc)) tmp = [] while 1: i = idoc.read(size) if i: tmp.append(i) else: idoc.close() break xml = _to_unicode(listparser._to_bytes('').join(tmp)) result = listparser.parse(xml) self.assertFalse(result.bozo) self.assertEqual(len(result.feeds), 1) self.assertEqual(ord(result.feeds[0].title), 225) # \u00e1
def do_GET(self): status = 200 location = etag = modified = None reply = listparser._to_bytes('') end_directives = False f = open(dirname(abspath(__file__)) + self.path, 'rb') for line in f: reply += line line = line.decode('utf8', 'replace') if not end_directives: if line.strip() == '-->': end_directives = True elif 'Status:' in line: status = int(line.strip()[7:]) elif 'Location:' in line: location = line.strip()[9:].strip() elif 'Server-ETag:' in line: etag = line.split(': ', 1)[1].strip() if self.headers.get('if-none-match') == etag: status = 304 elif 'Server-Modified:' in line: modified = line.split(': ', 1)[1].strip() if self.headers.get('if-modified-since') == modified: status = 304 f.close() self.send_response(status) if location: self.send_header('Location', location) if etag: self.send_header('ETag', etag) if modified: self.send_header('Last-Modified', modified) self.send_header('Content-type', 'text/xml') self.send_header('x-agent', self.headers.get('user-agent')) self.end_headers() self.wfile.write(reply)