def test_lxml_etree_bug(self): try: import lxml.etree except ImportError: pass else: doc = u"<feed>&illformed_charref</feed>".encode('utf8') # Importing lxml.etree currently causes libxml2 to # throw SAXException instead of SAXParseException. feedparser.parse(feedparser._StringIO(doc)) self.assertTrue(True)
def send_head(self): """Send custom headers defined in test case Example: <!-- Header: Content-type: application/atom+xml Header: X-Foo: bar --> """ # Short-circuit the HTTP status test `test_redirect_to_304()` if self.path == '/-/return-304.xml': self.send_response(304) self.send_header('Content-type', 'text/xml') self.end_headers() return feedparser._StringIO(u''.encode('utf-8')) path = self.translate_path(self.path) # the compression tests' filenames determine the header sent if self.path.startswith('/tests/compression'): if self.path.endswith('gz'): headers = {'Content-Encoding': 'gzip'} else: headers = {'Content-Encoding': 'deflate'} headers['Content-type'] = 'application/xml' else: headers = dict([ (k.decode('utf-8'), v.decode('utf-8').strip()) for k, v in self.headers_re.findall(open(path, 'rb').read()) ]) f = open(path, 'rb') if (self.headers.get('if-modified-since') == headers.get('Last-Modified', 'nom')) \ or (self.headers.get('if-none-match') == headers.get('ETag', 'nomatch')): status = 304 else: status = 200 headers.setdefault('Status', status) self.send_response(int(headers['Status'])) headers.setdefault('Content-type', self.guess_type(path)) self.send_header("Content-type", headers['Content-type']) self.send_header("Content-Length", str(os.stat(f.name)[6])) for k, v in headers.items(): if k not in ('Status', 'Content-type'): self.send_header(k, v) self.end_headers() return f
def send_head(self): """Send custom headers defined in test case Example: <!-- Header: Content-type: application/atom+xml Header: X-Foo: bar --> """ # Short-circuit the HTTP status test `test_redirect_to_304()` if self.path == '/-/return-304.xml': self.send_response(304) self.send_header('Content-type', 'text/xml') self.end_headers() return feedparser._StringIO(u''.encode('utf-8')) path = self.translate_path(self.path) # the compression tests' filenames determine the header sent if self.path.startswith('/tests/compression'): if self.path.endswith('gz'): headers = {'Content-Encoding': 'gzip'} else: headers = {'Content-Encoding': 'deflate'} headers['Content-type'] = 'application/xml' else: headers = dict( [(k.decode('utf-8'), v.decode('utf-8').strip()) for k, v in self.headers_re.findall(open(path, 'rb').read())]) f = open(path, 'rb') if (self.headers.get('if-modified-since') == headers.get('Last-Modified', 'nom')) \ or (self.headers.get('if-none-match') == headers.get('ETag', 'nomatch')): status = 304 else: status = 200 headers.setdefault('Status', status) self.send_response(int(headers['Status'])) headers.setdefault('Content-type', self.guess_type(path)) self.send_header("Content-type", headers['Content-type']) self.send_header("Content-Length", str(os.stat(f.name)[6])) for k, v in headers.items(): if k not in ('Status', 'Content-type'): self.send_header(k, v) self.end_headers() return f